| | | 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 | | using System.Threading.Tasks; |
| | | 7 | | using System.Xml; |
| | | 8 | | using CoreWCF.IdentityModel.Policy; |
| | | 9 | | using CoreWCF.IdentityModel.Selectors; |
| | | 10 | | using CoreWCF.IdentityModel.Tokens; |
| | | 11 | | |
| | | 12 | | namespace CoreWCF.Security.Tokens |
| | | 13 | | { |
| | | 14 | | public class SecurityContextSecurityTokenAuthenticator : SecurityTokenAuthenticator |
| | | 15 | | { |
| | 22 | 16 | | public SecurityContextSecurityTokenAuthenticator() : base() |
| | 22 | 17 | | { } |
| | | 18 | | |
| | | 19 | | protected override bool CanValidateTokenCore(SecurityToken token) |
| | | 20 | | { |
| | 0 | 21 | | return (token is SecurityContextSecurityToken); |
| | | 22 | | } |
| | | 23 | | |
| | | 24 | | protected override ValueTask<ReadOnlyCollection<IAuthorizationPolicy>> ValidateTokenCoreAsync(SecurityToken toke |
| | | 25 | | { |
| | 0 | 26 | | SecurityContextSecurityToken sct = (SecurityContextSecurityToken)token; |
| | 0 | 27 | | if (!IsTimeValid(sct)) |
| | | 28 | | { |
| | 0 | 29 | | ThrowExpiredContextFaultException(sct.ContextId, sct); |
| | | 30 | | } |
| | | 31 | | |
| | 0 | 32 | | return new ValueTask<ReadOnlyCollection<IAuthorizationPolicy>>(sct.AuthorizationPolicies); |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | private void ThrowExpiredContextFaultException(UniqueId contextId, SecurityContextSecurityToken sct) |
| | | 36 | | { |
| | 0 | 37 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new Exception(SR.Format(SR.SecurityContextExpire |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | private bool IsTimeValid(SecurityContextSecurityToken sct) |
| | | 41 | | { |
| | 0 | 42 | | DateTime utcNow = DateTime.UtcNow; |
| | 0 | 43 | | return (sct.ValidFrom <= utcNow && sct.ValidTo >= utcNow && sct.KeyEffectiveTime <= utcNow); |
| | | 44 | | } |
| | | 45 | | } |
| | | 46 | | } |