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