[mini] bump AOT version - WrapperType changed
[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 using System.IdentityModel.Selectors;
29 using System.IdentityModel.Tokens;
30 using System.ServiceModel.Channels;
31 using System.ServiceModel.Security;
32
33 using ReqType = System.ServiceModel.Security.Tokens.ServiceModelSecurityTokenRequirement;
34
35 namespace System.ServiceModel.Security.Tokens
36 {
37         public class SecureConversationSecurityTokenParameters : SecurityTokenParameters
38         {
39                 static readonly ChannelProtectionRequirements default_channel_protection_requirements;
40                 static readonly BindingContext dummy_context;
41
42                 static SecureConversationSecurityTokenParameters ()
43                 {
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;
50                         r.MakeReadOnly ();
51                         default_channel_protection_requirements = r;
52
53                         dummy_context = new BindingContext (
54                                 new CustomBinding (),
55                                 new BindingParameterCollection ());
56                 }
57
58                 SecurityBindingElement element;
59                 ChannelProtectionRequirements requirements;
60                 bool cancellable;
61
62                 public SecureConversationSecurityTokenParameters ()
63                         : this ((SecurityBindingElement) null)
64                 {
65                 }
66
67                 public SecureConversationSecurityTokenParameters (
68                         SecurityBindingElement element)
69                         : this (element, true)
70                 {
71                 }
72
73                 public SecureConversationSecurityTokenParameters (
74                         SecurityBindingElement element,
75                         bool requireCancellation)
76                         : this (element, requireCancellation, null)
77                 {
78                 }
79
80                 public SecureConversationSecurityTokenParameters (
81                         SecurityBindingElement element,
82                         bool requireCancellation,
83                         ChannelProtectionRequirements requirements)
84                 {
85                         this.element = element;
86                         this.cancellable = requireCancellation;
87                         if (requirements == null)
88                                 this.requirements = new ChannelProtectionRequirements (default_channel_protection_requirements);
89                         else
90                                 this.requirements = new ChannelProtectionRequirements (requirements);
91                 }
92
93                 protected SecureConversationSecurityTokenParameters (SecureConversationSecurityTokenParameters source)
94                         : base (source)
95                 {
96                         this.element = (SecurityBindingElement) source.element.Clone ();
97                         this.cancellable = source.cancellable;
98                         this.requirements = new ChannelProtectionRequirements (default_channel_protection_requirements);
99                 }
100
101                 public bool RequireCancellation {
102                         get { return cancellable; }
103                         set { cancellable = value; }
104                 }
105
106                 public SecurityBindingElement BootstrapSecurityBindingElement {
107                         get { return element; }
108                         set { element = value; }
109                 }
110
111                 public ChannelProtectionRequirements BootstrapProtectionRequirements {
112                         get { return requirements; }
113                 }
114
115                 // SecurityTokenParameters
116
117                 protected override bool HasAsymmetricKey {
118                         get { return false; }
119                 }
120
121                 protected override bool SupportsClientAuthentication {
122                         get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsClientAuthentication; }
123                 }
124
125                 protected override bool SupportsClientWindowsIdentity {
126                         get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsClientWindowsIdentity; }
127                 }
128
129                 protected override bool SupportsServerAuthentication {
130                         get { return element.GetProperty<ISecurityCapabilities> (dummy_context).SupportsServerAuthentication; }
131                 }
132
133                 protected override SecurityTokenParameters CloneCore ()
134                 {
135                         return new SecureConversationSecurityTokenParameters (this);
136                 }
137
138                 [MonoTODO]
139                 protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause (
140                         SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
141                 {
142                         throw new NotImplementedException ();
143                 }
144
145                 [MonoTODO]
146                 protected internal override void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
147                 {
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;
156                 }
157
158                 public override string ToString ()
159                 {
160                         return base.ToString ();
161                 }
162         }
163 }