Merge pull request #3240 from alexanderkyte/aot_compiler_leaks
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel / MessageSecurityVersion.cs
1 //
2 // MessageSecurityVersion.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 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.Collections.Generic;
29 using System.Collections.ObjectModel;
30 #if !MOBILE && !XAMMAC_4_5
31 using System.IdentityModel.Selectors;
32 using System.IdentityModel.Tokens;
33 #endif
34 using System.ServiceModel.Description;
35 using System.ServiceModel.Channels;
36 using System.ServiceModel.Security;
37 using System.ServiceModel.Security.Tokens;
38
39 namespace System.ServiceModel
40 {
41         public abstract class MessageSecurityVersion
42         {
43 #if !MOBILE && !XAMMAC_4_5
44                 // Types
45                 class MessageSecurityTokenVersion : SecurityTokenVersion
46                 {
47                         static string [] specs10_profile_source, specs11_source, specs11_profile_source;
48                         static readonly MessageSecurityTokenVersion wss10basic, wss11, wss11basic;
49
50
51                         static MessageSecurityTokenVersion ()
52                         {
53                                 specs10_profile_source = new string [] {
54                                         Constants.WssNamespace,
55                                         Constants.WstNamespace,
56                                         Constants.WsscNamespace,
57                                         Constants.WSBasicSecurityProfileCore1,
58                                         };
59                                 specs11_source = new string [] {
60                                         Constants.Wss11Namespace,
61                                         Constants.WstNamespace,
62                                         Constants.WsscNamespace,
63                                         };
64                                 specs11_profile_source = new string [] {
65                                         Constants.Wss11Namespace,
66                                         Constants.WstNamespace,
67                                         Constants.WsscNamespace,
68                                         Constants.WSBasicSecurityProfileCore1,
69                                         };
70
71                                 wss10basic = new MessageSecurityTokenVersion (false, true);
72                                 wss11basic = new MessageSecurityTokenVersion (true, true);
73                                 wss11 = new MessageSecurityTokenVersion (true, false);
74                         }
75
76                         public static MessageSecurityTokenVersion GetVersion (bool isWss11, bool basicProfile)
77                         {
78                                 if (isWss11)
79                                         return basicProfile ? wss11basic : wss11;
80                                 else
81                                         return wss10basic;
82                         }
83
84                         ReadOnlyCollection<string> specs;
85
86                         MessageSecurityTokenVersion (bool wss11, bool basicProfile)
87                         {
88                                 string [] src;
89                                 if (wss11)
90                                         src = basicProfile ? specs11_profile_source : specs11_source;
91                                 else
92                                         src = basicProfile ? specs10_profile_source : null;
93                                 specs = new ReadOnlyCollection<string> (src);
94                         }
95
96                         public override ReadOnlyCollection<string> GetSecuritySpecifications ()
97                         {
98                                 return specs;
99                         }
100                 }
101
102                 class MessageSecurityVersionImpl : MessageSecurityVersion
103                 {
104                         bool wss11, basic_profile, use2007;
105
106                         public MessageSecurityVersionImpl (bool wss11, bool basicProfile, bool use2007)
107                         {
108                                 this.wss11 = wss11;
109                                 this.basic_profile = basicProfile;
110                                 this.use2007 = use2007;
111                                 if (use2007) {
112                                         SecureConversationVersion = SecureConversationVersion.Default;
113                                         TrustVersion = TrustVersion.Default;
114                                 } else {
115                                         SecureConversationVersion = SecureConversationVersion.WSSecureConversationFeb2005;
116                                         TrustVersion = TrustVersion.WSTrustFeb2005;
117                                 }
118                                 this.SecurityVersion = wss11 ? SecurityVersion.WSSecurity11 : SecurityVersion.WSSecurity10;
119                         }
120
121                         public override BasicSecurityProfileVersion BasicSecurityProfileVersion {
122                                 get { return basic_profile ? BasicSecurityProfileVersion.BasicSecurityProfile10 : null; }
123                         }
124
125                         public override SecurityTokenVersion SecurityTokenVersion {
126                                 get { return MessageSecurityTokenVersion.GetVersion (wss11, basic_profile); }
127                         }
128
129                         public override SecurityPolicyVersion SecurityPolicyVersion {
130                                 get { return use2007 ? SecurityPolicyVersion.WSSecurityPolicy12 : SecurityPolicyVersion.WSSecurityPolicy11; }
131                         }
132                 }
133 #endif
134
135                 // Static members
136
137                 static MessageSecurityVersion wss10_basic, wss11, wss11_basic, wss10_2007_basic, wss11_2007_basic, wss11_2007;
138
139                 static MessageSecurityVersion ()
140                 {
141 #if !MOBILE && !XAMMAC_4_5
142                         wss10_basic = new MessageSecurityVersionImpl (false, true, false);
143                         wss11 = new MessageSecurityVersionImpl (true, false, false);
144                         wss11_basic = new MessageSecurityVersionImpl (true, true, false);
145                         wss10_2007_basic = new MessageSecurityVersionImpl (false, true, true);
146                         wss11_2007_basic = new MessageSecurityVersionImpl (true, true, true);
147                         wss11_2007 = new MessageSecurityVersionImpl (true, false, true);
148 #else
149                         throw new NotImplementedException ();
150 #endif
151                 }
152
153                 public static MessageSecurityVersion Default {
154                         get { return wss11; }
155                 }
156
157                 // guys, have you ever seen such silly member names??
158
159                 public static MessageSecurityVersion WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 {
160                         get { return wss10_basic; }
161                 }
162
163                 public static MessageSecurityVersion WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11 {
164                         get { return wss11; }
165                 }
166
167                 public static MessageSecurityVersion WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 {
168                         get { return wss11_basic; }
169                 }
170
171                 public static MessageSecurityVersion WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10 {
172                         get { return wss10_2007_basic; }
173                 }
174
175                 public static MessageSecurityVersion WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10 {
176                         get { return wss11_2007_basic; }
177                 }
178
179                 public static MessageSecurityVersion WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12 {
180                         get { return wss11_2007; }
181                 }
182
183                 // Instance members
184
185                 MessageSecurityVersion ()
186                 {
187                 }
188
189                 public abstract BasicSecurityProfileVersion BasicSecurityProfileVersion { get; }
190
191 #if !MOBILE && !XAMMAC_4_5
192                 public abstract SecurityTokenVersion SecurityTokenVersion { get; }
193 #endif
194
195                 public SecurityVersion SecurityVersion { get; internal set; }
196
197                 public SecureConversationVersion SecureConversationVersion { get; internal set; }
198
199                 public abstract SecurityPolicyVersion SecurityPolicyVersion { get; }
200
201                 public TrustVersion TrustVersion { get; internal set; }
202
203         }
204 }