tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
AuthenticationContextClaimsTransformation.cs
Go to the documentation of this file.
1using System;
5
7
10
12{
17 {
22
31
34 {
36
38 throw new InvalidOperationException("Expected a valid authentication context here!");
39
40 var enumerator = Enum.GetValues(typeof(RightsType));
41 var claims = new List<Claim>();
42 if (authenticationContext.User.Require(x => x.Enabled))
43 claims.Add(
44 new Claim(
45 ClaimTypes.Role,
47
49 {
50 // if there's a bad condition, do a weird thing and add all the roles
51 // we need it so we can get to TgsAuthorizeAttribute where we can properly decide between BadRequest and Forbid
53 ? ~0UL
57 foreach (Enum enumeratedRight in Enum.GetValues(rightEnum))
58 if (right.HasFlag(enumeratedRight))
59 claims.Add(
60 new Claim(
61 ClaimTypes.Role,
63 }
64
65 principal.AddIdentity(new ClaimsIdentity(claims));
66
67 return Task.FromResult(principal);
68 }
69 }
70}
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.
static string RoleName(RightsType rightsType, Enum right)
Gets the role claim name used for a given rightsType and right .
A IClaimsTransformation that maps Claims using an IAuthenticationContext.
AuthenticationContextClaimsTransformation(IAuthenticationContext authenticationContext)
Initializes a new instance of the AuthenticationContextClaimsTransformation class.
readonly IAuthenticationContext authenticationContext
The IAuthenticationContext for the AuthenticationContextClaimsTransformation.
Helper for using the AuthorizeAttribute with the Api.Rights system.
const string UserEnabledRole
Role used to indicate access to the server is allowed.
For creating and accessing authentication contexts.
bool Valid
If the IAuthenticationContext is for a valid login.
ulong GetRight(RightsType rightsType)
Get the value of a given rightsType .
@ List
User may list files if the Models.Instance allows it.
RightsType
The type of rights a model uses.
Definition RightsType.cs:7