2 // SecurityTokenParameters.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.
29 #if !MOBILE && !XAMMAC_4_5
30 using System.IdentityModel.Selectors;
31 using System.IdentityModel.Tokens;
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Security;
37 namespace System.ServiceModel.Security.Tokens
39 public abstract class SecurityTokenParameters
41 protected SecurityTokenParameters ()
45 protected SecurityTokenParameters (SecurityTokenParameters other)
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;
53 SecurityTokenInclusionMode inclusion_mode;
54 SecurityTokenReferenceStyle reference_style;
55 bool require_derived_keys = true;
56 BindingContext issuer_binding_context;
58 public SecurityTokenInclusionMode InclusionMode {
59 get { return inclusion_mode; }
60 set { inclusion_mode = value; }
63 public SecurityTokenReferenceStyle ReferenceStyle {
64 get { return reference_style; }
65 set { reference_style = value; }
68 public bool RequireDerivedKeys {
69 get { return require_derived_keys; }
70 set { require_derived_keys = value; }
73 public SecurityTokenParameters Clone ()
78 public override string ToString ()
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 (':');
87 sb.AppendFormat ("{0}{1}{2}", simple ? " " : "\n", simple ? "" : " ", String.Join ("\n ", val.ToString ().Split ('\n')));
90 sb.Length--; // chop trailing EOL.
91 return sb.ToString ();
94 protected abstract bool HasAsymmetricKey { get; }
96 protected abstract bool SupportsClientAuthentication { get; }
98 protected abstract bool SupportsClientWindowsIdentity { get; }
100 protected abstract bool SupportsServerAuthentication { get; }
102 internal bool InternalHasAsymmetricKey {
103 get { return HasAsymmetricKey; }
106 internal bool InternalSupportsClientAuthentication {
107 get { return SupportsClientAuthentication; }
110 internal bool InternalSupportsClientWindowsIdentity {
111 get { return SupportsClientWindowsIdentity; }
114 internal bool InternalSupportsServerAuthentication {
115 get { return SupportsServerAuthentication; }
118 protected abstract SecurityTokenParameters CloneCore ();
120 #if !MOBILE && !XAMMAC_4_5
121 protected abstract SecurityKeyIdentifierClause CreateKeyIdentifierClause (
122 SecurityToken token, SecurityTokenReferenceStyle referenceStyle);
124 // internalized call to CreateKeyIdentifierClause()
125 internal SecurityKeyIdentifierClause CallCreateKeyIdentifierClause (
126 SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
128 return CreateKeyIdentifierClause (token, referenceStyle);
131 protected internal abstract void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement);
134 internal BindingContext IssuerBindingContext {
135 set { issuer_binding_context = value; }
138 #if !MOBILE && !XAMMAC_4_5
139 internal void CallInitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
141 if (issuer_binding_context != null)
142 requirement.Properties [ServiceModelSecurityTokenRequirement.IssuerBindingContextProperty] = issuer_binding_context;
143 InitializeSecurityTokenRequirement (requirement);
147 protected virtual bool MatchesKeyIdentifierClause (
149 SecurityKeyIdentifierClause keyIdentifierClause,
150 SecurityTokenReferenceStyle referenceStyle)
152 throw new NotImplementedException ();