2010-03-12 Jb Evain <jbevain@novell.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Description / ClientCredentials.cs
1 //
2 // ClientCredentials.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005-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.ServiceModel.Channels;
31 using System.ServiceModel.Description;
32 using System.ServiceModel.Dispatcher;
33 using System.ServiceModel.Security;
34 #if !NET_2_1
35 using System.IdentityModel.Selectors;
36 using System.IdentityModel.Tokens;
37 using System.ServiceModel.Security.Tokens;
38 #endif
39
40 namespace System.ServiceModel.Description
41 {
42         public class ClientCredentials
43 #if NET_2_1
44                 : IEndpointBehavior
45 #else
46                 : SecurityCredentialsManager, IEndpointBehavior
47 #endif
48         {
49                 public ClientCredentials ()
50                 {
51                 }
52
53                 [MonoTODO]
54                 protected ClientCredentials (ClientCredentials source)
55                 {
56                         throw new NotImplementedException ();
57                 }
58
59                 UserNamePasswordClientCredential userpass =
60                         new UserNamePasswordClientCredential ();
61 #if !NET_2_1
62                 IssuedTokenClientCredential issued_token =
63                         new IssuedTokenClientCredential ();
64                 HttpDigestClientCredential digest =
65                         new HttpDigestClientCredential ();
66                 X509CertificateInitiatorClientCredential initiator =
67                         new X509CertificateInitiatorClientCredential ();
68                 X509CertificateRecipientClientCredential recipient =
69                         new X509CertificateRecipientClientCredential ();
70                 WindowsClientCredential windows =
71                         new WindowsClientCredential ();
72                 PeerCredential peer = new PeerCredential ();
73                 bool support_interactive = true;
74
75                 public X509CertificateInitiatorClientCredential ClientCertificate {
76                         get { return initiator; }
77                 }
78
79                 public HttpDigestClientCredential HttpDigest {
80                         get { return digest; }
81                 }
82
83                 public IssuedTokenClientCredential IssuedToken {
84                         get { return issued_token; }
85                 }
86
87                 public PeerCredential Peer {
88                         get { return peer; }
89                 }
90
91                 public X509CertificateRecipientClientCredential ServiceCertificate {
92                         get { return recipient; }
93                 }
94
95                 public bool SupportInteractive {
96                         get { return support_interactive; }
97                         set { support_interactive = value; }
98                 }
99
100                 public WindowsClientCredential Windows {
101                         get { return windows; }
102                 }
103 #endif
104
105                 public UserNamePasswordClientCredential UserName {
106                         get { return userpass; }
107                 }
108
109                 public ClientCredentials Clone ()
110                 {
111                         ClientCredentials ret = CloneCore ();
112                         if (ret.GetType () != GetType ())
113                                 throw new NotImplementedException ("CloneCore() must be implemented to return an instance of the same type in this custom ClientCredentials type.");
114                         return ret;
115                 }
116
117                 protected virtual ClientCredentials CloneCore ()
118                 {
119                         return new ClientCredentials (this);
120                 }
121
122 #if !NET_2_1
123                 public override SecurityTokenManager CreateSecurityTokenManager ()
124                 {
125                         return new ClientCredentialsSecurityTokenManager (this);
126                 }
127
128                 [MonoTODO]
129                 protected virtual SecurityToken GetInfoCardSecurityToken (
130                         bool requiresInfoCard, CardSpacePolicyElement [] chain,
131                         SecurityTokenSerializer tokenSerializer)
132                 {
133                         throw new NotImplementedException ();
134                 }
135
136                 void IEndpointBehavior.ApplyDispatchBehavior (ServiceEndpoint endpoint,
137                         EndpointDispatcher dispatcher)
138                 {
139                         // documented as to have no effect.
140                 }
141 #endif
142
143 #if !NET_2_1 || MONOTOUCH
144                 void IEndpointBehavior.AddBindingParameters (ServiceEndpoint endpoint,
145                         BindingParameterCollection parameters)
146                 {
147                         parameters.Add (this);
148                 }
149
150                 [MonoTODO]
151                 public virtual void ApplyClientBehavior (
152                         ServiceEndpoint endpoint, ClientRuntime behavior)
153                 {
154                         if (endpoint == null)
155                                 throw new ArgumentNullException ("endpoint");
156                         if (behavior == null)
157                                 throw new ArgumentNullException ("behavior");
158
159                         // FIXME: apply to endpoint when there is not security binding element.
160                 }
161
162                 void IEndpointBehavior.Validate (ServiceEndpoint endpoint)
163                 {
164                         // documented as reserved for future use.
165                 }
166 #endif
167         }
168 }