Couple more 'bockbuild split' mixups
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Security.Tokens / X509SecurityTokenParameters.cs
1 //
2 // X509SecurityTokenParameters.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.IdentityModel.Selectors;
29 using System.IdentityModel.Tokens;
30 using System.ServiceModel.Security;
31
32 namespace System.ServiceModel.Security.Tokens
33 {
34         public class X509SecurityTokenParameters : SecurityTokenParameters
35         {
36                 X509KeyIdentifierClauseType reference_style;
37
38                 public X509SecurityTokenParameters ()
39                         : this (X509KeyIdentifierClauseType.Any)
40                 {
41                 }
42
43                 public X509SecurityTokenParameters (X509KeyIdentifierClauseType x509ReferenceStyle)
44                         : this (x509ReferenceStyle, SecurityTokenInclusionMode.AlwaysToRecipient)
45                 {
46                 }
47
48                 public X509SecurityTokenParameters (X509KeyIdentifierClauseType x509ReferenceStyle, SecurityTokenInclusionMode inclusionMode)
49                 {
50                         reference_style = x509ReferenceStyle;
51                         InclusionMode = inclusionMode;
52                 }
53
54                 protected X509SecurityTokenParameters (X509SecurityTokenParameters source)
55                         : base (source)
56                 {
57                         reference_style = source.reference_style;
58                 }
59
60                 public X509KeyIdentifierClauseType X509ReferenceStyle {
61                         get { return reference_style; }
62                         set { reference_style = value; }
63                 }
64
65                 // It is documented as to return false, but that is wrong.
66                 protected override bool HasAsymmetricKey {
67                         get { return true; }
68                 }
69
70                 protected override bool SupportsClientAuthentication {
71                         get { return true; }
72                 }
73
74                 protected override bool SupportsClientWindowsIdentity {
75                         get { return true; }
76                 }
77
78                 protected override bool SupportsServerAuthentication {
79                         get { return true; }
80                 }
81
82                 protected override SecurityTokenParameters CloneCore ()
83                 {
84                         return new X509SecurityTokenParameters (this);
85                 }
86
87                 protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause (
88                         SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
89                 {
90                         if (token == null)
91                                 throw new ArgumentNullException ("token");
92
93                         if (referenceStyle == SecurityTokenReferenceStyle.Internal)
94                                 return new LocalIdKeyIdentifierClause (token.Id, token.GetType ());
95
96                         switch (reference_style) {
97                         default:
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;
108                                 goto default;
109                         }
110                 }
111
112                 protected internal override void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
113                 {
114                         requirement.TokenType = SecurityTokenTypes.X509Certificate;
115                         requirement.KeyType = SecurityKeyType.AsymmetricKey;
116                         requirement.RequireCryptographicToken = true;
117                 }
118
119                 public override string ToString ()
120                 {
121                         return base.ToString ();
122                 }
123         }
124 }