| | | 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.Generic; |
| | | 6 | | using System.Security.Claims; |
| | | 7 | | using System.Xml; |
| | | 8 | | using CoreWCF.IdentityModel.Claims; |
| | | 9 | | using CoreWCF.IdentityModel.Protocols.WSTrust; |
| | | 10 | | |
| | | 11 | | namespace CoreWCF.IdentityModel.Tokens |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// This is a place holder for all the attributes related to the issued token. |
| | | 15 | | /// </summary> |
| | | 16 | | public class SecurityTokenDescriptor |
| | | 17 | | { |
| | | 18 | | private string _appliesToAddress; |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets or sets the address for the <see cref="RequestSecurityTokenResponse"/> AppliesTo property. |
| | | 22 | | /// </summary> |
| | | 23 | | /// <exception cref="InvalidOperationException">Thrown if not an absolute URI.</exception> |
| | | 24 | | public string AppliesToAddress |
| | | 25 | | { |
| | | 26 | | get |
| | | 27 | | { |
| | 0 | 28 | | return _appliesToAddress; |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | set |
| | | 32 | | { |
| | 0 | 33 | | if (!string.IsNullOrEmpty(value)) |
| | | 34 | | { |
| | | 35 | | //if (!UriUtil.CanCreateValidUri(value, UriKind.Absolute)) |
| | | 36 | | //{ |
| | | 37 | | // throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.For |
| | | 38 | | //} |
| | | 39 | | } |
| | | 40 | | |
| | 0 | 41 | | _appliesToAddress = value; |
| | 0 | 42 | | } |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Gets or sets the address for the <see cref="RequestSecurityTokenResponse"/> ReplyToAddress property. |
| | | 47 | | /// </summary> |
| | 0 | 48 | | public string ReplyToAddress { get; set; } |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Gets or sets the credentials used to encrypt the token. |
| | | 52 | | /// </summary> |
| | 0 | 53 | | public EncryptingCredentials EncryptingCredentials { get; set; } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Gets or sets the credentials used to sign the token. |
| | | 57 | | /// </summary> |
| | 0 | 58 | | public SigningCredentials SigningCredentials { get; set; } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Gets or sets the SecurityKeyIdentifierClause when the token is attached |
| | | 62 | | /// to the message. |
| | | 63 | | /// </summary> |
| | 0 | 64 | | public SecurityKeyIdentifierClause AttachedReference { get; set; } |
| | | 65 | | |
| | | 66 | | /// <summary> |
| | | 67 | | /// Gets or sets the issuer name, which may be used inside the issued token as well. |
| | | 68 | | /// </summary> |
| | 0 | 69 | | public string TokenIssuerName { get; set; } |
| | | 70 | | |
| | | 71 | | /// <summary> |
| | | 72 | | /// Gets or sets the proof descriptor, which can be used to modify some fields inside |
| | | 73 | | /// the RSTR, such as requested proof token. |
| | | 74 | | /// </summary> |
| | | 75 | | //public ProofDescriptor Proof |
| | | 76 | | //{ |
| | | 77 | | // get { return this.proofDescriptor; } |
| | | 78 | | // set { this.proofDescriptor = value; } |
| | | 79 | | //} |
| | | 80 | | |
| | | 81 | | /// <summary> |
| | | 82 | | /// Gets the properties bag to extend the object. |
| | | 83 | | /// </summary> |
| | 0 | 84 | | public Dictionary<string, object> Properties { get; } = new Dictionary<string, object>(); |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// Gets or sets the issued security token. |
| | | 88 | | /// </summary> |
| | 0 | 89 | | public SecurityToken Token { get; set; } |
| | | 90 | | |
| | | 91 | | /// <summary> |
| | | 92 | | /// Gets or sets the token type of the issued token. |
| | | 93 | | /// </summary> |
| | 0 | 94 | | public string TokenType { get; set; } |
| | | 95 | | |
| | | 96 | | /// <summary> |
| | | 97 | | /// Gets or sets the unattached token reference to refer to the issued token when it is not |
| | | 98 | | /// attached to the message. |
| | | 99 | | /// </summary> |
| | 0 | 100 | | public SecurityKeyIdentifierClause UnattachedReference { get; set; } |
| | | 101 | | |
| | | 102 | | /// <summary> |
| | | 103 | | /// Gets or sets the lifetime information for the issued token. |
| | | 104 | | /// </summary> |
| | 0 | 105 | | public Lifetime Lifetime { get; set; } |
| | | 106 | | |
| | | 107 | | /// <summary> |
| | | 108 | | /// Gets or sets the OutputClaims to be included in the issued token. |
| | | 109 | | /// </summary> |
| | 0 | 110 | | public ClaimsIdentity Subject { get; set; } |
| | | 111 | | |
| | | 112 | | /// <summary> |
| | | 113 | | /// Gets or sets the AuthenticationInformation. |
| | | 114 | | /// </summary> |
| | 0 | 115 | | public AuthenticationInformation AuthenticationInfo { get; set; } |
| | | 116 | | |
| | | 117 | | /// <summary> |
| | | 118 | | /// Adds a <see cref="Claim"/> for the authentication type to the claim collection of |
| | | 119 | | /// the <see cref="SecurityTokenDescriptor"/> |
| | | 120 | | /// </summary> |
| | | 121 | | /// <param name="authType">The authentication type.</param> |
| | | 122 | | public void AddAuthenticationClaims(string authType) |
| | | 123 | | { |
| | 0 | 124 | | AddAuthenticationClaims(authType, DateTime.UtcNow); |
| | 0 | 125 | | } |
| | | 126 | | |
| | | 127 | | /// <summary> |
| | | 128 | | /// Adds <see cref="Claim"/>s for the authentication type and the authentication instant |
| | | 129 | | /// to the claim collection of the <see cref="SecurityTokenDescriptor"/> |
| | | 130 | | /// </summary> |
| | | 131 | | /// <param name="authType">Specifies the authentication type</param> |
| | | 132 | | /// <param name="time">Specifies the authentication instant in UTC. If the input is not in UTC, it is converted |
| | | 133 | | public void AddAuthenticationClaims(string authType, DateTime time) |
| | | 134 | | { |
| | 0 | 135 | | Subject.AddClaim( |
| | 0 | 136 | | new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.AuthenticationMethod, authType, Claim |
| | | 137 | | |
| | 0 | 138 | | Subject.AddClaim( |
| | 0 | 139 | | new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.AuthenticationInstant, XmlConvert.ToS |
| | 0 | 140 | | } |
| | | 141 | | } |
| | | 142 | | } |