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
|
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
namespace System.ServiceModel.Configuration
{
using System;
using System.Configuration;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.Xml;
public sealed partial class IssuedTokenServiceElement : ConfigurationElement
{
public IssuedTokenServiceElement()
{
}
[ConfigurationProperty(ConfigurationStrings.AllowedAudienceUris)]
public AllowedAudienceUriElementCollection AllowedAudienceUris
{
get { return (AllowedAudienceUriElementCollection)base[ConfigurationStrings.AllowedAudienceUris]; }
}
[ConfigurationProperty(ConfigurationStrings.AudienceUriMode, DefaultValue = IssuedTokenServiceCredential.DefaultAudienceUriMode)]
[ServiceModelEnumValidator(typeof(AudienceUriModeValidationHelper))]
public AudienceUriMode AudienceUriMode
{
get { return (AudienceUriMode)base[ConfigurationStrings.AudienceUriMode]; }
set { base[ConfigurationStrings.AudienceUriMode] = value; }
}
[ConfigurationProperty(ConfigurationStrings.CustomCertificateValidatorType, DefaultValue = "")]
[StringValidator(MinLength = 0)]
public string CustomCertificateValidatorType
{
get { return (string)base[ConfigurationStrings.CustomCertificateValidatorType]; }
set
{
if (String.IsNullOrEmpty(value))
{
value = String.Empty;
}
base[ConfigurationStrings.CustomCertificateValidatorType] = value;
}
}
[ConfigurationProperty(ConfigurationStrings.CertificateValidationMode, DefaultValue = IssuedTokenServiceCredential.DefaultCertificateValidationMode)]
[ServiceModelEnumValidator(typeof(X509CertificateValidationModeHelper))]
public X509CertificateValidationMode CertificateValidationMode
{
get { return (X509CertificateValidationMode)base[ConfigurationStrings.CertificateValidationMode]; }
set { base[ConfigurationStrings.CertificateValidationMode] = value; }
}
[ConfigurationProperty(ConfigurationStrings.RevocationMode, DefaultValue = IssuedTokenServiceCredential.DefaultRevocationMode)]
[StandardRuntimeEnumValidator(typeof(X509RevocationMode))]
public X509RevocationMode RevocationMode
{
get { return (X509RevocationMode)base[ConfigurationStrings.RevocationMode]; }
set { base[ConfigurationStrings.RevocationMode] = value; }
}
[ConfigurationProperty(ConfigurationStrings.TrustedStoreLocation, DefaultValue = IssuedTokenServiceCredential.DefaultTrustedStoreLocation)]
[StandardRuntimeEnumValidator(typeof(StoreLocation))]
public StoreLocation TrustedStoreLocation
{
get { return (StoreLocation)base[ConfigurationStrings.TrustedStoreLocation]; }
set { base[ConfigurationStrings.TrustedStoreLocation] = value; }
}
[ConfigurationProperty(ConfigurationStrings.SamlSerializerType, DefaultValue = "")]
[StringValidator(MinLength = 0)]
public string SamlSerializerType
{
get { return (string)base[ConfigurationStrings.SamlSerializerType]; }
set
{
if (String.IsNullOrEmpty(value))
{
value = String.Empty;
}
base[ConfigurationStrings.SamlSerializerType] = value;
}
}
[ConfigurationProperty(ConfigurationStrings.KnownCertificates)]
public X509CertificateTrustedIssuerElementCollection KnownCertificates
{
get { return (X509CertificateTrustedIssuerElementCollection)base[ConfigurationStrings.KnownCertificates]; }
}
[ConfigurationProperty(ConfigurationStrings.AllowUntrustedRsaIssuers, DefaultValue = IssuedTokenServiceCredential.DefaultAllowUntrustedRsaIssuers)]
public bool AllowUntrustedRsaIssuers
{
get { return (bool)base[ConfigurationStrings.AllowUntrustedRsaIssuers]; }
set { base[ConfigurationStrings.AllowUntrustedRsaIssuers] = value; }
}
public void Copy(IssuedTokenServiceElement from)
{
if (this.IsReadOnly())
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigReadOnly)));
}
if (null == from)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("from");
}
this.SamlSerializerType = from.SamlSerializerType;
#pragma warning suppress 56506 // [....]; ElementInformation is never null.
PropertyInformationCollection propertyInfo = from.ElementInformation.Properties;
if (propertyInfo[ConfigurationStrings.KnownCertificates].ValueOrigin != PropertyValueOrigin.Default)
{
this.KnownCertificates.Clear();
foreach (X509CertificateTrustedIssuerElement src in from.KnownCertificates)
{
X509CertificateTrustedIssuerElement copy = new X509CertificateTrustedIssuerElement();
copy.Copy(src);
this.KnownCertificates.Add(copy);
}
}
if (propertyInfo[ConfigurationStrings.AllowedAudienceUris].ValueOrigin != PropertyValueOrigin.Default)
{
this.AllowedAudienceUris.Clear();
foreach (AllowedAudienceUriElement src in from.AllowedAudienceUris)
{
AllowedAudienceUriElement copy = new AllowedAudienceUriElement();
copy.AllowedAudienceUri = src.AllowedAudienceUri;
this.AllowedAudienceUris.Add(copy);
}
}
this.AllowUntrustedRsaIssuers = from.AllowUntrustedRsaIssuers;
this.CertificateValidationMode = from.CertificateValidationMode;
this.AudienceUriMode = from.AudienceUriMode;
this.CustomCertificateValidatorType = from.CustomCertificateValidatorType;
this.RevocationMode = from.RevocationMode;
this.TrustedStoreLocation = from.TrustedStoreLocation;
}
internal void ApplyConfiguration(IssuedTokenServiceCredential issuedToken)
{
if (issuedToken == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("issuedToken");
}
issuedToken.CertificateValidationMode = this.CertificateValidationMode;
issuedToken.RevocationMode = this.RevocationMode;
issuedToken.TrustedStoreLocation = this.TrustedStoreLocation;
issuedToken.AudienceUriMode = this.AudienceUriMode;
if (!string.IsNullOrEmpty(this.CustomCertificateValidatorType))
{
Type type = System.Type.GetType(this.CustomCertificateValidatorType, true);
if (!typeof(X509CertificateValidator).IsAssignableFrom(type))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
SR.GetString(SR.ConfigInvalidCertificateValidatorType, this.CustomCertificateValidatorType, typeof(X509CertificateValidator).ToString())));
}
issuedToken.CustomCertificateValidator = (X509CertificateValidator)Activator.CreateInstance(type);
}
if (!string.IsNullOrEmpty(this.SamlSerializerType))
{
Type type = System.Type.GetType(this.SamlSerializerType, true);
if (!typeof(SamlSerializer).IsAssignableFrom(type))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(
SR.GetString(SR.ConfigInvalidSamlSerializerType, this.SamlSerializerType, typeof(SamlSerializer).ToString())));
}
issuedToken.SamlSerializer = (SamlSerializer)Activator.CreateInstance(type);
}
PropertyInformationCollection propertyInfo = this.ElementInformation.Properties;
if (propertyInfo[ConfigurationStrings.KnownCertificates].ValueOrigin != PropertyValueOrigin.Default)
{
foreach (X509CertificateTrustedIssuerElement src in this.KnownCertificates)
{
issuedToken.KnownCertificates.Add(SecurityUtils.GetCertificateFromStore(src.StoreName, src.StoreLocation, src.X509FindType, src.FindValue, null));
}
}
if (propertyInfo[ConfigurationStrings.AllowedAudienceUris].ValueOrigin != PropertyValueOrigin.Default)
{
foreach (AllowedAudienceUriElement src in this.AllowedAudienceUris)
{
issuedToken.AllowedAudienceUris.Add(src.AllowedAudienceUri);
}
}
issuedToken.AllowUntrustedRsaIssuers = this.AllowUntrustedRsaIssuers;
}
}
}
|