[runtime] Switch getenv to use heap memory
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Security.Tokens / SecureConversationSecurityTokenParameters.cs
1 //
2 // SecureConversationSecurityTokenParameters.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006-2007 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 #if !MOBILE && !XAMMAC_4_5
29 using System.IdentityModel.Selectors;
30 using System.IdentityModel.Tokens;
31 #endif
32 using System.ServiceModel.Channels;
33 using System.ServiceModel.Security;
34
35 #if !MOBILE && !XAMMAC_4_5
36 using ReqType = System.ServiceModel.Security.Tokens.ServiceModelSecurityTokenRequirement;
37 #endif
38
39 namespace System.ServiceModel.Security.Tokens
40 {
41         public class SecureConversationSecurityTokenParameters : SecurityTokenParameters
42         {
43 #if !MOBILE && !XAMMAC_4_5
44                 static readonly ChannelProtectionRequirements default_channel_protection_requirements;
45 #endif
46                 static readonly BindingContext dummy_context;
47
48                 static SecureConversationSecurityTokenParameters ()
49                 {
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;
57                         r.MakeReadOnly ();
58                         default_channel_protection_requirements = r;
59 #endif
60
61                         dummy_context = new BindingContext (
62                                 new CustomBinding (),
63                                 new BindingParameterCollection ());
64                 }
65
66                 SecurityBindingElement element;
67 #if !MOBILE && !XAMMAC_4_5
68                 ChannelProtectionRequirements requirements;
69 #endif
70                 bool cancellable;
71
72                 public SecureConversationSecurityTokenParameters ()
73                         : this ((SecurityBindingElement) null)
74                 {
75                 }
76
77                 public SecureConversationSecurityTokenParameters (
78                         SecurityBindingElement bootstrapSecurityBindingElement)
79                         : this (bootstrapSecurityBindingElement, true)
80                 {
81                 }
82
83                 public SecureConversationSecurityTokenParameters (
84                         SecurityBindingElement bootstrapSecurityBindingElement,
85                         bool requireCancellation)
86                         : this (bootstrapSecurityBindingElement, requireCancellation, null)
87                 {
88                 }
89
90 #if !MOBILE && !XAMMAC_4_5
91                 public SecureConversationSecurityTokenParameters (
92                         SecurityBindingElement bootstrapSecurityBindingElement,
93                         bool requireCancellation,
94                         ChannelProtectionRequirements bootstrapProtectionRequirements)
95                 {
96                         this.element = bootstrapSecurityBindingElement;
97                         this.cancellable = requireCancellation;
98                         if (bootstrapProtectionRequirements == null)
99                                 this.requirements = new ChannelProtectionRequirements (default_channel_protection_requirements);
100                         else
101                                 this.requirements = new ChannelProtectionRequirements (bootstrapProtectionRequirements);
102                 }
103 #else
104                 internal SecureConversationSecurityTokenParameters (
105                         SecurityBindingElement element,
106                         bool requireCancellation,
107                         object dummy)
108                 {
109                         this.element = element;
110                         this.cancellable = requireCancellation;
111                 }
112 #endif
113
114                 protected SecureConversationSecurityTokenParameters (SecureConversationSecurityTokenParameters source)
115                         : base (source)
116                 {
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);
121 #endif
122                 }
123
124                 public bool RequireCancellation {
125                         get { return cancellable; }
126                         set { cancellable = value; }
127                 }
128
129                 public SecurityBindingElement BootstrapSecurityBindingElement {
130                         get { return element; }
131                         set { element = value; }
132                 }
133
134 #if !MOBILE && !XAMMAC_4_5
135                 public ChannelProtectionRequirements BootstrapProtectionRequirements {
136                         get { return requirements; }
137                 }
138 #endif
139
140                 // SecurityTokenParameters
141
142                 protected override bool HasAsymmetricKey {
143                         get { return false; }
144                 }
145
146                 protected override bool SupportsClientAuthentication {
147                         get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsClientAuthentication; }
148                 }
149
150                 protected override bool SupportsClientWindowsIdentity {
151                         get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsClientWindowsIdentity; }
152                 }
153
154                 protected override bool SupportsServerAuthentication {
155                         get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsServerAuthentication; }
156                 }
157
158                 protected override SecurityTokenParameters CloneCore ()
159                 {
160                         return new SecureConversationSecurityTokenParameters (this);
161                 }
162
163 #if !MOBILE && !XAMMAC_4_5
164                 [MonoTODO]
165                 protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause (
166                         SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
167                 {
168                         throw new NotImplementedException ();
169                 }
170                 [MonoTODO]
171                 protected internal override void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
172                 {
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;
181                 }
182 #endif
183
184                 public override string ToString ()
185                 {
186                         return base.ToString ();
187                 }
188         }
189 }