| | | 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.Security.Cryptography.X509Certificates; |
| | | 5 | | using System.Security.Principal; |
| | | 6 | | using CoreWCF.Security; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.IdentityModel.Tokens |
| | | 9 | | { |
| | | 10 | | internal class X509WindowsSecurityToken : X509SecurityToken |
| | | 11 | | { |
| | | 12 | | private WindowsIdentity _windowsIdentity; |
| | | 13 | | private bool _disposed = false; |
| | | 14 | | |
| | | 15 | | public X509WindowsSecurityToken(X509Certificate2 certificate, WindowsIdentity windowsIdentity) |
| | 0 | 16 | | : this(certificate, windowsIdentity, null, true) |
| | | 17 | | { |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | public X509WindowsSecurityToken(X509Certificate2 certificate, WindowsIdentity windowsIdentity, string id) |
| | 0 | 21 | | : this(certificate, windowsIdentity, null, id, true) |
| | | 22 | | { |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | public X509WindowsSecurityToken(X509Certificate2 certificate, WindowsIdentity windowsIdentity, string authentica |
| | 0 | 26 | | : this(certificate, windowsIdentity, authenticationType, id, true) |
| | | 27 | | { |
| | 0 | 28 | | } |
| | | 29 | | |
| | | 30 | | internal X509WindowsSecurityToken(X509Certificate2 certificate, WindowsIdentity windowsIdentity, string authenti |
| | 0 | 31 | | : this(certificate, windowsIdentity, authenticationType, SecurityUniqueId.Create().Value, clone) |
| | | 32 | | { |
| | 0 | 33 | | } |
| | | 34 | | |
| | | 35 | | internal X509WindowsSecurityToken(X509Certificate2 certificate, WindowsIdentity windowsIdentity, string authenti |
| | 0 | 36 | | : base(certificate, id, clone) |
| | | 37 | | { |
| | 0 | 38 | | if (windowsIdentity == null) |
| | | 39 | | { |
| | 0 | 40 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(windowsIdentity)); |
| | | 41 | | } |
| | | 42 | | |
| | 0 | 43 | | AuthenticationType = authenticationType; |
| | 0 | 44 | | _windowsIdentity = clone ? SecurityUtils.CloneWindowsIdentityIfNecessary(windowsIdentity, authenticationType |
| | 0 | 45 | | } |
| | | 46 | | |
| | | 47 | | |
| | | 48 | | public WindowsIdentity WindowsIdentity |
| | | 49 | | { |
| | | 50 | | get |
| | | 51 | | { |
| | 0 | 52 | | ThrowIfDisposed(); |
| | 0 | 53 | | return _windowsIdentity; |
| | | 54 | | } |
| | | 55 | | } |
| | | 56 | | |
| | 0 | 57 | | public string AuthenticationType { get; } |
| | | 58 | | |
| | | 59 | | public override void Dispose() |
| | | 60 | | { |
| | | 61 | | try |
| | | 62 | | { |
| | 0 | 63 | | if (!_disposed) |
| | | 64 | | { |
| | 0 | 65 | | _disposed = true; |
| | 0 | 66 | | _windowsIdentity.Dispose(); |
| | 0 | 67 | | _windowsIdentity = null; |
| | | 68 | | } |
| | 0 | 69 | | } |
| | | 70 | | finally |
| | | 71 | | { |
| | 0 | 72 | | base.Dispose(); |
| | 0 | 73 | | } |
| | 0 | 74 | | } |
| | | 75 | | } |
| | | 76 | | } |