| | | 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.Net; |
| | | 7 | | using System.Security.Principal; |
| | | 8 | | using CoreWCF.IdentityModel; |
| | | 9 | | using CoreWCF.IdentityModel.Tokens; |
| | | 10 | | |
| | | 11 | | namespace CoreWCF.Security.Tokens |
| | | 12 | | { |
| | | 13 | | public class SspiSecurityToken : SecurityToken |
| | | 14 | | { |
| | | 15 | | private string _id; |
| | | 16 | | private readonly DateTime _effectiveTime; |
| | | 17 | | private readonly DateTime _expirationTime; |
| | | 18 | | |
| | 0 | 19 | | public SspiSecurityToken(TokenImpersonationLevel impersonationLevel, bool allowNtlm, NetworkCredential networkCr |
| | | 20 | | { |
| | 0 | 21 | | ImpersonationLevel = impersonationLevel; |
| | 0 | 22 | | AllowNtlm = allowNtlm; |
| | 0 | 23 | | NetworkCredential = SecurityUtils.GetNetworkCredentialsCopy(networkCredential); |
| | 0 | 24 | | _effectiveTime = DateTime.UtcNow; |
| | 0 | 25 | | _expirationTime = _effectiveTime.AddHours(10); |
| | 0 | 26 | | } |
| | | 27 | | |
| | 12 | 28 | | public SspiSecurityToken(NetworkCredential networkCredential, bool extractGroupsForWindowsAccounts, bool allowUn |
| | | 29 | | { |
| | 12 | 30 | | NetworkCredential = SecurityUtils.GetNetworkCredentialsCopy(networkCredential); |
| | 12 | 31 | | ExtractGroupsForWindowsAccounts = extractGroupsForWindowsAccounts; |
| | 12 | 32 | | AllowUnauthenticatedCallers = allowUnauthenticatedCallers; |
| | 12 | 33 | | _effectiveTime = DateTime.UtcNow; |
| | 12 | 34 | | _expirationTime = _effectiveTime.AddHours(10); |
| | 12 | 35 | | } |
| | | 36 | | |
| | | 37 | | public override string Id |
| | | 38 | | { |
| | | 39 | | get |
| | | 40 | | { |
| | 0 | 41 | | if (_id == null) |
| | | 42 | | { |
| | 0 | 43 | | _id = SecurityUniqueId.Create().Value; |
| | | 44 | | } |
| | | 45 | | |
| | 0 | 46 | | return _id; |
| | | 47 | | } |
| | | 48 | | } |
| | | 49 | | |
| | 0 | 50 | | public override DateTime ValidFrom => _effectiveTime; |
| | | 51 | | |
| | 0 | 52 | | public override DateTime ValidTo => _expirationTime; |
| | | 53 | | |
| | 0 | 54 | | public bool AllowUnauthenticatedCallers { get; } = SspiSecurityTokenProvider.DefaultAllowUnauthenticatedCallers; |
| | | 55 | | |
| | 12 | 56 | | public TokenImpersonationLevel ImpersonationLevel { get; } |
| | | 57 | | |
| | 12 | 58 | | public bool AllowNtlm { get; } |
| | | 59 | | |
| | 12 | 60 | | public NetworkCredential NetworkCredential { get; } |
| | | 61 | | |
| | 12 | 62 | | public bool ExtractGroupsForWindowsAccounts { get; } |
| | | 63 | | |
| | 0 | 64 | | public override ReadOnlyCollection<SecurityKey> SecurityKeys => EmptyReadOnlyCollection<SecurityKey>.Instance; |
| | | 65 | | } |
| | | 66 | | } |