2 // MessageSecurityVersion.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2006 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
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;
34 using System.ServiceModel.Description;
35 using System.ServiceModel.Channels;
36 using System.ServiceModel.Security;
37 using System.ServiceModel.Security.Tokens;
39 namespace System.ServiceModel
41 public abstract class MessageSecurityVersion
43 #if !MOBILE && !XAMMAC_4_5
45 class MessageSecurityTokenVersion : SecurityTokenVersion
47 static string [] specs10_profile_source, specs11_source, specs11_profile_source;
48 static readonly MessageSecurityTokenVersion wss10basic, wss11, wss11basic;
51 static MessageSecurityTokenVersion ()
53 specs10_profile_source = new string [] {
54 Constants.WssNamespace,
55 Constants.WstNamespace,
56 Constants.WsscNamespace,
57 Constants.WSBasicSecurityProfileCore1,
59 specs11_source = new string [] {
60 Constants.Wss11Namespace,
61 Constants.WstNamespace,
62 Constants.WsscNamespace,
64 specs11_profile_source = new string [] {
65 Constants.Wss11Namespace,
66 Constants.WstNamespace,
67 Constants.WsscNamespace,
68 Constants.WSBasicSecurityProfileCore1,
71 wss10basic = new MessageSecurityTokenVersion (false, true);
72 wss11basic = new MessageSecurityTokenVersion (true, true);
73 wss11 = new MessageSecurityTokenVersion (true, false);
76 public static MessageSecurityTokenVersion GetVersion (bool isWss11, bool basicProfile)
79 return basicProfile ? wss11basic : wss11;
84 ReadOnlyCollection<string> specs;
86 MessageSecurityTokenVersion (bool wss11, bool basicProfile)
90 src = basicProfile ? specs11_profile_source : specs11_source;
92 src = basicProfile ? specs10_profile_source : null;
93 specs = new ReadOnlyCollection<string> (src);
96 public override ReadOnlyCollection<string> GetSecuritySpecifications ()
102 class MessageSecurityVersionImpl : MessageSecurityVersion
104 bool wss11, basic_profile, use2007;
106 public MessageSecurityVersionImpl (bool wss11, bool basicProfile, bool use2007)
109 this.basic_profile = basicProfile;
110 this.use2007 = use2007;
112 SecureConversationVersion = SecureConversationVersion.Default;
113 TrustVersion = TrustVersion.Default;
115 SecureConversationVersion = SecureConversationVersion.WSSecureConversationFeb2005;
116 TrustVersion = TrustVersion.WSTrustFeb2005;
118 this.SecurityVersion = wss11 ? SecurityVersion.WSSecurity11 : SecurityVersion.WSSecurity10;
121 public override BasicSecurityProfileVersion BasicSecurityProfileVersion {
122 get { return basic_profile ? BasicSecurityProfileVersion.BasicSecurityProfile10 : null; }
125 public override SecurityTokenVersion SecurityTokenVersion {
126 get { return MessageSecurityTokenVersion.GetVersion (wss11, basic_profile); }
129 public override SecurityPolicyVersion SecurityPolicyVersion {
130 get { return use2007 ? SecurityPolicyVersion.WSSecurityPolicy12 : SecurityPolicyVersion.WSSecurityPolicy11; }
137 static MessageSecurityVersion wss10_basic, wss11, wss11_basic, wss10_2007_basic, wss11_2007_basic, wss11_2007;
139 static MessageSecurityVersion ()
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);
149 throw new NotImplementedException ();
153 public static MessageSecurityVersion Default {
154 get { return wss11; }
157 // guys, have you ever seen such silly member names??
159 public static MessageSecurityVersion WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 {
160 get { return wss10_basic; }
163 public static MessageSecurityVersion WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11 {
164 get { return wss11; }
167 public static MessageSecurityVersion WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 {
168 get { return wss11_basic; }
171 public static MessageSecurityVersion WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10 {
172 get { return wss10_2007_basic; }
175 public static MessageSecurityVersion WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10 {
176 get { return wss11_2007_basic; }
179 public static MessageSecurityVersion WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12 {
180 get { return wss11_2007; }
185 MessageSecurityVersion ()
189 public abstract BasicSecurityProfileVersion BasicSecurityProfileVersion { get; }
191 #if !MOBILE && !XAMMAC_4_5
192 public abstract SecurityTokenVersion SecurityTokenVersion { get; }
195 public SecurityVersion SecurityVersion { get; internal set; }
197 public SecureConversationVersion SecureConversationVersion { get; internal set; }
199 public abstract SecurityPolicyVersion SecurityPolicyVersion { get; }
201 public TrustVersion TrustVersion { get; internal set; }