| | | 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.Collections.ObjectModel; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | using CoreWCF.IdentityModel.Policy; |
| | | 8 | | using CoreWCF.IdentityModel.Selectors; |
| | | 9 | | using CoreWCF.IdentityModel.Tokens; |
| | | 10 | | |
| | | 11 | | namespace CoreWCF.Security |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Authenticator that wraps both SAML 1.1 and SAML 2.0 WrapperSecurityTokenAuthenticators. |
| | | 15 | | /// </summary> |
| | | 16 | | internal class WrappedSamlSecurityTokenAuthenticator : SecurityTokenAuthenticator |
| | | 17 | | { |
| | | 18 | | private WrappedSaml11SecurityTokenAuthenticator _wrappedSaml11SecurityTokenAuthenticator; |
| | | 19 | | private WrappedSaml2SecurityTokenAuthenticator _wrappedSaml2SecurityTokenAuthenticator; |
| | | 20 | | |
| | 2 | 21 | | public WrappedSamlSecurityTokenAuthenticator(WrappedSaml11SecurityTokenAuthenticator wrappedSaml11SecurityTokenA |
| | | 22 | | { |
| | 2 | 23 | | if (wrappedSaml11SecurityTokenAuthenticator == null) |
| | | 24 | | { |
| | 0 | 25 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(wrappedSaml11SecurityTokenAuthen |
| | | 26 | | } |
| | | 27 | | |
| | 2 | 28 | | if (wrappedSaml2SecurityTokenAuthenticator == null) |
| | | 29 | | { |
| | 0 | 30 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(wrappedSaml2SecurityTokenAuthent |
| | | 31 | | } |
| | | 32 | | |
| | 2 | 33 | | _wrappedSaml11SecurityTokenAuthenticator = wrappedSaml11SecurityTokenAuthenticator; |
| | 2 | 34 | | _wrappedSaml2SecurityTokenAuthenticator = wrappedSaml2SecurityTokenAuthenticator; |
| | 2 | 35 | | } |
| | | 36 | | |
| | | 37 | | protected override bool CanValidateTokenCore(SecurityToken token) |
| | | 38 | | { |
| | 94 | 39 | | return (_wrappedSaml11SecurityTokenAuthenticator.CanValidateToken(token) || _wrappedSaml2SecurityTokenAuthen |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | protected override ValueTask<ReadOnlyCollection<IAuthorizationPolicy>> ValidateTokenCoreAsync(SecurityToken toke |
| | | 43 | | { |
| | 47 | 44 | | if (_wrappedSaml11SecurityTokenAuthenticator.CanValidateToken(token)) |
| | | 45 | | { |
| | 47 | 46 | | return _wrappedSaml11SecurityTokenAuthenticator.ValidateTokenAsync(token); |
| | | 47 | | } |
| | 0 | 48 | | else if (_wrappedSaml2SecurityTokenAuthenticator.CanValidateToken(token)) |
| | | 49 | | { |
| | 0 | 50 | | return _wrappedSaml2SecurityTokenAuthenticator.ValidateTokenAsync(token); |
| | | 51 | | } |
| | | 52 | | else |
| | | 53 | | { |
| | 0 | 54 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.ID4101, tok |
| | | 55 | | } |
| | | 56 | | } |
| | | 57 | | } |
| | | 58 | | } |