| | | 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 | | |
| | | 7 | | namespace CoreWCF.IdentityModel.Tokens |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// A pseudo-token which handles encryption for a token which |
| | | 11 | | /// does not natively support it. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <remarks> |
| | | 14 | | /// For example, a SamlSecurityToken has no notion of how to encrypt |
| | | 15 | | /// itself, so to issue an encrypted SAML11 assertion, wrap a |
| | | 16 | | /// SamlSecurityToken with an EncryptedSecurityToken and provide |
| | | 17 | | /// appropriate EncryptingCredentials. |
| | | 18 | | /// </remarks> |
| | | 19 | | public class EncryptedSecurityToken : SecurityToken |
| | | 20 | | { |
| | | 21 | | /// <summary> |
| | | 22 | | /// Creates an instance of EncryptedSecurityToken. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="token">The <see cref="SecurityToken"/> to encrypt.</param> |
| | | 25 | | /// <param name="encryptingCredentials">The <see cref="EncryptingCredentials"/> to use for encryption.</param> |
| | 0 | 26 | | public EncryptedSecurityToken(SecurityToken token, EncryptingCredentials encryptingCredentials) |
| | | 27 | | { |
| | 0 | 28 | | EncryptingCredentials = encryptingCredentials ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumen |
| | 0 | 29 | | Token = token ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(token)); |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Inherited from <see cref="SecurityToken"/>. |
| | | 34 | | /// </summary> |
| | | 35 | | public override bool CanCreateKeyIdentifierClause<T>() |
| | | 36 | | { |
| | 0 | 37 | | return Token.CanCreateKeyIdentifierClause<T>(); |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Inherited from <see cref="SecurityToken"/>. |
| | | 42 | | /// </summary> |
| | | 43 | | public override T CreateKeyIdentifierClause<T>() |
| | | 44 | | { |
| | 0 | 45 | | return Token.CreateKeyIdentifierClause<T>(); |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Gets the <see cref="EncryptingCredentials"/> to use for encryption. |
| | | 50 | | /// </summary> |
| | 0 | 51 | | public EncryptingCredentials EncryptingCredentials { get; } |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Gets a unique identifier of the security token. |
| | | 55 | | /// </summary> |
| | 0 | 56 | | public override string Id => Token.Id; |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Inherited from <see cref="SecurityToken"/>. |
| | | 60 | | /// </summary> |
| | | 61 | | public override bool MatchesKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause) |
| | | 62 | | { |
| | 0 | 63 | | return Token.MatchesKeyIdentifierClause(keyIdentifierClause); |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | /// <summary> |
| | | 67 | | /// Inherited from <see cref="SecurityToken"/>. |
| | | 68 | | /// </summary> |
| | | 69 | | public override SecurityKey ResolveKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause) |
| | | 70 | | { |
| | 0 | 71 | | return Token.ResolveKeyIdentifierClause(keyIdentifierClause); |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Inherited from <see cref="SecurityToken"/>. |
| | | 76 | | /// </summary> |
| | 0 | 77 | | public override ReadOnlyCollection<SecurityKey> SecurityKeys => Token.SecurityKeys; |
| | | 78 | | |
| | | 79 | | /// <summary> |
| | | 80 | | /// Gets the encrypted <see cref="SecurityToken"/>. |
| | | 81 | | /// </summary> |
| | 0 | 82 | | public SecurityToken Token { get; } |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// Gets the first instant in time at which this security token is valid. |
| | | 86 | | /// </summary> |
| | 0 | 87 | | public override DateTime ValidFrom => Token.ValidFrom; |
| | | 88 | | |
| | | 89 | | /// <summary> |
| | | 90 | | /// Gets the last instant in time at which this security token is valid. |
| | | 91 | | /// </summary> |
| | 0 | 92 | | public override DateTime ValidTo => Token.ValidTo; |
| | | 93 | | } |
| | | 94 | | } |