Author: atsushi
Date: 2006-12-07 22:59:23 -0500 (Thu, 07 Dec 2006)
New Revision: 69218
Added:
trunk/olive/class/System.ServiceModel/Test/Resources/test2.pfx
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/InterceptorBindingElement.cs
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ServiceSecurityContextTest.cs
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/SecurityMessageProperty.cs
trunk/olive/class/System.ServiceModel/System.ServiceModel/ServiceSecurityContext.cs
trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources
trunk/olive/class/System.ServiceModel/Test/Resources/ChangeLog
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/SecurityMessagePropertyTest.cs
Log:
2006-12-08 Atsushi Emomoto <[EMAIL PROTECTED]>
* SecurityMessageProperty.cs : implemented, though not in actual use.
* ServiceSecurityContext.cs : implemented some members.
* ServiceSecurityContextTest.cs : new test.
* SecurityMessagePropertyTest.cs : after making several effort to
make GetOrCreateSecureMessage() pass (with new
InterceptorBindingElement), it turned out that GetOrCreate() does
not populate security information by itself...
* InterceptorBindingElement.cs : new utility binding element for
testing.
* test2.pfx : new file.
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel/ServiceSecurityContext.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/System.ServiceModel/ServiceSecurityContext.cs
2006-12-08 03:51:52 UTC (rev 69217)
+++
trunk/olive/class/System.ServiceModel/System.ServiceModel/ServiceSecurityContext.cs
2006-12-08 03:59:23 UTC (rev 69218)
@@ -36,44 +36,46 @@
{
public class ServiceSecurityContext
{
- static ServiceSecurityContext anonymous;
+ static ServiceSecurityContext anonymous = new
ServiceSecurityContext (new ReadOnlyCollection<IAuthorizationPolicy> (new
IAuthorizationPolicy [0]));
static ServiceSecurityContext current;
[MonoTODO]
public static ServiceSecurityContext Anonymous {
- get { throw new NotImplementedException (); }
+ get { return anonymous; }
}
- [MonoTODO]
+ [MonoTODO] // null by default?
public static ServiceSecurityContext Current {
- get { throw new NotImplementedException (); }
+ get { return current; }
}
AuthorizationContext context;
ReadOnlyCollection<IAuthorizationPolicy> policies;
+ IIdentity primary_identity;
- [MonoTODO]
public ServiceSecurityContext (AuthorizationContext
authorizationContext)
: this (authorizationContext, new
ReadOnlyCollection<IAuthorizationPolicy> (new IAuthorizationPolicy [0]))
{
}
- [MonoTODO]
public ServiceSecurityContext (
ReadOnlyCollection<IAuthorizationPolicy>
authorizationPolicies)
- : this (null, authorizationPolicies)
+ : this
(AuthorizationContext.CreateDefaultAuthorizationContext
(authorizationPolicies), authorizationPolicies)
{
}
- [MonoTODO]
public ServiceSecurityContext (AuthorizationContext
authorizationContext,
ReadOnlyCollection<IAuthorizationPolicy>
authorizationPolicies)
{
+ if (authorizationContext == null)
+ throw new ArgumentNullException
("authorizationContext");
+ if (authorizationPolicies == null)
+ throw new ArgumentNullException
("authorizationPolicies");
this.policies = authorizationPolicies;
- this.context =
AuthorizationContext.CreateDefaultAuthorizationContext (authorizationPolicies);
- if (authorizationContext != null)
- foreach (string key in
authorizationContext.Properties.Keys)
- context.Properties.Add (key,
authorizationContext.Properties [key]);
+ this.context = authorizationContext;
+
+ // FIXME: get correct identity
+ primary_identity = new GenericIdentity (String.Empty);
}
public AuthorizationContext AuthorizationContext {
@@ -86,12 +88,12 @@
[MonoTODO]
public bool IsAnonymous {
- get { throw new NotImplementedException (); }
+ get { return policies.Count == 0; }
}
[MonoTODO]
public IIdentity PrimaryIdentity {
- get { throw new NotImplementedException (); }
+ get { return primary_identity; }
}
[MonoTODO]
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog
===================================================================
---
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog
2006-12-08 03:51:52 UTC (rev 69217)
+++
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog
2006-12-08 03:59:23 UTC (rev 69218)
@@ -1,3 +1,8 @@
+2006-12-08 Atsushi Emomoto <[EMAIL PROTECTED]>
+
+ * SecurityMessageProperty.cs : implemented, though not in actual use.
+ * ServiceSecurityContext.cs : implemented some members.
+
2006-12-07 Atsushi Emomoto <[EMAIL PROTECTED]>
* MessagePartSpecification : implemented Union().
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/SecurityMessageProperty.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/SecurityMessageProperty.cs
2006-12-08 03:51:52 UTC (rev 69217)
+++
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/SecurityMessageProperty.cs
2006-12-08 03:59:23 UTC (rev 69218)
@@ -4,7 +4,7 @@
// Author:
// Atsushi Enomoto <[EMAIL PROTECTED]>
//
-// Copyright (C) 2005 Novell, Inc. http://www.novell.com
+// Copyright (C) 2005-2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -35,32 +35,34 @@
namespace System.ServiceModel.Security
{
- public class SecurityMessageProperty : IMessageProperty
+ public class SecurityMessageProperty : IMessageProperty, IDisposable
{
SecurityTokenSpecification initiator_token, protection_token,
recipient_token, transport_token;
+ Collection<SupportingTokenSpecification> incoming_supp_tokens =
+ new Collection<SupportingTokenSpecification> ();
+ ReadOnlyCollection<IAuthorizationPolicy> policies;
string sender_id_prefix;
ServiceSecurityContext context;
public SecurityMessageProperty ()
{
+ context = ServiceSecurityContext.Anonymous;
}
- [MonoTODO]
public bool HasIncomingSupportingTokens {
- get { throw new NotImplementedException (); }
+ get { return incoming_supp_tokens != null &&
incoming_supp_tokens.Count > 0; }
}
- [MonoTODO]
public ReadOnlyCollection<IAuthorizationPolicy>
ExternalAuthorizationPolicies {
- get { throw new NotImplementedException (); }
+ get { return policies; }
+ set { policies = value; }
}
- [MonoTODO]
public Collection<SupportingTokenSpecification>
IncomingSupportingTokens {
- get { throw new NotImplementedException (); }
+ get { return incoming_supp_tokens; }
}
public SecurityTokenSpecification InitiatorToken {
@@ -98,10 +100,20 @@
return (SecurityMessageProperty) MemberwiseClone ();
}
- [MonoTODO]
+ public void Dispose ()
+ {
+ context = null;
+ policies = null;
+ }
+
public static SecurityMessageProperty GetOrCreate (Message
message)
{
- throw new NotImplementedException ();
+ SecurityMessageProperty s = message.Properties.Security;
+ if (s == null) {
+ s = new SecurityMessageProperty ();
+ message.Properties.Add ("Security", s);
+ }
+ return s;
}
}
}
Modified:
trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources
===================================================================
--- trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources
2006-12-08 03:51:52 UTC (rev 69217)
+++ trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources
2006-12-08 03:59:23 UTC (rev 69218)
@@ -14,6 +14,7 @@
System.ServiceModel.Channels/HandlerBodyWriter.cs
System.ServiceModel.Channels/HandlerTransportBindingElement.cs
System.ServiceModel.Channels/HttpTransportBindingElementTest.cs
+System.ServiceModel.Channels/InterceptorBindingElement.cs
System.ServiceModel.Channels/InvalidBindingElement.cs
System.ServiceModel.Channels/LocalClientSecuritySettingsTest.cs
System.ServiceModel.Channels/MessageBufferTest.cs
@@ -68,6 +69,7 @@
System.ServiceModel.Security/SecurityAlgorithmSuiteTest.cs
System.ServiceModel.Security/SecurityMessagePropertyTest.cs
System.ServiceModel.Security/ServiceCredentialsSecurityTokenManagerTest.cs
+System.ServiceModel.Security/ServiceSecurityContextTest.cs
System.ServiceModel.Security/SupportingTokenParametersTest.cs
System.ServiceModel.Security/WSSecurityTokenSerializerTest.cs
System.ServiceModel/BasicHttpBindingTest.cs
Modified: trunk/olive/class/System.ServiceModel/Test/Resources/ChangeLog
===================================================================
--- trunk/olive/class/System.ServiceModel/Test/Resources/ChangeLog
2006-12-08 03:51:52 UTC (rev 69217)
+++ trunk/olive/class/System.ServiceModel/Test/Resources/ChangeLog
2006-12-08 03:59:23 UTC (rev 69218)
@@ -1,3 +1,7 @@
+2006-12-08 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * test2.pfx : new file.
+
2006-08-01 Atsushi Enomoto <[EMAIL PROTECTED]>
* test.pfx : new file for serializer test for now.
Added: trunk/olive/class/System.ServiceModel/Test/Resources/test2.pfx
===================================================================
(Binary files differ)
Property changes on:
trunk/olive/class/System.ServiceModel/Test/Resources/test2.pfx
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
===================================================================
---
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
2006-12-08 03:51:52 UTC (rev 69217)
+++
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
2006-12-08 03:59:23 UTC (rev 69218)
@@ -1,3 +1,8 @@
+2006-12-08 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * InterceptorBindingElement.cs : new utility binding element for
+ testing.
+
2006-12-07 Atsushi Enomoto <[EMAIL PROTECTED]>
* SecurityBindingElementTest.cs : added duplicate authenticator test.
Added:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/InterceptorBindingElement.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/InterceptorBindingElement.cs
2006-12-08 03:51:52 UTC (rev 69217)
+++
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/InterceptorBindingElement.cs
2006-12-08 03:59:23 UTC (rev 69218)
@@ -0,0 +1,515 @@
+//
+// InterceptorBindingElement.cs
+//
+// Author:
+// Atsushi Enomoto <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2006 Novell, Inc. http://www.novell.com
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Collections.ObjectModel;
+using System.Net;
+using System.Net.Security;
+using System.Security.Principal;
+using System.Security.Cryptography.X509Certificates;
+using System.ServiceModel;
+using System.ServiceModel.Channels;
+using System.ServiceModel.Description;
+using System.ServiceModel.Security;
+using System.ServiceModel.Security.Tokens;
+using System.Security.Cryptography.Xml;
+using System.Threading;
+using NUnit.Framework;
+
+using MonoTests.System.ServiceModel.Channels;
+
+namespace MonoTests.System.ServiceModel.Channels
+{
+ public delegate void InterceptorRequestContextHandler (MessageBuffer
src);
+
+ class InterceptorBindingElement : BindingElement
+ {
+ InterceptorRequestContextHandler handler;
+
+ public InterceptorBindingElement
(InterceptorRequestContextHandler handler)
+ {
+ this.handler = handler;
+ }
+
+ public InterceptorRequestContextHandler Handler {
+ get { return handler; }
+ }
+
+ public override bool CanBuildChannelListener<TChannel>
(BindingContext context)
+ {
+ return true;
+ }
+
+ public override bool CanBuildChannelFactory<TChannel>
(BindingContext context)
+ {
+ return true;
+ }
+
+ public override IChannelListener<TChannel>
BuildChannelListener<TChannel> (BindingContext context)
+ {
+ return new InterceptorChannelListener<TChannel> (this,
context);
+ }
+
+ public override IChannelFactory<TChannel>
BuildChannelFactory<TChannel> (BindingContext context)
+ {
+ return new InterceptorChannelFactory<TChannel> (this,
context);
+ }
+
+ public override T GetProperty<T> (BindingContext ctx)
+ {
+ return ctx.GetInnerProperty<T> ();
+ }
+
+ public override BindingElement Clone ()
+ {
+ return this;
+ }
+ }
+
+ abstract class DefaultTimeoutCommunicationObject : CommunicationObject
+ {
+ IDefaultCommunicationTimeouts timeouts;
+ public DefaultTimeoutCommunicationObject
(IDefaultCommunicationTimeouts timeouts)
+ {
+ this.timeouts = timeouts;
+ }
+
+ protected override TimeSpan DefaultOpenTimeout {
+ get { return timeouts.OpenTimeout; }
+ }
+ protected override TimeSpan DefaultCloseTimeout {
+ get { return timeouts.CloseTimeout; }
+ }
+ }
+
+ class InterceptorChannelFactory<TChannel> : ChannelFactoryBase<TChannel>
+ {
+ InterceptorBindingElement element;
+ IChannelFactory<TChannel> inner;
+
+ public InterceptorChannelFactory (InterceptorBindingElement
element, BindingContext context)
+ : base (null)
+ {
+ this.element = element;
+ inner = context.BuildInnerChannelFactory<TChannel> ();
+ }
+
+ public InterceptorBindingElement Element {
+ get { return element; }
+ }
+
+ public override T GetProperty<T> ()
+ {
+ return inner.GetProperty<T> ();
+ }
+
+ protected override TChannel OnCreateChannel (EndpointAddress
address, Uri uri)
+ {
+ if (typeof (TChannel) == typeof (IRequestChannel))
+ return (TChannel) (object) new
InterceptorRequestChannel (
+
(InterceptorChannelFactory<IRequestChannel>) (object) this,
+ (IRequestChannel) (object)
inner.CreateChannel (address, uri));
+ throw new NotImplementedException ();
+ }
+
+
+ protected override void OnOpen (TimeSpan timeout)
+ {
+ inner.Open (timeout);
+ }
+
+ protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
AsyncCallback callback, object state)
+ {
+ return inner.BeginOpen (timeout, callback, state);
+ }
+
+ protected override void OnEndOpen (IAsyncResult result)
+ {
+ inner.EndOpen (result);
+ }
+
+ protected override void OnClose (TimeSpan timeout)
+ {
+ inner.Close (timeout);
+ }
+
+ protected override IAsyncResult OnBeginClose (TimeSpan timeout,
AsyncCallback callback, object state)
+ {
+ return inner.BeginClose (timeout, callback, state);
+ }
+
+ protected override void OnEndClose (IAsyncResult result)
+ {
+ inner.EndClose (result);
+ }
+
+ protected override void OnAbort ()
+ {
+ inner.Abort ();
+ }
+ }
+
+ class InterceptorChannelListener<TChannel> :
ChannelListenerBase<TChannel> where TChannel : class, IChannel
+ {
+ InterceptorBindingElement element;
+ IChannelListener<TChannel> inner;
+
+ public InterceptorChannelListener (InterceptorBindingElement
element, BindingContext context)
+ {
+ this.element = element;
+ inner = context.BuildInnerChannelListener<TChannel> ();
+ }
+
+ public InterceptorBindingElement Element {
+ get { return element; }
+ }
+
+ public override Uri Uri {
+ get { return inner.Uri; }
+ }
+
+ protected override TChannel OnAcceptChannel (TimeSpan timeout)
+ {
+ if (typeof (TChannel) == typeof (IReplyChannel))
+ return (TChannel) (object) new
InterceptorReplyChannel (
+
(InterceptorChannelListener<IReplyChannel>) (object) this,
+ (IReplyChannel) (object)
inner.AcceptChannel (timeout));
+ throw new NotImplementedException ();
+ }
+
+ protected override IAsyncResult OnBeginAcceptChannel (
+ TimeSpan timeout, AsyncCallback callback, object state)
+ {
+ return inner.BeginAcceptChannel (timeout, callback,
state);
+ }
+
+ protected override TChannel OnEndAcceptChannel (IAsyncResult
result)
+ {
+ if (typeof (TChannel) == typeof (IReplyChannel))
+ return (TChannel) (object) new
InterceptorReplyChannel (
+
(InterceptorChannelListener<IReplyChannel>) (object) this,
+ (IReplyChannel) (object)
inner.EndAcceptChannel (result));
+ throw new NotImplementedException ();
+ }
+
+
+ protected override bool OnWaitForChannel (TimeSpan timeout)
+ {
+ return inner.WaitForChannel (timeout);
+ }
+
+ protected override IAsyncResult OnBeginWaitForChannel (TimeSpan
timeout, AsyncCallback callback, object state)
+ {
+ return inner.BeginWaitForChannel (timeout, callback,
state);
+ }
+
+ protected override bool OnEndWaitForChannel (IAsyncResult
result)
+ {
+ return inner.EndWaitForChannel (result);
+ }
+
+
+ protected override void OnAbort ()
+ {
+ inner.Abort ();
+ }
+
+ protected override void OnOpen (TimeSpan timeout)
+ {
+ inner.Open (timeout);
+ }
+
+ protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
AsyncCallback callback, object state)
+ {
+ return inner.BeginOpen (timeout, callback, state);
+ }
+
+ protected override void OnEndOpen (IAsyncResult result)
+ {
+ inner.EndOpen (result);
+ }
+
+ protected override void OnClose (TimeSpan timeout)
+ {
+ inner.Close (timeout);
+ }
+
+ protected override IAsyncResult OnBeginClose (TimeSpan timeout,
AsyncCallback callback, object state)
+ {
+ return inner.BeginClose (timeout, callback, state);
+ }
+
+ protected override void OnEndClose (IAsyncResult result)
+ {
+ inner.EndClose (result);
+ }
+ }
+
+ class InterceptorRequestChannel : ChannelBase, IRequestChannel
+ {
+ InterceptorChannelFactory<IRequestChannel> source;
+ IRequestChannel inner;
+
+ public InterceptorRequestChannel
(InterceptorChannelFactory<IRequestChannel> source, IRequestChannel inner)
+ : base (source)
+ {
+ this.source = source;
+ this.inner = inner;
+ }
+
+ public EndpointAddress RemoteAddress {
+ get { return inner.RemoteAddress; }
+ }
+
+ public Uri Via {
+ get { return inner.Via; }
+ }
+
+ public Message Request (Message message)
+ {
+ return inner.Request (message);
+ }
+ public Message Request (Message message, TimeSpan timeout)
+ {
+ return inner.Request (message, timeout);
+ }
+ public IAsyncResult BeginRequest (Message message,
AsyncCallback callback, object state)
+ {
+ return inner.BeginRequest (message, callback, state);
+ }
+ public IAsyncResult BeginRequest (Message message, TimeSpan
timeout, AsyncCallback callback, object state)
+ {
+ return inner.BeginRequest (message, timeout, callback,
state);
+ }
+ public Message EndRequest (IAsyncResult result)
+ {
+ return inner.EndRequest (result);
+ }
+
+
+ protected override void OnAbort ()
+ {
+ inner.Abort ();
+ }
+
+ protected override void OnOpen (TimeSpan timeout)
+ {
+ inner.Open (timeout);
+ }
+
+ protected override IAsyncResult OnBeginOpen (TimeSpan timeout,
AsyncCallback callback, object state)
+ {
+ return inner.BeginOpen (timeout, callback, state);
+ }
+
+ protected override void OnEndOpen (IAsyncResult result)
+ {
+ inner.EndOpen (result);
+ }
+
+ protected override void OnClose (TimeSpan timeout)
+ {
+ inner.Close (timeout);
+ }
+
+ protected override IAsyncResult OnBeginClose (TimeSpan timeout,
AsyncCallback callback, object state)
+ {
+ return inner.BeginClose (timeout, callback, state);
+ }
+
+ protected override void OnEndClose (IAsyncResult result)
+ {
+ inner.EndClose (result);
+ }
+ }
+
+ class InterceptorReplyChannel : ReplyChannelBase
+ {
+ InterceptorChannelListener<IReplyChannel> source;
+ IReplyChannel inner;
+
+ public InterceptorReplyChannel
(InterceptorChannelListener<IReplyChannel> source, IReplyChannel inner)
+ : base (source)
+ {
+ this.source = source;
+ this.inner = inner;
+ }
+
+ public override EndpointAddress LocalAddress {
+ get { return inner.LocalAddress; }
+ }
+
+ RequestContext Inspect (RequestContext src)
+ {
+ CopyRequestContext ret = new CopyRequestContext (src);
+ source.Element.Handler (ret.Buffer);
+ return ret;
+ }
+
+ public override RequestContext ReceiveRequest ()
+ {
+ return Inspect (inner.ReceiveRequest ());
+ }
+
+ public override RequestContext ReceiveRequest (TimeSpan timeout)
+ {
+ return Inspect (inner.ReceiveRequest (timeout));
+ }
+
+ public override IAsyncResult BeginReceiveRequest (AsyncCallback
callback, object state)
+ {
+ return inner.BeginReceiveRequest (callback, state);
+ }
+
+ public override IAsyncResult BeginReceiveRequest (TimeSpan
timeout, AsyncCallback callback, object state)
+ {
+ return inner.BeginReceiveRequest (timeout, callback,
state);
+ }
+
+ public override RequestContext EndReceiveRequest (IAsyncResult
result)
+ {
+ return Inspect (inner.EndReceiveRequest (result));
+ }
+
+ public override bool TryReceiveRequest (TimeSpan timeout, out
RequestContext context)
+ {
+ if (inner.TryReceiveRequest (timeout, out context)) {
+ context = Inspect (context);
+ return true;
+ }
+ context = null;
+ return false;
+ }
+
+ public override IAsyncResult BeginTryReceiveRequest (TimeSpan
timeout, AsyncCallback callback, object state)
+ {
+ return inner.BeginTryReceiveRequest (timeout, callback,
state);
+ }
+
+ public override bool EndTryReceiveRequest (IAsyncResult result,
out RequestContext context)
+ {
+ if (inner.EndTryReceiveRequest (result, out context)) {
+ context = Inspect (context);
+ return true;
+ }
+ context = null;
+ return false;
+ }
+
+ public override bool WaitForRequest (TimeSpan timeout)
+ {
+ return inner.WaitForRequest (timeout);
+ }
+
+ public override IAsyncResult BeginWaitForRequest (TimeSpan
timeout, AsyncCallback callback, object state)
+ {
+ return inner.BeginWaitForRequest (timeout, callback,
state);
+ }
+
+ public override bool EndWaitForRequest (IAsyncResult result)
+ {
+ return inner.EndWaitForRequest (result);
+ }
+
+ protected override void OnAbort ()
+ {
+ inner.Abort ();
+ }
+
+ protected override void OnClose (TimeSpan timeout)
+ {
+ inner.Close (timeout);
+ }
+
+ protected override void OnOpen (TimeSpan timeout)
+ {
+ inner.Open (timeout);
+ }
+ }
+
+ class CopyRequestContext : RequestContext
+ {
+ RequestContext src;
+ MessageBuffer buffer;
+ Message copy_msg;
+
+ public CopyRequestContext (RequestContext src)
+ {
+ this.src = src;
+ buffer = src.RequestMessage.CreateBufferedCopy
(0x10000);
+ copy_msg = buffer.CreateMessage ();
+ }
+
+ public MessageBuffer Buffer {
+ get { return buffer; }
+ }
+
+ public override void Abort ()
+ {
+ src.Abort ();
+ }
+
+ public override void Close ()
+ {
+ src.Close ();
+ }
+
+ public override void Close (TimeSpan timeout)
+ {
+ src.Close (timeout);
+ }
+
+ public override IAsyncResult BeginReply (Message message,
AsyncCallback callback, object state)
+ {
+ return src.BeginReply (message, callback, state);
+ }
+
+ public override IAsyncResult BeginReply (Message message,
TimeSpan timeout, AsyncCallback callback, object state)
+ {
+ return src.BeginReply (message, timeout, callback,
state);
+ }
+
+ public override void EndReply (IAsyncResult result)
+ {
+ src.EndReply (result);
+ }
+
+ public override void Reply (Message message)
+ {
+ src.Reply (message);
+ }
+
+ public override void Reply (Message message, TimeSpan timeout)
+ {
+ src.Reply (message, timeout);
+ }
+
+ public override Message RequestMessage {
+ get { return copy_msg; }
+ }
+ }
+}
Property changes on:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Channels/InterceptorBindingElement.cs
___________________________________________________________________
Name: svn:eol-style
+ native
Modified:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
===================================================================
---
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
2006-12-08 03:51:52 UTC (rev 69217)
+++
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
2006-12-08 03:59:23 UTC (rev 69218)
@@ -1,3 +1,11 @@
+2006-12-08 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * ServiceSecurityContextTest.cs : new test.
+ * SecurityMessagePropertyTest.cs : after making several effort to
+ make GetOrCreateSecureMessage() pass (with new
+ InterceptorBindingElement), it turned out that GetOrCreate() does
+ not populate security information by itself...
+
2006-12-07 Atsushi Enomoto <[EMAIL PROTECTED]>
* MessagePartSpecificationTest.cs : new test.
Modified:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/SecurityMessagePropertyTest.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/SecurityMessagePropertyTest.cs
2006-12-08 03:51:52 UTC (rev 69217)
+++
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/SecurityMessagePropertyTest.cs
2006-12-08 03:59:23 UTC (rev 69218)
@@ -42,13 +42,13 @@
using MonoTests.System.ServiceModel.Channels;
-namespace MonoTests.System.ServiceModel
+namespace MonoTests.System.ServiceModel.Security
{
[TestFixture]
public class SecurityMessagePropertyTest
{
static X509Certificate2 cert = new X509Certificate2
("Test/Resources/test.pfx", "mono");
- static X509Certificate2 cert2 = new X509Certificate2
("Test/Resources/test.cer");
+ static X509Certificate2 cert2 = new X509Certificate2
("Test/Resources/test2.pfx", "mono");
[ServiceContract]
public interface ICalc
@@ -136,7 +136,6 @@
}
[Test]
- [Category ("NotWorking")]
public void GetOrCreateNonSecureMessage ()
{
Message m = Message.CreateMessage
(MessageVersion.Default, "urn:myaction");
@@ -149,6 +148,7 @@
Assert.IsNull (p.ExternalAuthorizationPolicies, "#5");
// Assert.AreEqual (0,
p.ExternalAuthorizationPolicies.Count, "#5");
Assert.IsFalse (p.HasIncomingSupportingTokens, "#6");
+ Assert.IsNotNull (p.IncomingSupportingTokens, "#6-2");
ServiceSecurityContext ssc = p.ServiceSecurityContext;
Assert.IsNotNull (ssc, "#7");
@@ -163,61 +163,76 @@
}
[Test]
- [Ignore ("incomplete")]
-// [ExpectedException (typeof (Exception))]
+ [Category ("NotWorking")]
+ // not sure how "good" this test is ... if it fails at
+ // service side, it just results in timeout error.
+ // The assertion makes sure that it passes all the tests, but
+ // in case it failed, there is almost no hint ...
public void GetOrCreateSecureMessage ()
{
- AsymmetricSecurityBindingElement svcsbe =
- new AsymmetricSecurityBindingElement ();
- svcsbe.InitiatorTokenParameters =
- new X509SecurityTokenParameters ();
- svcsbe.RecipientTokenParameters =
- new X509SecurityTokenParameters ();
-
- RequestSender sender = delegate (Message msg) {
- GetOrCreateSecureMessageCore (msg);
- return null;
+ bool passed = false;
+ ServiceHost host = new ServiceHost (typeof
(CalcService));
+ InterceptorRequestContextHandler handler = delegate
(MessageBuffer src) {
+ Message msg = src.CreateMessage ();
+ GetOrCreateSecureMessageAtService (msg);
+ passed = true;
};
- CustomBinding b_req = new CustomBinding (svcsbe,
- new HttpTransportBindingElement ());
-
- b_req.ReceiveTimeout = b_req.SendTimeout =
TimeSpan.FromSeconds (5);
- EndpointAddress remaddr = new EndpointAddress (
- new Uri ("http://localhost:37564"),
- new X509CertificateEndpointIdentity (cert2));
- CalcProxy proxy = new CalcProxy (b_req, remaddr);
- proxy.ClientCredentials.ClientCertificate.Certificate =
cert;
- ServiceHost host = new ServiceHost (typeof
(CalcService));
try {
- AsymmetricSecurityBindingElement clisbe =
- new AsymmetricSecurityBindingElement ();
- clisbe.InitiatorTokenParameters =
- new X509SecurityTokenParameters ();
- clisbe.RecipientTokenParameters =
- new X509SecurityTokenParameters ();
+ SymmetricSecurityBindingElement clisbe =
+ new SymmetricSecurityBindingElement ();
+ clisbe.ProtectionTokenParameters =
+ new X509SecurityTokenParameters
(X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.Never);
BindingElement transport = new
HttpTransportBindingElement ();
- CustomBinding b_res = new CustomBinding
(clisbe, transport);
+ BindingElement sintercept = new
InterceptorBindingElement (handler);
+ CustomBinding b_res = new CustomBinding (clisbe,
+ sintercept,
+ transport);
b_res.ReceiveTimeout = b_res.SendTimeout =
TimeSpan.FromSeconds (5);
host.AddServiceEndpoint (typeof (ICalc), b_res,
"http://localhost:37564");
ServiceCredentials cred = new
ServiceCredentials ();
cred.ServiceCertificate.Certificate = cert;
+
cred.ClientCertificate.Authentication.CertificateValidationMode =
X509CertificateValidationMode.None;
host.Description.Behaviors.Add (cred);
host.Open ();
- proxy.Sum (1, 2);
+ ProcessClient ();
+
} finally {
- if (proxy.State == CommunicationState.Opened)
- proxy.Close ();
if (host.State == CommunicationState.Opened)
host.Close ();
}
+ if (!passed)
+ Assert.Fail ("Didn't pass the interceptor.");
}
- void GetOrCreateSecureMessageCore (Message msg)
+ void ProcessClient ()
{
+ SymmetricSecurityBindingElement svcsbe =
+ new SymmetricSecurityBindingElement ();
+ svcsbe.ProtectionTokenParameters =
+ new X509SecurityTokenParameters
(X509KeyIdentifierClauseType.Thumbprint, SecurityTokenInclusionMode.Never);
+
+ BindingElement cintercept = new
InterceptorBindingElement (null);
+ CustomBinding b_req = new CustomBinding (svcsbe,
+ cintercept,
+ new HttpTransportBindingElement ());
+
+ b_req.ReceiveTimeout = b_req.SendTimeout =
TimeSpan.FromSeconds (5);
+ EndpointAddress remaddr = new EndpointAddress (
+ new Uri ("http://localhost:37564"),
+ new X509CertificateEndpointIdentity (cert));
+ CalcProxy proxy = new CalcProxy (b_req, remaddr);
+ proxy.ClientCredentials.ClientCertificate.Certificate =
cert2;
+
+ proxy.Sum (1, 2);
+ proxy.Close ();
+ }
+
+ static void GetOrCreateSecureMessageAtClient (Message msg)
+ {
foreach (object o in msg.Properties)
if (o is SecurityMessageProperty)
Assert.Fail ("The input msg should not
contain SecurityMessageProperty yet.");
@@ -242,5 +257,34 @@
Assert.AreEqual (0, ssc.AuthorizationPolicies.Count,
"#9");
Assert.IsTrue (ssc.IsAnonymous, "#10");
}
+
+ static void GetOrCreateSecureMessageAtService (Message msg)
+ {
+ Assert.IsNull (msg.Properties.Security, "#0");
+ foreach (object o in msg.Properties)
+ if (o is SecurityMessageProperty)
+ Assert.Fail ("The input msg should not
contain SecurityMessageProperty yet.");
+ SecurityMessageProperty p =
SecurityMessageProperty.GetOrCreate (msg);
+ Assert.IsNotNull (msg.Properties.Security, "#0-2");
+
+ Assert.AreEqual (null, p.InitiatorToken, "#1");
+ Assert.AreEqual (null, p.RecipientToken, "#2");
+ Assert.IsNull (p.ProtectionToken, "#3");
+ Assert.IsNull (p.TransportToken, "#4");
+ Assert.IsNull (p.ExternalAuthorizationPolicies, "#5");
+// Assert.AreEqual (0,
p.ExternalAuthorizationPolicies.Count, "#5");
+ Assert.IsFalse (p.HasIncomingSupportingTokens, "#6");
+ ServiceSecurityContext ssc = p.ServiceSecurityContext;
+ Assert.IsNotNull (ssc, "#7");
+
+ // not sure if it is worthy of testing though ...
+ GenericIdentity identity = ssc.PrimaryIdentity as
GenericIdentity;
+ Assert.IsNotNull (identity, "#8-1");
+ Assert.AreEqual ("", identity.Name, "#8-2");
+ Assert.AreEqual ("", identity.AuthenticationType,
"#8-3");
+
+ Assert.AreEqual (0, ssc.AuthorizationPolicies.Count,
"#9");
+ Assert.IsTrue (ssc.IsAnonymous, "#10");
+ }
}
}
Added:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ServiceSecurityContextTest.cs
===================================================================
---
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ServiceSecurityContextTest.cs
2006-12-08 03:51:52 UTC (rev 69217)
+++
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ServiceSecurityContextTest.cs
2006-12-08 03:59:23 UTC (rev 69218)
@@ -0,0 +1,89 @@
+//
+// ServiceSecurityContextTest.cs
+//
+// Author:
+// Atsushi Enomoto <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2006 Novell, Inc. http://www.novell.com
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Collections.ObjectModel;
+using System.Net;
+using System.Net.Security;
+using System.IdentityModel.Policy;
+using System.Security.Principal;
+using System.ServiceModel;
+using System.ServiceModel.Channels;
+using System.ServiceModel.Security;
+using System.ServiceModel.Security.Tokens;
+using NUnit.Framework;
+
+using PolicyList =
System.Collections.ObjectModel.ReadOnlyCollection<System.IdentityModel.Policy.IAuthorizationPolicy>;
+
+namespace MonoTests.System.ServiceModel
+{
+ [TestFixture]
+ public class ServiceSecurityContextTest
+ {
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ConstructorNullArgs1 ()
+ {
+ new ServiceSecurityContext (null, null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ConstructorNullArgs2 ()
+ {
+ new ServiceSecurityContext ((AuthorizationContext)
null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void ConstructorNullArgs3 ()
+ {
+ new ServiceSecurityContext ((PolicyList) null);
+ }
+
+ [Test]
+ public void Constructor ()
+ {
+ ServiceSecurityContext c = new ServiceSecurityContext
(new PolicyList (new IAuthorizationPolicy [0]));
+ Assert.IsNotNull (c.AuthorizationContext, "#1");
+ Assert.AreEqual (0, c.AuthorizationPolicies.Count,
"#2");
+ // it is somehow treated as anonymous ...
+ Assert.IsTrue (c.IsAnonymous, "#3");
+ // FIXME: test PrimaryIdentity
+ }
+
+ [Test]
+ public void Anonymous ()
+ {
+ ServiceSecurityContext c =
ServiceSecurityContext.Anonymous;
+ Assert.IsNotNull (c.AuthorizationContext, "#1");
+ Assert.AreEqual (0, c.AuthorizationPolicies.Count,
"#2");
+ Assert.IsTrue (c.IsAnonymous, "#3");
+ // FIXME: test PrimaryIdentity
+ }
+ }
+}
Property changes on:
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ServiceSecurityContextTest.cs
___________________________________________________________________
Name: svn:eol-style
+ native
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches