2010-04-01 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 1 Apr 2010 09:13:45 +0000 (09:13 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 1 Apr 2010 09:13:45 +0000 (09:13 -0000)
* 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

mcs/class/System.ServiceModel/System.ServiceModel.Channels/ChangeLog
mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpTransportBindingElement.cs
mcs/class/System.ServiceModel/System.ServiceModel.Channels/HttpsTransportBindingElement.cs
mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/ChangeLog
mcs/class/System.ServiceModel/Test/System.ServiceModel.Channels/HttpsTransportBindingElementTest.cs

index 990043ba47983fa0f73b53180a0bf2f1fe25bafe..c1565386e451c5c24e7149a92483d2ae82212d24 100755 (executable)
@@ -1,3 +1,9 @@
+2010-04-01  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * HttpTransportBindingElement.cs, HttpsTransportBindingElement.cs:
+         implement HttpsTransportBindingElement.GetProperty<T>(). Extend the
+         properties type from HTTP.
+
 2010-04-01  Atsushi Enomoto  <atsushi@ximian.com>
 
        * FaultConverter.cs : use addressing version from the message.
index 3c229390d63e4a7d4d813490b9adc300bd40b69b..313d2fa7fc1733b18bd66c86809c4a8bef6f66e1 100644 (file)
@@ -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
 }
index 396a4276574c4cdafebf497b1ab6ed87e9102232..ad0c83047ef8b2f289fab3683b39167aa051e51c 100644 (file)
@@ -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
 }
index 8baacb77cb0d6a5bf3a594d22eb076718e76e905..5a5dd80b83ac3e245253aebf0d68aae6acf68dec 100644 (file)
@@ -1,3 +1,8 @@
+2010-04-01  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * HttpsTransportBindingElementTest.cs :
+         added test for GetProperty<T>().
+
 2010-03-29  Atsushi Enomoto  <atsushi@ximian.com>
 
        * FaultConverterTest.cs : added more TryCreateException() tests.
index 0e827a934bb05206bc866f9c110d01617f1b107a..caf0d7f827e50ca0e980169689a04ae70708840c 100644 (file)
@@ -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");
+               }
        }
 }