tgstation-server 6.9.2
The /tg/station 13 server suite
Loading...
Searching...
No Matches
AuthenticationContext.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3
6
8{
11 {
13 public bool Valid { get; private set; }
14
16 public User User => user ?? throw new InvalidOperationException("AuthenticationContext is invalid!");
17
19 public PermissionSet PermissionSet => permissionSet ?? throw new InvalidOperationException("AuthenticationContext is invalid!");
20
22 public InstancePermissionSet? InstancePermissionSet { get; private set; }
23
25 public ISystemIdentity? SystemIdentity { get; private set; }
26
31
36
41 {
42 }
43
45 public void Dispose() => SystemIdentity?.Dispose();
46
66
69 {
71
72 if (User == null)
73 throw new InvalidOperationException("Authentication context has no user!");
74
75 if (isInstance && InstancePermissionSet == null)
76 return 0;
78
79 // use the api versions because they're the ones that contain the actual properties
81
84
85 var prop = typeToCheck.GetProperties().Where(x => x.PropertyType == nullableRightsType && x.CanRead).First();
86
87 var right = prop.GetMethod!.Invoke(
91 Array.Empty<object>())
92 ?? throw new InvalidOperationException("A user right was null!");
93
94 return (ulong)right;
95 }
96 }
97}
string? SystemIdentifier
The SID/UID of the UserModelBase on Windows/POSIX respectively.
static bool IsInstanceRight(RightsType rightsType)
Check if a given rightsType is meant for an Models.Instance.
static Type RightToType(RightsType rightsType)
Map a given rightsType to its respective Enum Type.
PermissionSet? PermissionSet
The Models.PermissionSet the UserGroup has.
Definition UserGroup.cs:20
UserGroup? Group
The UserGroup the User belongs to, if any.
Definition User.cs:32
void Initialize(ISystemIdentity? systemIdentity, User user, InstancePermissionSet? instanceUser)
Initializes the AuthenticationContext.
AuthenticationContext()
Initializes a new instance of the AuthenticationContext class.
PermissionSet? permissionSet
Backing field for PermissionSet.
ISystemIdentity? SystemIdentity
The ISystemIdentity of User if applicable.
bool Valid
If the IAuthenticationContext is for a valid login.
PermissionSet PermissionSet
The User's effective PermissionSet.
ulong GetRight(RightsType rightsType)
Get the value of a given rightsType .The value of rightsType . Note that if InstancePermissionSet is ...
Represents the currently authenticated Models.User.
Represents a user on the current global::System.Runtime.InteropServices.OSPlatform.
@ List
User may list files if the Models.Instance allows it.
RightsType
The type of rights a model uses.
Definition RightsType.cs:7