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> ();
87 public override string ToString ()
89 return base.ToString ();
92 public Collection<XmlElement> AdditionalRequestParameters {
93 get { return additional_reqs; }
96 public Collection<ClaimTypeRequirement> ClaimTypeRequirements {
100 protected override bool HasAsymmetricKey {
101 get { return false; }
104 public EndpointAddress IssuerAddress {
105 get { return issuer_address; }
106 set { issuer_address = value; }
109 public Binding IssuerBinding {
110 get { return binding; }
111 set { binding = value; }
114 public EndpointAddress IssuerMetadataAddress {
115 get { return issuer_meta_address; }
116 set { issuer_meta_address = value; }
120 get { return key_size; }
121 set { key_size = value; }
124 public SecurityKeyType KeyType {
125 get { return key_type; }
126 set { key_type = value; }
129 public string TokenType {
130 get { return token_type; }
131 set { token_type = value; }
134 protected override bool SupportsClientAuthentication {
138 protected override bool SupportsClientWindowsIdentity {
139 get { return false; }
142 protected override bool SupportsServerAuthentication {
146 protected override SecurityTokenParameters CloneCore ()
148 return new IssuedSecurityTokenParameters (this);
152 protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause (
153 SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
155 throw new NotImplementedException ();
158 public Collection<XmlElement> CreateRequestParameters (
159 MessageSecurityVersion messageSecurityVersion,
160 SecurityTokenSerializer securityTokenSerializer)
162 XmlDocument doc = new XmlDocument ();
163 Collection<XmlElement> ret = new Collection<XmlElement> ();
166 KeyType == SecurityKeyType.SymmetricKey ?
167 Constants.WstSymmetricKeyTypeUri :
168 Constants.WstAsymmetricKeyTypeUri;
169 XmlElement kt = doc.CreateElement ("t", "KeyType", Constants.WstNamespace);
170 kt.AppendChild (doc.CreateTextNode (keyTypeUri));
174 XmlElement cts = doc.CreateElement ("t", "Claims", Constants.WstNamespace);
175 foreach (ClaimTypeRequirement req in ClaimTypeRequirements) {
176 XmlElement el = doc.CreateElement ("wsid", "ClaimType", Constants.WsidNamespace);
177 el.SetAttribute ("Uri", req.ClaimType);
179 el.SetAttribute ("Optional", "true");
180 cts.AppendChild (el);
184 // Additional parameters
185 foreach (XmlElement el in AdditionalRequestParameters)
190 protected internal override void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
192 if (requirement == null)
193 throw new ArgumentNullException ("requirement");
194 requirement.TokenType = TokenType;
195 requirement.Properties [ReqType.IssuedSecurityTokenParametersProperty] = this.Clone ();
196 requirement.Properties [ReqType.IssuerAddressProperty] = IssuerAddress;
197 requirement.Properties [ReqType.IssuerBindingProperty] = IssuerBinding;
198 requirement.RequireCryptographicToken = true;
199 requirement.KeyType = KeyType;