| | | 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.Collections.ObjectModel; |
| | | 7 | | using System.Security.Claims; |
| | | 8 | | using System.Threading.Tasks; |
| | | 9 | | using CoreWCF.IdentityModel.Claims; |
| | | 10 | | using CoreWCF.IdentityModel.Policy; |
| | | 11 | | using CoreWCF.IdentityModel.Tokens; |
| | | 12 | | using CoreWCF.Security; |
| | | 13 | | |
| | | 14 | | namespace CoreWCF.IdentityModel.Selectors |
| | | 15 | | { |
| | | 16 | | public class WindowsSecurityTokenAuthenticator : SecurityTokenAuthenticator |
| | | 17 | | { |
| | | 18 | | private readonly bool _includeWindowsGroups; |
| | | 19 | | private readonly LdapSettings _ldapSettings; |
| | | 20 | | |
| | 1 | 21 | | public WindowsSecurityTokenAuthenticator() : this(WindowsClaimSet.DefaultIncludeWindowsGroups, null) |
| | | 22 | | { |
| | 1 | 23 | | } |
| | | 24 | | |
| | 1 | 25 | | public WindowsSecurityTokenAuthenticator(bool includeWindowsGroups, LdapSettings ldapSettings) |
| | | 26 | | { |
| | 1 | 27 | | _includeWindowsGroups = includeWindowsGroups; |
| | 1 | 28 | | _ldapSettings = ldapSettings; |
| | 1 | 29 | | } |
| | | 30 | | |
| | | 31 | | protected override bool CanValidateTokenCore(SecurityToken token) |
| | | 32 | | { |
| | 1 | 33 | | return (token is WindowsSecurityToken || token is GenericIdentitySecurityToken); |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | protected override ValueTask<ReadOnlyCollection<IAuthorizationPolicy>> ValidateTokenCoreAsync(SecurityToken toke |
| | | 37 | | { |
| | 1 | 38 | | if (token is WindowsSecurityToken) |
| | | 39 | | { |
| | 0 | 40 | | var windowsToken = (WindowsSecurityToken)token; |
| | 0 | 41 | | var claimSet = new WindowsClaimSet(windowsToken.WindowsIdentity, windowsToken.AuthenticationType, _inclu |
| | 0 | 42 | | return new ValueTask<ReadOnlyCollection<IAuthorizationPolicy>>(SecurityUtils.CreateAuthorizationPolicies |
| | | 43 | | } |
| | | 44 | | else |
| | | 45 | | { |
| | 1 | 46 | | var genericToken = (GenericIdentitySecurityToken)token; |
| | 1 | 47 | | var claimSet = new WindowsClaimSet(genericToken.GenericIdentity, _includeWindowsGroups, _ldapSettings); |
| | 1 | 48 | | return new ValueTask<ReadOnlyCollection<IAuthorizationPolicy>>(SecurityUtils.CreateAuthorizationPolicies |
| | | 49 | | } |
| | | 50 | | } |
| | | 51 | | } |
| | | 52 | | } |