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 using System.IdentityModel.Selectors;
29 using System.IdentityModel.Tokens;
30 using System.ServiceModel.Channels;
31 using System.ServiceModel.Security;
33 using ReqType = System.ServiceModel.Security.Tokens.ServiceModelSecurityTokenRequirement;
35 namespace System.ServiceModel.Security.Tokens
37 public class SecureConversationSecurityTokenParameters : SecurityTokenParameters
39 static readonly ChannelProtectionRequirements default_channel_protection_requirements;
40 static readonly BindingContext dummy_context;
42 static SecureConversationSecurityTokenParameters ()
44 ChannelProtectionRequirements r =
45 new ChannelProtectionRequirements ();
46 r.IncomingSignatureParts.ChannelParts.IsBodyIncluded = true;
47 r.OutgoingSignatureParts.ChannelParts.IsBodyIncluded = true;
48 r.IncomingEncryptionParts.ChannelParts.IsBodyIncluded = true;
49 r.OutgoingEncryptionParts.ChannelParts.IsBodyIncluded = true;
51 default_channel_protection_requirements = r;
53 dummy_context = new BindingContext (
55 new BindingParameterCollection ());
58 SecurityBindingElement element;
59 ChannelProtectionRequirements requirements;
62 public SecureConversationSecurityTokenParameters ()
63 : this ((SecurityBindingElement) null)
67 public SecureConversationSecurityTokenParameters (
68 SecurityBindingElement element)
69 : this (element, true)
73 public SecureConversationSecurityTokenParameters (
74 SecurityBindingElement element,
75 bool requireCancellation)
76 : this (element, requireCancellation, null)
80 public SecureConversationSecurityTokenParameters (
81 SecurityBindingElement element,
82 bool requireCancellation,
83 ChannelProtectionRequirements requirements)
85 this.element = element;
86 this.cancellable = requireCancellation;
87 if (requirements == null)
88 this.requirements = new ChannelProtectionRequirements (default_channel_protection_requirements);
90 this.requirements = new ChannelProtectionRequirements (requirements);
93 protected SecureConversationSecurityTokenParameters (SecureConversationSecurityTokenParameters source)
96 this.element = (SecurityBindingElement) source.element.Clone ();
97 this.cancellable = source.cancellable;
98 this.requirements = new ChannelProtectionRequirements (default_channel_protection_requirements);
101 public bool RequireCancellation {
102 get { return cancellable; }
103 set { cancellable = value; }
106 public SecurityBindingElement BootstrapSecurityBindingElement {
107 get { return element; }
108 set { element = value; }
111 public ChannelProtectionRequirements BootstrapProtectionRequirements {
112 get { return requirements; }
115 // SecurityTokenParameters
117 protected override bool HasAsymmetricKey {
118 get { return false; }
121 protected override bool SupportsClientAuthentication {
122 get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsClientAuthentication; }
125 protected override bool SupportsClientWindowsIdentity {
126 get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsClientWindowsIdentity; }
129 protected override bool SupportsServerAuthentication {
130 get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsServerAuthentication; }
133 protected override SecurityTokenParameters CloneCore ()
135 return new SecureConversationSecurityTokenParameters (this);
139 protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause (
140 SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
142 throw new NotImplementedException ();
146 protected internal override void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
148 // .NET somehow causes NRE. dunno why.
149 requirement.TokenType = ServiceModelSecurityTokenTypes.SecureConversation;
150 requirement.RequireCryptographicToken = true;
151 requirement.Properties [ReqType.SupportSecurityContextCancellationProperty] = RequireCancellation;
152 requirement.Properties [ReqType.SecureConversationSecurityBindingElementProperty] =
153 BootstrapSecurityBindingElement;
154 requirement.Properties [ReqType.IssuedSecurityTokenParametersProperty] = this.Clone ();
155 requirement.KeyType = SecurityKeyType.SymmetricKey;
158 public override string ToString ()
160 return base.ToString ();