Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
WindowsPrincipal.cs
Go to the documentation of this file.
5
7
9{
10 private readonly WindowsIdentity _identity;
11
12 public override IIdentity Identity => _identity;
13
15 {
16 get
17 {
18 foreach (ClaimsIdentity identity in Identities)
19 {
20 if (!(identity is WindowsIdentity windowsIdentity))
21 {
22 continue;
23 }
24 foreach (Claim userClaim in windowsIdentity.UserClaims)
25 {
26 yield return userClaim;
27 }
28 }
29 }
30 }
31
33 {
34 get
35 {
36 foreach (ClaimsIdentity identity in Identities)
37 {
38 if (!(identity is WindowsIdentity windowsIdentity))
39 {
40 continue;
41 }
42 foreach (Claim deviceClaim in windowsIdentity.DeviceClaims)
43 {
44 yield return deviceClaim;
45 }
46 }
47 }
48 }
49
52 {
53 _identity = ntIdentity ?? throw new ArgumentNullException("ntIdentity");
54 }
55
56 public override bool IsInRole(string role)
57 {
58 if (role == null || role.Length == 0)
59 {
60 return false;
61 }
62 NTAccount identity = new NTAccount(role);
67 {
68 return true;
69 }
70 return base.IsInRole(role);
71 }
72
73 public virtual bool IsInRole(WindowsBuiltInRole role)
74 {
76 {
78 }
79 return IsInRole((int)role);
80 }
81
82 public virtual bool IsInRole(int rid)
83 {
84 Span<int> span = stackalloc int[2] { 32, rid };
85 return IsInRole(new SecurityIdentifier(IdentifierAuthority.NTAuthority, span));
86 }
87
88 public virtual bool IsInRole(SecurityIdentifier sid)
89 {
90 if (sid == null)
91 {
92 throw new ArgumentNullException("sid");
93 }
95 {
96 return false;
97 }
99 if (_identity.ImpersonationLevel == TokenImpersonationLevel.None && !global::Interop.Advapi32.DuplicateTokenEx(_identity.AccessToken, 8u, IntPtr.Zero, 2u, 2u, ref phNewToken))
100 {
101 throw new SecurityException(new Win32Exception().Message);
102 }
103 bool IsMember = false;
104 if (!global::Interop.Advapi32.CheckTokenMembership((_identity.ImpersonationLevel != 0) ? _identity.AccessToken : phNewToken, sid.BinaryForm, ref IsMember))
105 {
106 throw new SecurityException(new Win32Exception().Message);
107 }
108 phNewToken.Dispose();
109 return IsMember;
110 }
111
113 {
115 }
116}
void Add(TKey key, TValue value)
static string Arg_EnumIllegalVal
Definition SR.cs:144
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7
virtual IEnumerable< ClaimsIdentity > Identities
override IdentityReference Translate(Type targetType)
Definition NTAccount.cs:72
virtual bool IsInRole(WindowsBuiltInRole role)
virtual bool IsInRole(SecurityIdentifier sid)
WindowsPrincipal(WindowsIdentity ntIdentity)
virtual IEnumerable< Claim > UserClaims
virtual IEnumerable< Claim > DeviceClaims
static readonly IntPtr Zero
Definition IntPtr.cs:18