tgstation-server 6.12.0
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 InvalidContext();
17
20
22 public InstancePermissionSet? InstancePermissionSet { get; private set; }
23
25 public ISystemIdentity? SystemIdentity { get; private set; }
26
29
31 public string SessionId => sessionId ?? throw InvalidContext();
32
37
42
47
51 string? sessionId;
52
57 {
58 }
59
65 => new("AuthenticationContext is invalid!");
66
68 public void Dispose() => SystemIdentity?.Dispose();
69
101
104 {
106
107 if (User == null)
108 throw new InvalidOperationException("Authentication context has no user!");
109
110 if (isInstance && InstancePermissionSet == null)
111 return 0;
113
114 // use the api versions because they're the ones that contain the actual properties
116
119
120 var prop = typeToCheck.GetProperties().Where(x => x.PropertyType == nullableRightsType && x.CanRead).First();
121
122 var right = prop.GetMethod!.Invoke(
126 Array.Empty<object>())
127 ?? throw new InvalidOperationException("A user right was null!");
128
129 return (ulong)right;
130 }
131 }
132}
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:21
UserGroup? Group
The UserGroup the User belongs to, if any.
Definition User.cs:41
string SessionId
A string that uniquely identifies the login session.
AuthenticationContext()
Initializes a new instance of the AuthenticationContext class.
DateTimeOffset SessionExpiry
When the login session expires.
PermissionSet? permissionSet
Backing field for PermissionSet.
void Initialize(User user, DateTimeOffset sessionExpiry, string sessionId, InstancePermissionSet? instanceUser, ISystemIdentity? systemIdentity)
Initializes the AuthenticationContext.
static InvalidOperationException InvalidContext()
InvalidOperationException for accessing fields on an InValid AuthenticationContext.
ISystemIdentity? SystemIdentity
The ISystemIdentity of User if applicable.
DateTimeOffset? sessionExpiry
Backing field for SessionExpiry.
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 ...
For creating and accessing authentication contexts.
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