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 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;
37 namespace System.ServiceModel
39 public abstract class MessageSecurityVersion
42 class MessageSecurityTokenVersion : SecurityTokenVersion
44 static string [] specs10_profile_source, specs11_source, specs11_profile_source;
45 static readonly MessageSecurityTokenVersion wss10basic, wss11, wss11basic;
48 static MessageSecurityTokenVersion ()
50 specs10_profile_source = new string [] {
51 Constants.WssNamespace,
52 Constants.WstNamespace,
53 Constants.WsscNamespace,
54 Constants.WSBasicSecurityProfileCore1,
56 specs11_source = new string [] {
57 Constants.Wss11Namespace,
58 Constants.WstNamespace,
59 Constants.WsscNamespace,
61 specs11_profile_source = new string [] {
62 Constants.Wss11Namespace,
63 Constants.WstNamespace,
64 Constants.WsscNamespace,
65 Constants.WSBasicSecurityProfileCore1,
68 wss10basic = new MessageSecurityTokenVersion (false, true);
69 wss11basic = new MessageSecurityTokenVersion (true, true);
70 wss11 = new MessageSecurityTokenVersion (true, false);
73 public static MessageSecurityTokenVersion GetVersion (bool isWss11, bool basicProfile)
76 return basicProfile ? wss11basic : wss11;
81 ReadOnlyCollection<string> specs;
83 MessageSecurityTokenVersion (bool wss11, bool basicProfile)
87 src = basicProfile ? specs11_profile_source : specs11_source;
89 src = basicProfile ? specs10_profile_source : null;
90 specs = new ReadOnlyCollection<string> (src);
93 public override ReadOnlyCollection<string> GetSecuritySpecifications ()
99 class MessageSecurityVersionImpl : MessageSecurityVersion
101 bool wss11, basic_profile, use2007;
103 public MessageSecurityVersionImpl (bool wss11, bool basicProfile, bool use2007)
106 this.basic_profile = basicProfile;
107 this.use2007 = use2007;
109 SecureConversationVersion = SecureConversationVersion.Default;
110 TrustVersion = TrustVersion.Default;
112 SecureConversationVersion = SecureConversationVersion.WSSecureConversationFeb2005;
113 TrustVersion = TrustVersion.WSTrustFeb2005;
117 public override BasicSecurityProfileVersion BasicSecurityProfileVersion {
118 get { return basic_profile ? BasicSecurityProfileVersion.BasicSecurityProfile10 : null; }
121 public override SecurityTokenVersion SecurityTokenVersion {
122 get { return MessageSecurityTokenVersion.GetVersion (wss11, basic_profile); }
125 public override SecurityVersion SecurityVersion {
126 get { return wss11 ? SecurityVersion.WSSecurity11 : SecurityVersion.WSSecurity10; }
129 public override SecurityPolicyVersion SecurityPolicyVersion {
130 get { return use2007 ? SecurityPolicyVersion.WSSecurityPolicy12 : SecurityPolicyVersion.WSSecurityPolicy11; }
136 static MessageSecurityVersion wss10_basic, wss11, wss11_basic, wss10_2007_basic, wss11_2007_basic, wss11_2007;
138 static MessageSecurityVersion ()
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);
148 public static MessageSecurityVersion Default {
149 get { return wss11; }
152 // guys, have you ever seen such silly member names??
154 public static MessageSecurityVersion WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 {
155 get { return wss10_basic; }
158 public static MessageSecurityVersion WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11 {
159 get { return wss11; }
162 public static MessageSecurityVersion WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 {
163 get { return wss11_basic; }
166 public static MessageSecurityVersion WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10 {
167 get { return wss10_2007_basic; }
170 public static MessageSecurityVersion WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10 {
171 get { return wss11_2007_basic; }
174 public static MessageSecurityVersion WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12 {
175 get { return wss11_2007; }
180 MessageSecurityVersion ()
184 public abstract BasicSecurityProfileVersion BasicSecurityProfileVersion { get; }
186 public abstract SecurityTokenVersion SecurityTokenVersion { get; }
188 public abstract SecurityVersion SecurityVersion { get; }
190 public SecureConversationVersion SecureConversationVersion { get; internal set; }
192 public abstract SecurityPolicyVersion SecurityPolicyVersion { get; }
194 public TrustVersion TrustVersion { get; internal set; }