Merge pull request #3248 from esdrubal/web_request_abort
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Security.Tokens / SecurityTokenParameters.cs
1 //
2 // SecurityTokenParameters.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
29 #if !MOBILE && !XAMMAC_4_5
30 using System.IdentityModel.Selectors;
31 using System.IdentityModel.Tokens;
32 #endif
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Security;
35 using System.Text;
36
37 namespace System.ServiceModel.Security.Tokens
38 {
39         public abstract class SecurityTokenParameters
40         {
41                 protected SecurityTokenParameters ()
42                 {
43                 }
44
45                 protected SecurityTokenParameters (SecurityTokenParameters other)
46                 {
47                         inclusion_mode = other.inclusion_mode;
48                         reference_style = other.reference_style;
49                         require_derived_keys = other.require_derived_keys;
50                         issuer_binding_context = other.issuer_binding_context != null ? other.issuer_binding_context.Clone () : null;
51                 }
52
53                 SecurityTokenInclusionMode inclusion_mode;
54                 SecurityTokenReferenceStyle reference_style;
55                 bool require_derived_keys = true;
56                 BindingContext issuer_binding_context;
57
58                 public SecurityTokenInclusionMode InclusionMode {
59                         get { return inclusion_mode; }
60                         set { inclusion_mode = value; }
61                 }
62
63                 public SecurityTokenReferenceStyle ReferenceStyle {
64                         get { return reference_style; }
65                         set { reference_style = value; }
66                 }
67
68                 public bool RequireDerivedKeys {
69                         get { return require_derived_keys; }
70                         set { require_derived_keys = value; }
71                 }
72
73                 public SecurityTokenParameters Clone ()
74                 {
75                         return CloneCore ();
76                 }
77
78                 public override string ToString ()
79                 {
80                         var sb = new StringBuilder ();
81                         sb.Append (GetType ().FullName).Append (":\n");
82                         foreach (var pi in GetType ().GetProperties ()) {
83                                 var simple = Type.GetTypeCode (pi.PropertyType) != TypeCode.Object;
84                                 var val = pi.GetValue (this, null);
85                                 sb.Append (pi.Name).Append (':');
86                                 if (val != null)
87                                         sb.AppendFormat ("{0}{1}{2}", simple ? " " : "\n", simple ? "" : "  ", String.Join ("\n  ", val.ToString ().Split ('\n')));
88                                 sb.Append ('\n');
89                         }
90                         sb.Length--; // chop trailing EOL.
91                         return sb.ToString ();
92                 }
93
94                 protected abstract bool HasAsymmetricKey { get; }
95
96                 protected abstract bool SupportsClientAuthentication { get; }
97
98                 protected abstract bool SupportsClientWindowsIdentity { get; }
99
100                 protected abstract bool SupportsServerAuthentication { get; }
101
102                 internal bool InternalHasAsymmetricKey {
103                         get { return HasAsymmetricKey; }
104                 }
105
106                 internal bool InternalSupportsClientAuthentication {
107                         get { return SupportsClientAuthentication; }
108                 }
109
110                 internal bool InternalSupportsClientWindowsIdentity {
111                         get { return SupportsClientWindowsIdentity; }
112                 }
113
114                 internal bool InternalSupportsServerAuthentication {
115                         get { return SupportsServerAuthentication; }
116                 }
117
118                 protected abstract SecurityTokenParameters CloneCore ();
119
120 #if !MOBILE && !XAMMAC_4_5
121                 protected abstract SecurityKeyIdentifierClause CreateKeyIdentifierClause (
122                         SecurityToken token, SecurityTokenReferenceStyle referenceStyle);
123
124                 // internalized call to CreateKeyIdentifierClause()
125                 internal SecurityKeyIdentifierClause CallCreateKeyIdentifierClause (
126                         SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
127                 {
128                         return CreateKeyIdentifierClause (token, referenceStyle);
129                 }
130
131                 protected internal abstract void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement);
132 #endif
133
134                 internal BindingContext IssuerBindingContext {
135                         set { issuer_binding_context = value; }
136                 }
137
138 #if !MOBILE && !XAMMAC_4_5
139                 internal void CallInitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
140                 {
141                         if (issuer_binding_context != null)
142                                 requirement.Properties [ServiceModelSecurityTokenRequirement.IssuerBindingContextProperty] = issuer_binding_context;
143                         InitializeSecurityTokenRequirement (requirement);
144                 }
145
146                 [MonoTODO]
147                 protected virtual bool MatchesKeyIdentifierClause (
148                         SecurityToken token,
149                         SecurityKeyIdentifierClause keyIdentifierClause,
150                         SecurityTokenReferenceStyle referenceStyle)
151                 {
152                         throw new NotImplementedException ();
153                 }
154 #endif
155         }
156 }