Browse Source

2010-04-01 Atsushi Enomoto <[email protected]>

	* HttpTransportBindingElement.cs, HttpsTransportBindingElement.cs:
	  implement HttpsTransportBindingElement.GetProperty<T>(). Extend the
	  properties type from HTTP.

	* HttpsTransportBindingElementTest.cs :
	  added test for GetProperty<T>().


svn path=/trunk/mcs/; revision=154621
Atsushi Eno 15 years ago
parent
commit
73481d620c

+ 6 - 0
mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog

@@ -1,3 +1,9 @@
+2010-04-01  Atsushi Enomoto  <[email protected]>
+
+	* HttpTransportBindingElement.cs, HttpsTransportBindingElement.cs:
+	  implement HttpsTransportBindingElement.GetProperty<T>(). Extend the
+	  properties type from HTTP.
+
 2010-04-01  Atsushi Enomoto  <[email protected]>
 
 	* FaultConverter.cs : use addressing version from the message.

+ 44 - 42
mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpTransportBindingElement.cs

@@ -223,61 +223,63 @@ namespace System.ServiceModel.Channels
 		{
 			throw new NotImplementedException ();
 		}
+#endif
+	}
 
-		class HttpBindingProperties : ISecurityCapabilities, IBindingDeliveryCapabilities
-		{
-			HttpTransportBindingElement source;
+#if !NET_2_1
+	class HttpBindingProperties : ISecurityCapabilities, IBindingDeliveryCapabilities
+	{
+		HttpTransportBindingElement source;
 
-			public HttpBindingProperties (HttpTransportBindingElement source)
-			{
-				this.source = source;
-			}
+		public HttpBindingProperties (HttpTransportBindingElement source)
+		{
+			this.source = source;
+		}
 
-			public bool AssuresOrderedDelivery {
-				get { return false; }
-			}
+		public bool AssuresOrderedDelivery {
+			get { return false; }
+		}
 
-			public bool QueuedDelivery {
-				get { return false; }
-			}
+		public bool QueuedDelivery {
+			get { return false; }
+		}
 
-			public ProtectionLevel SupportedRequestProtectionLevel {
-				get { return ProtectionLevel.None; }
-			}
+		public virtual ProtectionLevel SupportedRequestProtectionLevel {
+			get { return ProtectionLevel.None; }
+		}
 
-			public ProtectionLevel SupportedResponseProtectionLevel {
-				get { return ProtectionLevel.None; }
-			}
+		public virtual ProtectionLevel SupportedResponseProtectionLevel {
+			get { return ProtectionLevel.None; }
+		}
 
-			public bool SupportsClientAuthentication {
-				get { return source.AuthenticationScheme != AuthenticationSchemes.Anonymous; }
-			}
+		public virtual bool SupportsClientAuthentication {
+			get { return source.AuthenticationScheme != AuthenticationSchemes.Anonymous; }
+		}
 
-			public bool SupportsServerAuthentication {
-				get {
-					switch (source.AuthenticationScheme) {
-					case AuthenticationSchemes.Negotiate:
-						return true;
-					default:
-						return false;
-					}
+		public virtual bool SupportsServerAuthentication {
+			get {
+				switch (source.AuthenticationScheme) {
+				case AuthenticationSchemes.Negotiate:
+					return true;
+				default:
+					return false;
 				}
 			}
+		}
 
-			public bool SupportsClientWindowsIdentity {
-				get {
-					switch (source.AuthenticationScheme) {
-					case AuthenticationSchemes.Basic:
-					case AuthenticationSchemes.Digest: // hmm... why? but they return true on .NET
-					case AuthenticationSchemes.Negotiate:
-					case AuthenticationSchemes.Ntlm:
-						return true;
-					default:
-						return false;
-					}
+		public virtual bool SupportsClientWindowsIdentity {
+			get {
+				switch (source.AuthenticationScheme) {
+				case AuthenticationSchemes.Basic:
+				case AuthenticationSchemes.Digest: // hmm... why? but they return true on .NET
+				case AuthenticationSchemes.Negotiate:
+				case AuthenticationSchemes.Ntlm:
+					return true;
+				default:
+					return false;
 				}
 			}
 		}
-#endif
 	}
+#endif
 }

+ 41 - 0
mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpsTransportBindingElement.cs

@@ -89,6 +89,47 @@ namespace System.ServiceModel.Channels
 		{
 			throw new NotImplementedException ();
 		}
+
+		// overriden only in full profile
+		public override T GetProperty<T> (BindingContext context)
+		{
+			if (typeof (T) == typeof (ISecurityCapabilities))
+				return (T) (object) new HttpsBindingProperties (this);
+			return base.GetProperty<T> (context);
+		}
 #endif
 	}
+
+#if !NET_2_1
+	class HttpsBindingProperties : HttpBindingProperties
+	{
+		HttpsTransportBindingElement source;
+
+		public HttpsBindingProperties (HttpsTransportBindingElement source)
+			: base (source)
+		{
+			this.source = source;
+		}
+
+		public override ProtectionLevel SupportedRequestProtectionLevel {
+			get { return ProtectionLevel.EncryptAndSign; }
+		}
+
+		public override ProtectionLevel SupportedResponseProtectionLevel {
+			get { return ProtectionLevel.EncryptAndSign; }
+		}
+
+		public override bool SupportsClientAuthentication {
+			get { return source.RequireClientCertificate || base.SupportsClientAuthentication; }
+		}
+
+		public override bool SupportsServerAuthentication {
+			get { return true; }
+		}
+
+		public override bool SupportsClientWindowsIdentity {
+			get { return source.RequireClientCertificate || base.SupportsClientWindowsIdentity; }
+		}
+	}
+#endif
 }

+ 5 - 0
mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog

@@ -1,3 +1,8 @@
+2010-04-01  Atsushi Enomoto  <[email protected]>
+
+	* HttpsTransportBindingElementTest.cs :
+	  added test for GetProperty<T>().
+
 2010-03-29  Atsushi Enomoto  <[email protected]>
 
 	* FaultConverterTest.cs : added more TryCreateException() tests.

+ 18 - 0
mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/HttpsTransportBindingElementTest.cs

@@ -62,5 +62,23 @@ namespace MonoTests.System.ServiceModel.Channels
 			b.Security.Mode = BasicHttpSecurityMode.Transport;
 			b.BuildChannelListener<IReplyChannel> (new Uri ("http://localhost:8080"));
 		}
+
+		[Test]
+		public void GetProperty ()
+		{
+			var b = new HttpsTransportBindingElement ();
+			var s = b.GetProperty<ISecurityCapabilities> (new BindingContext (new CustomBinding (), new BindingParameterCollection ()));
+			Assert.IsNotNull (s, "#1");
+			Assert.AreEqual (ProtectionLevel.EncryptAndSign, s.SupportedRequestProtectionLevel, "#2");
+			Assert.AreEqual (ProtectionLevel.EncryptAndSign, s.SupportedResponseProtectionLevel, "#3");
+			Assert.IsFalse (s.SupportsClientAuthentication, "#4");
+			Assert.IsFalse (s.SupportsClientWindowsIdentity, "#5");
+			Assert.IsTrue (s.SupportsServerAuthentication, "#6");
+
+			b.RequireClientCertificate = true;
+			s = b.GetProperty<ISecurityCapabilities> (new BindingContext (new CustomBinding (), new BindingParameterCollection ()));
+			Assert.IsTrue (s.SupportsClientAuthentication, "#7");
+			Assert.IsTrue (s.SupportsClientWindowsIdentity, "#8");
+		}
 	}
 }