2 // X509SecurityTokenParameters.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.
28 using System.IdentityModel.Selectors;
29 using System.IdentityModel.Tokens;
30 using System.ServiceModel.Security;
32 namespace System.ServiceModel.Security.Tokens
34 public class X509SecurityTokenParameters : SecurityTokenParameters
36 X509KeyIdentifierClauseType reference_style;
38 public X509SecurityTokenParameters ()
39 : this (X509KeyIdentifierClauseType.Any)
43 public X509SecurityTokenParameters (X509KeyIdentifierClauseType x509ReferenceStyle)
44 : this (x509ReferenceStyle, SecurityTokenInclusionMode.AlwaysToRecipient)
48 public X509SecurityTokenParameters (X509KeyIdentifierClauseType x509ReferenceStyle, SecurityTokenInclusionMode inclusionMode)
50 reference_style = x509ReferenceStyle;
51 InclusionMode = inclusionMode;
54 protected X509SecurityTokenParameters (X509SecurityTokenParameters source)
57 reference_style = source.reference_style;
60 public X509KeyIdentifierClauseType X509ReferenceStyle {
61 get { return reference_style; }
62 set { reference_style = value; }
65 // It is documented as to return false, but that is wrong.
66 protected override bool HasAsymmetricKey {
70 protected override bool SupportsClientAuthentication {
74 protected override bool SupportsClientWindowsIdentity {
78 protected override bool SupportsServerAuthentication {
82 protected override SecurityTokenParameters CloneCore ()
84 return new X509SecurityTokenParameters (this);
87 protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause (
88 SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
91 throw new ArgumentNullException ("token");
93 if (referenceStyle == SecurityTokenReferenceStyle.Internal)
94 return new LocalIdKeyIdentifierClause (token.Id, token.GetType ());
96 switch (reference_style) {
98 return token.CreateKeyIdentifierClause<X509IssuerSerialKeyIdentifierClause> ();
99 case X509KeyIdentifierClauseType.Thumbprint:
100 return token.CreateKeyIdentifierClause<X509ThumbprintKeyIdentifierClause> ();
101 case X509KeyIdentifierClauseType.SubjectKeyIdentifier:
102 return token.CreateKeyIdentifierClause<X509SubjectKeyIdentifierClause> ();
103 case X509KeyIdentifierClauseType.RawDataKeyIdentifier:
104 return token.CreateKeyIdentifierClause<X509RawDataKeyIdentifierClause> ();
105 case X509KeyIdentifierClauseType.Any:
106 if (token.CanCreateKeyIdentifierClause<X509SubjectKeyIdentifierClause> ())
107 goto case X509KeyIdentifierClauseType.SubjectKeyIdentifier;
112 protected internal override void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
114 requirement.TokenType = SecurityTokenTypes.X509Certificate;
115 requirement.KeyType = SecurityKeyType.AsymmetricKey;
116 requirement.RequireCryptographicToken = true;
119 public override string ToString ()
121 return base.ToString ();