using System; using System.Collections.Generic; using System.Text; using System.IdentityModel.Tokens; using System.Collections.ObjectModel; namespace System.IdentityModel.Tokens { /// /// A pseudo-token which handles encryption for a token which /// does not natively support it. /// /// /// For example, a SamlSecurityToken has no notion of how to encrypt /// itself, so to issue an encrypted SAML11 assertion, wrap a /// SamlSecurityToken with an EncryptedSecurityToken and provide /// appropriate EncryptingCredentials. /// public class EncryptedSecurityToken : SecurityToken { EncryptingCredentials _encryptingCredentials; SecurityToken _realToken; /// /// Creates an instance of EncryptedSecurityToken. /// /// The to encrypt. /// The to use for encryption. public EncryptedSecurityToken(SecurityToken token, EncryptingCredentials encryptingCredentials) { if (null == token) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("token"); } if (null == encryptingCredentials) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("encryptingCredentials"); } _encryptingCredentials = encryptingCredentials; _realToken = token; } /// /// Inherited from . /// public override bool CanCreateKeyIdentifierClause() { return _realToken.CanCreateKeyIdentifierClause(); } /// /// Inherited from . /// public override T CreateKeyIdentifierClause() { return _realToken.CreateKeyIdentifierClause(); } /// /// Gets the to use for encryption. /// public EncryptingCredentials EncryptingCredentials { get { return _encryptingCredentials; } } /// /// Gets a unique identifier of the security token. /// public override string Id { get { return _realToken.Id; } } /// /// Inherited from . /// public override bool MatchesKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause) { return _realToken.MatchesKeyIdentifierClause(keyIdentifierClause); } /// /// Inherited from . /// public override SecurityKey ResolveKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause) { return _realToken.ResolveKeyIdentifierClause(keyIdentifierClause); } /// /// Inherited from . /// public override ReadOnlyCollection SecurityKeys { get { return _realToken.SecurityKeys; } } /// /// Gets the encrypted . /// public SecurityToken Token { get { return _realToken; } } /// /// Gets the first instant in time at which this security token is valid. /// public override DateTime ValidFrom { get { return _realToken.ValidFrom; } } /// /// Gets the last instant in time at which this security token is valid. /// public override DateTime ValidTo { get { return _realToken.ValidTo; } } } }