| | | 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.Principal; |
| | | 5 | | |
| | | 6 | | namespace CoreWCF.Security.Tokens |
| | | 7 | | { |
| | | 8 | | internal class WindowsSidIdentity : IIdentity |
| | | 9 | | { |
| | | 10 | | private string _name; |
| | | 11 | | |
| | 0 | 12 | | public WindowsSidIdentity(SecurityIdentifier sid) |
| | | 13 | | { |
| | 0 | 14 | | SecurityIdentifier = sid ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(sid)); |
| | 0 | 15 | | AuthenticationType = string.Empty; |
| | 0 | 16 | | } |
| | | 17 | | |
| | 0 | 18 | | public WindowsSidIdentity(SecurityIdentifier sid, string name, string authenticationType) |
| | | 19 | | { |
| | 0 | 20 | | SecurityIdentifier = sid ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(sid)); |
| | 0 | 21 | | _name = name ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(name)); |
| | 0 | 22 | | AuthenticationType = authenticationType ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull( |
| | 0 | 23 | | } |
| | | 24 | | |
| | 0 | 25 | | public SecurityIdentifier SecurityIdentifier { get; } |
| | | 26 | | |
| | 0 | 27 | | public string AuthenticationType { get; } |
| | | 28 | | |
| | | 29 | | public bool IsAuthenticated |
| | | 30 | | { |
| | 0 | 31 | | get { return true; } |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | public string Name |
| | | 35 | | { |
| | | 36 | | get |
| | | 37 | | { |
| | 0 | 38 | | if (_name == null) |
| | | 39 | | { |
| | 0 | 40 | | _name = ((NTAccount)SecurityIdentifier.Translate(typeof(NTAccount))).Value; |
| | | 41 | | } |
| | | 42 | | |
| | 0 | 43 | | return _name; |
| | | 44 | | } |
| | | 45 | | } |
| | | 46 | | |
| | | 47 | | public override bool Equals(object obj) |
| | | 48 | | { |
| | 0 | 49 | | if (ReferenceEquals(this, obj)) |
| | | 50 | | { |
| | 0 | 51 | | return true; |
| | | 52 | | } |
| | | 53 | | |
| | 0 | 54 | | if (!(obj is WindowsSidIdentity sidIdentity)) |
| | | 55 | | { |
| | 0 | 56 | | return false; |
| | | 57 | | } |
| | | 58 | | |
| | 0 | 59 | | return SecurityIdentifier == sidIdentity.SecurityIdentifier; |
| | | 60 | | } |
| | | 61 | | |
| | | 62 | | public override int GetHashCode() |
| | | 63 | | { |
| | 0 | 64 | | return SecurityIdentifier.GetHashCode(); |
| | | 65 | | } |
| | | 66 | | } |
| | | 67 | | } |