2 // ClientCredentials.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005-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.ServiceModel.Channels;
31 using System.ServiceModel.Description;
32 using System.ServiceModel.Dispatcher;
33 using System.ServiceModel.Security;
35 using System.IdentityModel.Selectors;
36 using System.IdentityModel.Tokens;
37 using System.ServiceModel.Security.Tokens;
40 namespace System.ServiceModel.Description
42 public class ClientCredentials
43 #if MOBILE || XAMMAC_4_5
46 : SecurityCredentialsManager, IEndpointBehavior
49 public ClientCredentials ()
54 protected ClientCredentials (ClientCredentials source)
56 userpass = source.userpass.Clone ();
57 digest = source.digest.Clone ();
58 initiator = source.initiator.Clone ();
59 recipient = source.recipient.Clone ();
60 windows = source.windows.Clone ();
62 issued_token = source.issued_token.Clone ();
63 peer = source.peer.Clone ();
64 support_interactive = source.support_interactive;
68 UserNamePasswordClientCredential userpass =
69 new UserNamePasswordClientCredential ();
71 HttpDigestClientCredential digest =
72 new HttpDigestClientCredential ();
73 X509CertificateInitiatorClientCredential initiator =
74 new X509CertificateInitiatorClientCredential ();
75 X509CertificateRecipientClientCredential recipient =
76 new X509CertificateRecipientClientCredential ();
77 WindowsClientCredential windows =
78 new WindowsClientCredential ();
80 public X509CertificateInitiatorClientCredential ClientCertificate {
81 get { return initiator; }
84 public HttpDigestClientCredential HttpDigest {
85 get { return digest; }
88 public X509CertificateRecipientClientCredential ServiceCertificate {
89 get { return recipient; }
92 public WindowsClientCredential Windows {
93 get { return windows; }
97 IssuedTokenClientCredential issued_token =
98 new IssuedTokenClientCredential ();
99 PeerCredential peer = new PeerCredential ();
100 bool support_interactive = true;
102 public IssuedTokenClientCredential IssuedToken {
103 get { return issued_token; }
106 public PeerCredential Peer {
110 public bool SupportInteractive {
111 get { return support_interactive; }
112 set { support_interactive = value; }
116 public UserNamePasswordClientCredential UserName {
117 get { return userpass; }
120 public ClientCredentials Clone ()
122 ClientCredentials ret = CloneCore ();
123 if (ret.GetType () != GetType ())
124 throw new NotImplementedException ("CloneCore() must be implemented to return an instance of the same type in this custom ClientCredentials type.");
128 protected virtual ClientCredentials CloneCore ()
130 return new ClientCredentials (this);
133 #if !MOBILE && !XAMMAC_4_5
134 public override SecurityTokenManager CreateSecurityTokenManager ()
136 return new ClientCredentialsSecurityTokenManager (this);
140 protected virtual SecurityToken GetInfoCardSecurityToken (
141 bool requiresInfoCard, CardSpacePolicyElement [] chain,
142 SecurityTokenSerializer tokenSerializer)
144 throw new NotImplementedException ();
148 void IEndpointBehavior.ApplyDispatchBehavior (ServiceEndpoint endpoint,
149 EndpointDispatcher dispatcher)
151 // documented as to have no effect.
154 void IEndpointBehavior.AddBindingParameters (ServiceEndpoint endpoint,
155 BindingParameterCollection parameters)
157 parameters.Add (this);
161 public virtual void ApplyClientBehavior (
162 ServiceEndpoint endpoint, ClientRuntime behavior)
164 if (endpoint == null)
165 throw new ArgumentNullException ("endpoint");
166 if (behavior == null)
167 throw new ArgumentNullException ("behavior");
169 // FIXME: apply to endpoint when there is not security binding element.
172 void IEndpointBehavior.Validate (ServiceEndpoint endpoint)
174 // documented as reserved for future use.