2 // SecureConversationSecurityTokenParameters.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2006-2007 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 #if !MOBILE && !XAMMAC_4_5
29 using System.IdentityModel.Selectors;
30 using System.IdentityModel.Tokens;
32 using System.ServiceModel.Channels;
33 using System.ServiceModel.Security;
35 #if !MOBILE && !XAMMAC_4_5
36 using ReqType = System.ServiceModel.Security.Tokens.ServiceModelSecurityTokenRequirement;
39 namespace System.ServiceModel.Security.Tokens
41 public class SecureConversationSecurityTokenParameters : SecurityTokenParameters
43 #if !MOBILE && !XAMMAC_4_5
44 static readonly ChannelProtectionRequirements default_channel_protection_requirements;
46 static readonly BindingContext dummy_context;
48 static SecureConversationSecurityTokenParameters ()
50 #if !MOBILE && !XAMMAC_4_5
51 ChannelProtectionRequirements r =
52 new ChannelProtectionRequirements ();
53 r.IncomingSignatureParts.ChannelParts.IsBodyIncluded = true;
54 r.OutgoingSignatureParts.ChannelParts.IsBodyIncluded = true;
55 r.IncomingEncryptionParts.ChannelParts.IsBodyIncluded = true;
56 r.OutgoingEncryptionParts.ChannelParts.IsBodyIncluded = true;
58 default_channel_protection_requirements = r;
61 dummy_context = new BindingContext (
63 new BindingParameterCollection ());
66 SecurityBindingElement element;
67 #if !MOBILE && !XAMMAC_4_5
68 ChannelProtectionRequirements requirements;
72 public SecureConversationSecurityTokenParameters ()
73 : this ((SecurityBindingElement) null)
77 public SecureConversationSecurityTokenParameters (
78 SecurityBindingElement bootstrapSecurityBindingElement)
79 : this (bootstrapSecurityBindingElement, true)
83 public SecureConversationSecurityTokenParameters (
84 SecurityBindingElement bootstrapSecurityBindingElement,
85 bool requireCancellation)
86 : this (bootstrapSecurityBindingElement, requireCancellation, null)
90 #if !MOBILE && !XAMMAC_4_5
91 public SecureConversationSecurityTokenParameters (
92 SecurityBindingElement bootstrapSecurityBindingElement,
93 bool requireCancellation,
94 ChannelProtectionRequirements bootstrapProtectionRequirements)
96 this.element = bootstrapSecurityBindingElement;
97 this.cancellable = requireCancellation;
98 if (bootstrapProtectionRequirements == null)
99 this.requirements = new ChannelProtectionRequirements (default_channel_protection_requirements);
101 this.requirements = new ChannelProtectionRequirements (bootstrapProtectionRequirements);
104 internal SecureConversationSecurityTokenParameters (
105 SecurityBindingElement element,
106 bool requireCancellation,
109 this.element = element;
110 this.cancellable = requireCancellation;
114 protected SecureConversationSecurityTokenParameters (SecureConversationSecurityTokenParameters source)
117 this.element = (SecurityBindingElement) source.element.Clone ();
118 this.cancellable = source.cancellable;
119 #if !MOBILE && !XAMMAC_4_5
120 this.requirements = new ChannelProtectionRequirements (default_channel_protection_requirements);
124 public bool RequireCancellation {
125 get { return cancellable; }
126 set { cancellable = value; }
129 public SecurityBindingElement BootstrapSecurityBindingElement {
130 get { return element; }
131 set { element = value; }
134 #if !MOBILE && !XAMMAC_4_5
135 public ChannelProtectionRequirements BootstrapProtectionRequirements {
136 get { return requirements; }
140 // SecurityTokenParameters
142 protected override bool HasAsymmetricKey {
143 get { return false; }
146 protected override bool SupportsClientAuthentication {
147 get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsClientAuthentication; }
150 protected override bool SupportsClientWindowsIdentity {
151 get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsClientWindowsIdentity; }
154 protected override bool SupportsServerAuthentication {
155 get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsServerAuthentication; }
158 protected override SecurityTokenParameters CloneCore ()
160 return new SecureConversationSecurityTokenParameters (this);
163 #if !MOBILE && !XAMMAC_4_5
165 protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause (
166 SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
168 throw new NotImplementedException ();
171 protected internal override void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
173 // .NET somehow causes NRE. dunno why.
174 requirement.TokenType = ServiceModelSecurityTokenTypes.SecureConversation;
175 requirement.RequireCryptographicToken = true;
176 requirement.Properties [ReqType.SupportSecurityContextCancellationProperty] = RequireCancellation;
177 requirement.Properties [ReqType.SecureConversationSecurityBindingElementProperty] =
178 BootstrapSecurityBindingElement;
179 requirement.Properties [ReqType.IssuedSecurityTokenParametersProperty] = this.Clone ();
180 requirement.KeyType = SecurityKeyType.SymmetricKey;
184 public override string ToString ()
186 return base.ToString ();