| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Security.Cryptography.X509Certificates; |
| | | 6 | | using CoreWCF.IdentityModel.Configuration; |
| | | 7 | | using CoreWCF.IdentityModel.Selectors; |
| | | 8 | | using CoreWCF.Security; |
| | | 9 | | |
| | | 10 | | namespace CoreWCF.IdentityModel.Tokens |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Configuration common to all SecurityTokenHandlers. |
| | | 14 | | /// </summary> |
| | | 15 | | public class SecurityTokenHandlerConfiguration |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Gets a value indicating whether or not to detect replay tokens by default. |
| | | 19 | | /// </summary> |
| | | 20 | | public static readonly bool DefaultDetectReplayedTokens; // false |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Gets the default issuer name registry. |
| | | 24 | | /// </summary> |
| | 2 | 25 | | public static readonly IssuerNameRegistry DefaultIssuerNameRegistry = new ConfigurationBasedIssuerNameRegistry() |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Gets the default issuer token resolver. |
| | | 29 | | /// </summary> |
| | 2 | 30 | | public static readonly SecurityTokenResolver DefaultIssuerTokenResolver = CoreWCF.IdentityModel.Tokens.IssuerTok |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Gets the default maximum clock skew. |
| | | 34 | | /// </summary> |
| | 2 | 35 | | public static readonly TimeSpan DefaultMaxClockSkew = new TimeSpan(0, 5, 0); // 5 minutes |
| | | 36 | | |
| | | 37 | | /// <summary> |
| | | 38 | | /// Gets a value indicating whether or not to save bootstrap tokens by default. |
| | | 39 | | /// </summary> |
| | | 40 | | public static readonly bool DefaultSaveBootstrapContext; // false; |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Gets the default token replay cache expiration period. |
| | | 44 | | /// </summary> |
| | 2 | 45 | | public static readonly TimeSpan DefaultTokenReplayCacheExpirationPeriod = TimeSpan.MaxValue; |
| | | 46 | | |
| | | 47 | | // The below 3 defaults were moved from IdentityConfiguration class as we can not have service configuration in |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Gets the default X.509 certificate validation mode. |
| | | 51 | | /// </summary> |
| | 2 | 52 | | public static readonly X509CertificateValidationMode DefaultCertificateValidationMode = IdentityConfiguration.De |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Gets the default X.509 certificate revocation validation mode. |
| | | 56 | | /// </summary> |
| | 2 | 57 | | public static readonly X509RevocationMode DefaultRevocationMode = IdentityConfiguration.DefaultRevocationMode; |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// Gets the default X.509 certificate trusted store location. |
| | | 61 | | /// </summary> |
| | 2 | 62 | | public static readonly StoreLocation DefaultTrustedStoreLocation = IdentityConfiguration.DefaultTrustedStoreLoca |
| | 10 | 63 | | X509CertificateValidationMode certificateValidationMode = DefaultCertificateValidationMode; |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Gets the default X.509 certificate validator instance. |
| | | 67 | | /// </summary> |
| | 2 | 68 | | public static readonly X509CertificateValidator DefaultCertificateValidator = X509Util.CreateCertificateValidato |
| | 10 | 69 | | private AudienceRestriction _audienceRestriction = new AudienceRestriction(); |
| | 10 | 70 | | private X509CertificateValidator _certificateValidator = DefaultCertificateValidator; |
| | 10 | 71 | | private IssuerNameRegistry _issuerNameRegistry = DefaultIssuerNameRegistry; |
| | 10 | 72 | | private SecurityTokenResolver _issuerTokenResolver = DefaultIssuerTokenResolver; |
| | 10 | 73 | | private TimeSpan _maxClockSkew = DefaultMaxClockSkew; |
| | 10 | 74 | | private SecurityTokenResolver _serviceTokenResolver = EmptySecurityTokenResolver.Instance; |
| | 10 | 75 | | private TimeSpan _tokenReplayCacheExpirationPeriod = DefaultTokenReplayCacheExpirationPeriod; |
| | 10 | 76 | | private IdentityModelCaches _caches = new IdentityModelCaches(); |
| | | 77 | | |
| | | 78 | | /// <summary> |
| | | 79 | | /// Creates an instance of <see cref="SecurityTokenHandlerConfiguration"/> |
| | | 80 | | /// </summary> |
| | 10 | 81 | | public SecurityTokenHandlerConfiguration() |
| | | 82 | | { |
| | 10 | 83 | | } |
| | | 84 | | |
| | | 85 | | /// <summary> |
| | | 86 | | /// Gets or sets the AudienceRestriction. |
| | | 87 | | /// </summary> |
| | | 88 | | public AudienceRestriction AudienceRestriction |
| | | 89 | | { |
| | | 90 | | get |
| | | 91 | | { |
| | 138 | 92 | | return _audienceRestriction; |
| | | 93 | | } |
| | | 94 | | |
| | | 95 | | set |
| | | 96 | | { |
| | 0 | 97 | | _audienceRestriction = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof( |
| | 0 | 98 | | } |
| | | 99 | | } |
| | | 100 | | |
| | | 101 | | /// <summary> |
| | | 102 | | /// Gets or sets the certificate validator used by handlers to validate issuer certificates |
| | | 103 | | /// </summary> |
| | | 104 | | public X509CertificateValidator CertificateValidator |
| | | 105 | | { |
| | | 106 | | get |
| | | 107 | | { |
| | 30 | 108 | | return _certificateValidator; |
| | | 109 | | } |
| | | 110 | | |
| | | 111 | | set |
| | | 112 | | { |
| | 4 | 113 | | _certificateValidator = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof |
| | 4 | 114 | | } |
| | | 115 | | } |
| | | 116 | | |
| | 12 | 117 | | public X509RevocationMode RevocationMode { get; set; } = DefaultRevocationMode; |
| | | 118 | | |
| | | 119 | | /// <summary> |
| | | 120 | | /// Gets or sets the trusted store location used by handlers to validate issuer certificates |
| | | 121 | | /// </summary> |
| | 10 | 122 | | public StoreLocation TrustedStoreLocation { get; set; } = DefaultTrustedStoreLocation; |
| | | 123 | | |
| | | 124 | | /// <summary> |
| | | 125 | | /// Gets or sets the certificate validation mode used by handlers to validate issuer certificates |
| | | 126 | | /// </summary> |
| | | 127 | | public X509CertificateValidationMode CertificateValidationMode |
| | | 128 | | { |
| | 0 | 129 | | get { return certificateValidationMode; } |
| | 4 | 130 | | set { certificateValidationMode = value; } |
| | | 131 | | } |
| | | 132 | | |
| | | 133 | | /// <summary> |
| | | 134 | | /// Gets or sets a value indicating whether to detect replaying of tokens by handlers in this configuration. |
| | | 135 | | /// </summary> |
| | 58 | 136 | | public bool DetectReplayedTokens { get; set; } = DefaultDetectReplayedTokens; |
| | | 137 | | |
| | | 138 | | /// <summary> |
| | | 139 | | /// Gets or sets the IssuerNameRegistry. |
| | | 140 | | /// </summary> |
| | | 141 | | public IssuerNameRegistry IssuerNameRegistry |
| | | 142 | | { |
| | | 143 | | get |
| | | 144 | | { |
| | 32 | 145 | | return _issuerNameRegistry; |
| | | 146 | | } |
| | | 147 | | |
| | | 148 | | set |
| | | 149 | | { |
| | 4 | 150 | | _issuerNameRegistry = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(v |
| | 4 | 151 | | } |
| | | 152 | | } |
| | | 153 | | |
| | | 154 | | /// <summary> |
| | | 155 | | /// Gets or sets the IssuerTokenResolver. |
| | | 156 | | /// </summary> |
| | | 157 | | public SecurityTokenResolver IssuerTokenResolver |
| | | 158 | | { |
| | | 159 | | get |
| | | 160 | | { |
| | 50 | 161 | | return _issuerTokenResolver; |
| | | 162 | | } |
| | | 163 | | |
| | | 164 | | set |
| | | 165 | | { |
| | 4 | 166 | | _issuerTokenResolver = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof( |
| | 4 | 167 | | } |
| | | 168 | | } |
| | | 169 | | |
| | | 170 | | /// <summary> |
| | | 171 | | /// Gets or sets the maximum clock skew for handlers using this config. |
| | | 172 | | /// </summary> |
| | | 173 | | public TimeSpan MaxClockSkew |
| | | 174 | | { |
| | | 175 | | get |
| | | 176 | | { |
| | 48 | 177 | | return _maxClockSkew; |
| | | 178 | | } |
| | | 179 | | |
| | | 180 | | set |
| | | 181 | | { |
| | 2 | 182 | | if (value < TimeSpan.Zero) |
| | | 183 | | { |
| | 0 | 184 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.Format(SR.ID2070)); |
| | | 185 | | } |
| | | 186 | | |
| | 2 | 187 | | _maxClockSkew = value; |
| | 2 | 188 | | } |
| | | 189 | | } |
| | | 190 | | |
| | | 191 | | /// <summary> |
| | | 192 | | /// Gets or sets a value indicating whether BootstrapContext is saved in the ClaimsIdentity and Sessions after t |
| | | 193 | | /// </summary> |
| | 42 | 194 | | public bool SaveBootstrapContext { get; set; } = DefaultSaveBootstrapContext; |
| | | 195 | | |
| | | 196 | | /// <summary> |
| | | 197 | | /// Gets or sets the TokenResolver that resolves Service tokens. |
| | | 198 | | /// </summary> |
| | | 199 | | public SecurityTokenResolver ServiceTokenResolver |
| | | 200 | | { |
| | | 201 | | get |
| | | 202 | | { |
| | 4 | 203 | | return _serviceTokenResolver; |
| | | 204 | | } |
| | | 205 | | |
| | | 206 | | set |
| | | 207 | | { |
| | 0 | 208 | | _serviceTokenResolver = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof |
| | 0 | 209 | | } |
| | | 210 | | } |
| | | 211 | | |
| | | 212 | | /// <summary> |
| | | 213 | | /// Gets or sets the Caches that are used. |
| | | 214 | | /// </summary> |
| | | 215 | | public IdentityModelCaches Caches |
| | | 216 | | { |
| | | 217 | | get |
| | | 218 | | { |
| | 2 | 219 | | return _caches; |
| | | 220 | | } |
| | | 221 | | |
| | | 222 | | set |
| | | 223 | | { |
| | 0 | 224 | | _caches = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | 0 | 225 | | } |
| | | 226 | | } |
| | | 227 | | |
| | | 228 | | /// <summary> |
| | | 229 | | /// Gets or sets the expiration period for items placed in the TokenReplayCache. |
| | | 230 | | /// </summary> |
| | | 231 | | public TimeSpan TokenReplayCacheExpirationPeriod |
| | | 232 | | { |
| | | 233 | | get |
| | | 234 | | { |
| | 0 | 235 | | return _tokenReplayCacheExpirationPeriod; |
| | | 236 | | } |
| | | 237 | | |
| | | 238 | | set |
| | | 239 | | { |
| | 0 | 240 | | if (value <= TimeSpan.Zero) |
| | | 241 | | { |
| | 0 | 242 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(value), SR.Format(SR.ID0016)); |
| | | 243 | | } |
| | | 244 | | |
| | 0 | 245 | | _tokenReplayCacheExpirationPeriod = value; |
| | 0 | 246 | | } |
| | | 247 | | } |
| | | 248 | | } |
| | | 249 | | } |