| | | 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 CoreWCF.Runtime; |
| | | 6 | | using CoreWCF.Security.Tokens; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Security |
| | | 9 | | { |
| | | 10 | | internal class NegotiationTokenAuthenticatorState : IDisposable |
| | | 11 | | { |
| | | 12 | | private bool _isNegotiationCompleted; |
| | | 13 | | private SecurityContextSecurityToken _serviceToken; |
| | | 14 | | |
| | 0 | 15 | | public AsyncLock AsyncLock { get; } = new AsyncLock(); |
| | | 16 | | |
| | 0 | 17 | | public bool IsNegotiationCompleted => _isNegotiationCompleted; |
| | | 18 | | |
| | | 19 | | public SecurityContextSecurityToken ServiceToken |
| | | 20 | | { |
| | | 21 | | get |
| | | 22 | | { |
| | 0 | 23 | | CheckCompleted(); |
| | 0 | 24 | | return _serviceToken; |
| | | 25 | | } |
| | | 26 | | } |
| | | 27 | | |
| | 0 | 28 | | public virtual void Dispose() { } |
| | | 29 | | |
| | | 30 | | public void SetServiceToken(SecurityContextSecurityToken token) |
| | | 31 | | { |
| | 0 | 32 | | _serviceToken = token ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(token)); |
| | 0 | 33 | | _isNegotiationCompleted = true; |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | public virtual string GetRemoteIdentityName() |
| | | 37 | | { |
| | 0 | 38 | | if (_isNegotiationCompleted) |
| | | 39 | | { |
| | 0 | 40 | | return SecurityUtils.GetIdentityNamesFromPolicies(_serviceToken.AuthorizationPolicies); |
| | | 41 | | } |
| | 0 | 42 | | return string.Empty; |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | private void CheckCompleted() |
| | | 46 | | { |
| | 0 | 47 | | if (!_isNegotiationCompleted) |
| | | 48 | | { |
| | 0 | 49 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Neg |
| | | 50 | | } |
| | 0 | 51 | | } |
| | | 52 | | } |
| | | 53 | | } |