2008-11-01 Marek Habersack <mhabersack@novell.com>
[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;
102
103                         public MessageSecurityVersionImpl (bool wss11, bool basicProfile)
104                         {
105                                 this.wss11 = wss11;
106                                 this.basic_profile = basicProfile;
107                         }
108
109                         public override BasicSecurityProfileVersion BasicSecurityProfileVersion {
110                                 get { return basic_profile ? BasicSecurityProfileVersion.BasicSecurityProfile10 : null; }
111                         }
112
113                         public override SecurityTokenVersion SecurityTokenVersion {
114                                 get { return MessageSecurityTokenVersion.GetVersion (wss11, basic_profile); }
115                         }
116
117                         public override SecurityVersion SecurityVersion {
118                                 get { return wss11 ? SecurityVersion.WSSecurity11 : SecurityVersion.WSSecurity10; }
119                         }
120                 }
121
122                 // Static members
123
124                 static MessageSecurityVersion wss10_basic, wss11, wss11_basic;
125
126                 static MessageSecurityVersion ()
127                 {
128                         wss10_basic = new MessageSecurityVersionImpl (false, true);
129                         wss11 = new MessageSecurityVersionImpl (true, false);
130                         wss11_basic = new MessageSecurityVersionImpl (true, true);
131                 }
132
133                 public static MessageSecurityVersion Default {
134                         get { return wss11; }
135                 }
136
137                 // guys, have you ever seen such silly member names??
138
139                 public static MessageSecurityVersion WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 {
140                         get { return wss10_basic; }
141                 }
142
143                 public static MessageSecurityVersion WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11 {
144                         get { return wss11; }
145                 }
146
147                 public static MessageSecurityVersion WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 {
148                         get { return wss11_basic; }
149                 }
150
151                 // Instance members
152
153                 MessageSecurityVersion ()
154                 {
155                 }
156
157                 public abstract BasicSecurityProfileVersion BasicSecurityProfileVersion { get; }
158
159                 public abstract SecurityTokenVersion SecurityTokenVersion { get; }
160
161                 public abstract SecurityVersion SecurityVersion { get; }
162         }
163 }