| | | 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.Authentication.ExtendedProtection; |
| | | 6 | | using CoreWCF.IdentityModel.Selectors; |
| | | 7 | | using CoreWCF.IdentityModel.Tokens; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Security.Tokens |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// The ProviderBackedSecurityToken was added for the ChannelBindingToken work for Win7. |
| | | 13 | | /// It is used to delay the resolution of a token until it is needed. |
| | | 14 | | /// For the CBT, this delay is necessary as the CBT is not available until SecurityAppliedMessage.OnWriteMessage is |
| | | 15 | | /// The CBT binds a token to the |
| | | 16 | | /// </summary> |
| | | 17 | | internal class ProviderBackedSecurityToken : SecurityToken |
| | | 18 | | { |
| | | 19 | | // Double-checked locking pattern requires volatile for read/write synchronization |
| | | 20 | | #pragma warning disable CS0649 // The field is never assigned to |
| | | 21 | | private readonly SecurityToken _securityToken; |
| | | 22 | | #pragma warning restore CS0649 // The field is never assigned to |
| | | 23 | | private TimeSpan _timeout; |
| | | 24 | | private ChannelBinding _channelBinding; |
| | | 25 | | private readonly object _lock; |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Constructor to create an instance of this class. |
| | | 29 | | /// </summary> |
| | | 30 | | /// <param name="securityToken">SecurityToken that represents the SecurityTokenElement element.</param> |
| | 0 | 31 | | public ProviderBackedSecurityToken(SecurityTokenProvider tokenProvider, TimeSpan timeout) |
| | | 32 | | { |
| | 0 | 33 | | _lock = new object(); |
| | 0 | 34 | | TokenProvider = tokenProvider ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullE |
| | 0 | 35 | | _timeout = timeout; |
| | 0 | 36 | | } |
| | | 37 | | |
| | 0 | 38 | | public SecurityTokenProvider TokenProvider { get; } |
| | | 39 | | |
| | | 40 | | public ChannelBinding ChannelBinding |
| | | 41 | | { |
| | 0 | 42 | | set { _channelBinding = value; } |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | private void ResolveSecurityToken() |
| | | 46 | | { |
| | 0 | 47 | | throw new NotImplementedException(); |
| | | 48 | | //TODO |
| | | 49 | | //if ( _securityToken == null ) |
| | | 50 | | //{ |
| | | 51 | | // lock ( _lock ) |
| | | 52 | | // { |
| | | 53 | | // if ( _securityToken == null ) |
| | | 54 | | // { |
| | | 55 | | |
| | | 56 | | // ClientCredentialsSecurityTokenManager.KerberosSecurityTokenProviderWrapper kerbTokenProvider = |
| | | 57 | | // as ClientCredentialsSecurityTokenManager.KerberosSecurityToken |
| | | 58 | | // if (kerbTokenProvider != null) |
| | | 59 | | // { |
| | | 60 | | // _securityToken = kerbTokenProvider.GetToken((new TimeoutHelper(_timeout)).RemainingTime(), |
| | | 61 | | // } |
| | | 62 | | // else |
| | | 63 | | // { |
| | | 64 | | // _securityToken = _tokenProvider.GetToken((new TimeoutHelper(_timeout)).RemainingTime()); |
| | | 65 | | // } |
| | | 66 | | // } |
| | | 67 | | // } |
| | | 68 | | //} |
| | | 69 | | |
| | | 70 | | //if ( _securityToken == null ) |
| | | 71 | | //{ |
| | | 72 | | // throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new SecurityTokenException( SR.Format( SR.S |
| | | 73 | | //} |
| | | 74 | | |
| | | 75 | | //return; |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | public SecurityToken Token |
| | | 79 | | { |
| | | 80 | | get |
| | | 81 | | { |
| | 0 | 82 | | if (_securityToken == null) |
| | | 83 | | { |
| | 0 | 84 | | ResolveSecurityToken(); |
| | | 85 | | } |
| | | 86 | | |
| | 0 | 87 | | return _securityToken; |
| | | 88 | | } |
| | | 89 | | } |
| | | 90 | | |
| | | 91 | | public override string Id |
| | | 92 | | { |
| | | 93 | | get |
| | | 94 | | { |
| | 0 | 95 | | if (_securityToken == null) |
| | | 96 | | { |
| | 0 | 97 | | ResolveSecurityToken(); |
| | | 98 | | } |
| | | 99 | | |
| | 0 | 100 | | return _securityToken.Id; |
| | | 101 | | } |
| | | 102 | | } |
| | | 103 | | |
| | | 104 | | public override System.Collections.ObjectModel.ReadOnlyCollection<SecurityKey> SecurityKeys |
| | | 105 | | { |
| | | 106 | | get |
| | | 107 | | { |
| | 0 | 108 | | if (_securityToken == null) |
| | | 109 | | { |
| | 0 | 110 | | ResolveSecurityToken(); |
| | | 111 | | } |
| | | 112 | | |
| | 0 | 113 | | return _securityToken.SecurityKeys; |
| | | 114 | | } |
| | | 115 | | } |
| | | 116 | | |
| | | 117 | | public override DateTime ValidFrom |
| | | 118 | | { |
| | | 119 | | get |
| | | 120 | | { |
| | 0 | 121 | | if (_securityToken == null) |
| | | 122 | | { |
| | 0 | 123 | | ResolveSecurityToken(); |
| | | 124 | | } |
| | | 125 | | |
| | 0 | 126 | | return _securityToken.ValidFrom; |
| | | 127 | | } |
| | | 128 | | } |
| | | 129 | | |
| | | 130 | | public override DateTime ValidTo |
| | | 131 | | { |
| | | 132 | | get |
| | | 133 | | { |
| | 0 | 134 | | if (_securityToken == null) |
| | | 135 | | { |
| | 0 | 136 | | ResolveSecurityToken(); |
| | | 137 | | } |
| | | 138 | | |
| | 0 | 139 | | return _securityToken.ValidTo; |
| | | 140 | | } |
| | | 141 | | } |
| | | 142 | | } |
| | | 143 | | } |