2 // WSFederationHttpBinding.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2006 Novell, Inc. http://www.novell.com
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Collections.Generic;
30 using System.Net.Security;
31 using System.ServiceModel.Channels;
32 using System.ServiceModel.Description;
33 using System.ServiceModel.Security;
34 using System.ServiceModel.Security.Tokens;
36 namespace System.ServiceModel
38 public class WSFederationHttpBinding : WSHttpBindingBase
40 WSFederationHttpSecurity security;
41 Uri privacy_notice_at;
42 int privacy_notice_ver;
45 public WSFederationHttpBinding ()
46 : this (WSFederationHttpSecurityMode.Message)
50 public WSFederationHttpBinding (
51 WSFederationHttpSecurityMode securityMode)
52 : this (securityMode, true)
56 public WSFederationHttpBinding (
57 WSFederationHttpSecurityMode securityMode,
58 bool reliableSessionEnabled)
60 security = new WSFederationHttpSecurity (securityMode);
64 public WSFederationHttpBinding (string configurationName)
66 throw new NotImplementedException ();
70 public bool AllowCookies {
71 get { return allow_cookies; }
72 set { allow_cookies = value; }
76 public Uri PrivacyNoticeAt {
77 get { return privacy_notice_at; }
78 set { privacy_notice_at = value; }
82 public int PrivacyNoticeVersion {
83 get { return privacy_notice_ver; }
84 set { privacy_notice_ver = value; }
88 public WSFederationHttpSecurity Security {
89 get { return security; }
93 public override BindingElementCollection CreateBindingElements ()
95 return base.CreateBindingElements ();
99 protected override SecurityBindingElement CreateMessageSecurity ()
101 SymmetricSecurityBindingElement element =
102 new SymmetricSecurityBindingElement ();
104 element.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
106 // if (!Security.Message.EstablishSecurityContext)
107 // element.SetKeyDerivation (false);
109 IssuedSecurityTokenParameters istp =
110 new IssuedSecurityTokenParameters ();
111 // FIXME: issuer binding must be secure.
112 istp.IssuerBinding = new CustomBinding (
113 new TextMessageEncodingBindingElement (),
115 element.EndpointSupportingTokenParameters.Endorsing.Add (istp);
117 if (Security.Message.NegotiateServiceCredential) {
118 element.ProtectionTokenParameters =
119 // FIXME: fill proper parameters
120 new SslSecurityTokenParameters (false, true);
122 element.ProtectionTokenParameters =
123 new X509SecurityTokenParameters ();
126 // if (!Security.Message.EstablishSecurityContext)
129 // SecureConversation enabled
131 ChannelProtectionRequirements reqs =
132 new ChannelProtectionRequirements ();
133 // FIXME: fill the reqs
135 // FIXME: for TransportWithMessageCredential mode,
136 // return TransportSecurityBindingElement.
138 return SecurityBindingElement.CreateSecureConversationBindingElement (
139 // FIXME: requireCancellation
140 element, true, reqs);
144 protected override TransportBindingElement GetTransport ()
146 switch (Security.Mode) {
147 case WSFederationHttpSecurityMode.TransportWithMessageCredential:
148 return new HttpsTransportBindingElement ();
150 return new HttpTransportBindingElement ();