2 // IssuedSecurityTokenParameters.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.ObjectModel;
30 using System.Xml.XPath;
31 using System.IdentityModel.Selectors;
32 using System.IdentityModel.Tokens;
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Security;
36 using ReqType = System.ServiceModel.Security.Tokens.ServiceModelSecurityTokenRequirement;
38 namespace System.ServiceModel.Security.Tokens
40 public class IssuedSecurityTokenParameters : SecurityTokenParameters
42 public IssuedSecurityTokenParameters ()
46 public IssuedSecurityTokenParameters (string tokenType)
47 : this (tokenType, null)
51 public IssuedSecurityTokenParameters (string tokenType, EndpointAddress issuerAddress)
52 : this (tokenType, issuerAddress, null)
56 public IssuedSecurityTokenParameters (string tokenType,
57 EndpointAddress issuerAddress, Binding issuerBinding)
59 token_type = tokenType;
60 issuer_address = issuerAddress;
61 binding = issuerBinding;
64 protected IssuedSecurityTokenParameters (IssuedSecurityTokenParameters source)
67 binding = source.binding;
68 issuer_address = source.issuer_address;
69 issuer_meta_address = source.issuer_meta_address;
70 key_size = source.key_size;
71 key_type = source.key_type;
72 token_type = source.token_type;
73 reqs = new Collection<ClaimTypeRequirement> (source.reqs);
74 additional_reqs = new Collection<XmlElement> (source.additional_reqs);
78 EndpointAddress issuer_address, issuer_meta_address;
80 SecurityKeyType key_type;
82 Collection<ClaimTypeRequirement> reqs =
83 new Collection<ClaimTypeRequirement> ();
84 Collection<XmlElement> additional_reqs =
85 new Collection<XmlElement> ();
88 public override string ToString ()
90 return base.ToString ();
93 public Collection<XmlElement> AdditionalRequestParameters {
94 get { return additional_reqs; }
97 public Collection<ClaimTypeRequirement> ClaimTypeRequirements {
101 protected override bool HasAsymmetricKey {
102 get { return false; }
105 public EndpointAddress IssuerAddress {
106 get { return issuer_address; }
107 set { issuer_address = value; }
110 public Binding IssuerBinding {
111 get { return binding; }
112 set { binding = value; }
115 public EndpointAddress IssuerMetadataAddress {
116 get { return issuer_meta_address; }
117 set { issuer_meta_address = value; }
121 get { return key_size; }
122 set { key_size = value; }
125 public SecurityKeyType KeyType {
126 get { return key_type; }
127 set { key_type = value; }
130 public string TokenType {
131 get { return token_type; }
132 set { token_type = value; }
135 protected override bool SupportsClientAuthentication {
139 protected override bool SupportsClientWindowsIdentity {
140 get { return false; }
143 protected override bool SupportsServerAuthentication {
147 protected override SecurityTokenParameters CloneCore ()
149 return new IssuedSecurityTokenParameters (this);
153 protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause (
154 SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
156 throw new NotImplementedException ();
159 public Collection<XmlElement> CreateRequestParameters (
160 MessageSecurityVersion messageSecurityVersion,
161 SecurityTokenSerializer securityTokenSerializer)
163 XmlDocument doc = new XmlDocument ();
164 Collection<XmlElement> ret = new Collection<XmlElement> ();
167 KeyType == SecurityKeyType.SymmetricKey ?
168 Constants.WstSymmetricKeyTypeUri :
169 Constants.WstAsymmetricKeyTypeUri;
170 XmlElement kt = doc.CreateElement ("t", "KeyType", Constants.WstNamespace);
171 kt.AppendChild (doc.CreateTextNode (keyTypeUri));
175 XmlElement cts = doc.CreateElement ("t", "Claims", Constants.WstNamespace);
176 foreach (ClaimTypeRequirement req in ClaimTypeRequirements) {
177 XmlElement el = doc.CreateElement ("wsid", "ClaimType", Constants.WsidNamespace);
178 el.SetAttribute ("Uri", req.ClaimType);
180 el.SetAttribute ("Optional", "true");
181 cts.AppendChild (el);
185 // Additional parameters
186 foreach (XmlElement el in AdditionalRequestParameters)
191 protected override void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
193 if (requirement == null)
194 throw new ArgumentNullException ("requirement");
195 requirement.TokenType = TokenType;
196 requirement.Properties [ReqType.IssuedSecurityTokenParametersProperty] = this.Clone ();
197 requirement.Properties [ReqType.IssuerAddressProperty] = IssuerAddress;
198 requirement.Properties [ReqType.IssuerBindingProperty] = IssuerBinding;
199 requirement.RequireCryptographicToken = true;
200 requirement.KeyType = KeyType;