2010-07-27 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel / WSFederationHttpBinding.cs
1 //
2 // WSFederationHttpBinding.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.  http://www.novell.com
8 //
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:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
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.
27 //
28 using System;
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;
35
36 namespace System.ServiceModel
37 {
38         public class WSFederationHttpBinding : WSHttpBindingBase
39         {
40                 WSFederationHttpSecurity security;
41                 Uri privacy_notice_at;
42                 int privacy_notice_ver;
43                 bool allow_cookies;
44
45                 public WSFederationHttpBinding ()
46                         : this (WSFederationHttpSecurityMode.Message)
47                 {
48                 }
49
50                 public WSFederationHttpBinding (
51                         WSFederationHttpSecurityMode securityMode)
52                         : this (securityMode, true)
53                 {
54                 }
55
56                 public WSFederationHttpBinding (
57                         WSFederationHttpSecurityMode securityMode,
58                         bool reliableSessionEnabled)
59                 {
60                         security = new WSFederationHttpSecurity (securityMode);
61                 }
62
63                 [MonoTODO]
64                 public WSFederationHttpBinding (string configurationName)
65                 {
66                         throw new NotImplementedException ();
67                 }
68
69                 [MonoTODO]
70                 public bool AllowCookies {
71                         get { return allow_cookies; }
72                         set { allow_cookies = value; }
73                 }
74
75                 [MonoTODO]
76                 public Uri PrivacyNoticeAt {
77                         get { return privacy_notice_at; }
78                         set { privacy_notice_at = value; }
79                 }
80
81                 [MonoTODO]
82                 public int PrivacyNoticeVersion {
83                         get { return privacy_notice_ver; }
84                         set { privacy_notice_ver = value; }
85                 }
86
87                 [MonoTODO]
88                 public WSFederationHttpSecurity Security {
89                         get { return security; }
90                 }
91
92                 [MonoTODO]
93                 public override BindingElementCollection CreateBindingElements ()
94                 {
95                         return base.CreateBindingElements ();
96                 }
97
98                 [MonoTODO]
99                 protected override SecurityBindingElement CreateMessageSecurity ()
100                 {
101                         SymmetricSecurityBindingElement element =
102                                 new SymmetricSecurityBindingElement ();
103
104                         element.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
105
106 //                      if (!Security.Message.EstablishSecurityContext)
107 //                              element.SetKeyDerivation (false);
108
109                         IssuedSecurityTokenParameters istp =
110                                 new IssuedSecurityTokenParameters ();
111                         // FIXME: issuer binding must be secure.
112                         istp.IssuerBinding = new CustomBinding (
113                                 new TextMessageEncodingBindingElement (),
114                                 GetTransport ());
115                         element.EndpointSupportingTokenParameters.Endorsing.Add (istp);
116
117                         if (Security.Message.NegotiateServiceCredential) {
118                                 element.ProtectionTokenParameters =
119                                         // FIXME: fill proper parameters
120                                         new SslSecurityTokenParameters (false, true);
121                         } else {
122                                 element.ProtectionTokenParameters =
123                                         new X509SecurityTokenParameters ();
124                         }
125
126 //                      if (!Security.Message.EstablishSecurityContext)
127 //                              return element;
128
129                         // SecureConversation enabled
130
131                         ChannelProtectionRequirements reqs =
132                                 new ChannelProtectionRequirements ();
133                         // FIXME: fill the reqs
134
135                         // FIXME: for TransportWithMessageCredential mode,
136                         // return TransportSecurityBindingElement.
137
138                         return SecurityBindingElement.CreateSecureConversationBindingElement (
139                                 // FIXME: requireCancellation
140                                 element, true, reqs);
141                 }
142
143                 [MonoTODO]
144                 protected override TransportBindingElement GetTransport ()
145                 {
146                         switch (Security.Mode) {
147                         case WSFederationHttpSecurityMode.TransportWithMessageCredential:
148                                 return new HttpsTransportBindingElement ();
149                         default:
150                                 return new HttpTransportBindingElement ();
151                         }
152                 }
153         }
154 }