1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
//
// IssuedSecurityTokenParameters.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections.ObjectModel;
using System.Xml;
using System.Xml.XPath;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.ServiceModel.Channels;
using System.ServiceModel.Security;
using ReqType = System.ServiceModel.Security.Tokens.ServiceModelSecurityTokenRequirement;
namespace System.ServiceModel.Security.Tokens
{
public class IssuedSecurityTokenParameters : SecurityTokenParameters
{
public IssuedSecurityTokenParameters ()
{
}
public IssuedSecurityTokenParameters (string tokenType)
: this (tokenType, null)
{
}
public IssuedSecurityTokenParameters (string tokenType, EndpointAddress issuerAddress)
: this (tokenType, issuerAddress, null)
{
}
public IssuedSecurityTokenParameters (string tokenType,
EndpointAddress issuerAddress, Binding issuerBinding)
{
token_type = tokenType;
issuer_address = issuerAddress;
binding = issuerBinding;
}
protected IssuedSecurityTokenParameters (IssuedSecurityTokenParameters other)
: base (other)
{
binding = other.binding;
issuer_address = other.issuer_address;
issuer_meta_address = other.issuer_meta_address;
key_size = other.key_size;
key_type = other.key_type;
token_type = other.token_type;
reqs = new Collection<ClaimTypeRequirement> (other.reqs);
additional_reqs = new Collection<XmlElement> (other.additional_reqs);
}
Binding binding;
EndpointAddress issuer_address, issuer_meta_address;
int key_size;
SecurityKeyType key_type;
string token_type;
Collection<ClaimTypeRequirement> reqs =
new Collection<ClaimTypeRequirement> ();
Collection<XmlElement> additional_reqs =
new Collection<XmlElement> ();
public override string ToString ()
{
return base.ToString ();
}
public Collection<XmlElement> AdditionalRequestParameters {
get { return additional_reqs; }
}
public Collection<ClaimTypeRequirement> ClaimTypeRequirements {
get { return reqs; }
}
protected override bool HasAsymmetricKey {
get { return false; }
}
public EndpointAddress IssuerAddress {
get { return issuer_address; }
set { issuer_address = value; }
}
public Binding IssuerBinding {
get { return binding; }
set { binding = value; }
}
public EndpointAddress IssuerMetadataAddress {
get { return issuer_meta_address; }
set { issuer_meta_address = value; }
}
public int KeySize {
get { return key_size; }
set { key_size = value; }
}
public SecurityKeyType KeyType {
get { return key_type; }
set { key_type = value; }
}
public string TokenType {
get { return token_type; }
set { token_type = value; }
}
protected override bool SupportsClientAuthentication {
get { return true; }
}
protected override bool SupportsClientWindowsIdentity {
get { return false; }
}
protected override bool SupportsServerAuthentication {
get { return true; }
}
protected override SecurityTokenParameters CloneCore ()
{
return new IssuedSecurityTokenParameters (this);
}
[MonoTODO]
protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause (
SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
{
throw new NotImplementedException ();
}
public Collection<XmlElement> CreateRequestParameters (
MessageSecurityVersion messageSecurityVersion,
SecurityTokenSerializer securityTokenSerializer)
{
XmlDocument doc = new XmlDocument ();
Collection<XmlElement> ret = new Collection<XmlElement> ();
// KeyType
string keyTypeUri =
KeyType == SecurityKeyType.SymmetricKey ?
Constants.WstSymmetricKeyTypeUri :
Constants.WstAsymmetricKeyTypeUri;
XmlElement kt = doc.CreateElement ("t", "KeyType", Constants.WstNamespace);
kt.AppendChild (doc.CreateTextNode (keyTypeUri));
ret.Add (kt);
// ClaimTypes
XmlElement cts = doc.CreateElement ("t", "Claims", Constants.WstNamespace);
foreach (ClaimTypeRequirement req in ClaimTypeRequirements) {
XmlElement el = doc.CreateElement ("wsid", "ClaimType", Constants.WsidNamespace);
el.SetAttribute ("Uri", req.ClaimType);
if (req.IsOptional)
el.SetAttribute ("Optional", "true");
cts.AppendChild (el);
}
ret.Add (cts);
// Additional parameters
foreach (XmlElement el in AdditionalRequestParameters)
ret.Add (el);
return ret;
}
protected internal override void InitializeSecurityTokenRequirement (SecurityTokenRequirement requirement)
{
if (requirement == null)
throw new ArgumentNullException ("requirement");
requirement.TokenType = TokenType;
requirement.Properties [ReqType.IssuedSecurityTokenParametersProperty] = this.Clone ();
requirement.Properties [ReqType.IssuerAddressProperty] = IssuerAddress;
requirement.Properties [ReqType.IssuerBindingProperty] = IssuerBinding;
requirement.RequireCryptographicToken = true;
requirement.KeyType = KeyType;
}
}
}
|