Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
GenericPrincipal.cs
Go to the documentation of this file.
4
6
8{
9 private readonly IIdentity m_identity;
10
11 private readonly string[] m_roles;
12
13 public override IIdentity Identity => m_identity;
14
15 public GenericPrincipal(IIdentity identity, string[]? roles)
16 {
17 if (identity == null)
18 {
19 throw new ArgumentNullException("identity");
20 }
21 m_identity = identity;
22 if (roles != null)
23 {
24 m_roles = (string[])roles.Clone();
25 }
26 else
27 {
28 m_roles = null;
29 }
31 }
32
33 private void AddIdentityWithRoles(IIdentity identity, string[] roles)
34 {
36 if (roles != null && roles.Length != 0)
37 {
38 List<Claim> list = new List<Claim>(roles.Length);
39 foreach (string value in roles)
40 {
41 if (!string.IsNullOrWhiteSpace(value))
42 {
43 list.Add(new Claim(claimsIdentity2.RoleClaimType, value, "http://www.w3.org/2001/XMLSchema#string", "LOCAL AUTHORITY", "LOCAL AUTHORITY", claimsIdentity2));
44 }
45 }
46 claimsIdentity2.ExternalClaims.Add(list);
47 }
48 base.AddIdentity(claimsIdentity2);
49 }
50
51 public override bool IsInRole([NotNullWhen(true)] string? role)
52 {
53 if (role == null || m_roles == null)
54 {
55 return false;
56 }
57 for (int i = 0; i < m_roles.Length; i++)
58 {
59 if (string.Equals(m_roles[i], role, StringComparison.OrdinalIgnoreCase))
60 {
61 return true;
62 }
63 }
64 return base.IsInRole(role);
65 }
66
68 {
69 return new GenericPrincipal(new GenericIdentity(string.Empty), new string[1] { string.Empty });
70 }
71}
void Add(TKey key, TValue value)
void AddIdentityWithRoles(IIdentity identity, string[] roles)
override bool IsInRole([NotNullWhen(true)] string? role)
GenericPrincipal(IIdentity identity, string[]? roles)