tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
TgsRestAuthorizeAttribute{TAuthority}.cs
Go to the documentation of this file.
1using System;
2using System.Reflection;
3
4using Microsoft.AspNetCore.Authorization;
5
7
9{
14 [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
15 public sealed class TgsRestAuthorizeAttribute<TAuthority> : AuthorizeAttribute
16 where TAuthority : IAuthority
17 {
21 public string MethodName { get; }
22
27 public TgsRestAuthorizeAttribute(string methodName)
28 {
29 ArgumentNullException.ThrowIfNull(methodName);
30
31 var authorityType = typeof(TAuthority);
32 var authorityMethod = authorityType.GetMethod(methodName)
33 ?? throw new InvalidOperationException($"Could not find method {methodName} on {authorityType}!");
34
35 var authorizeAttribute = authorityMethod.GetCustomAttribute<TgsAuthorizeAttribute>()
36 ?? throw new InvalidOperationException($"Could not find method {authorityType}.{methodName}() has no {nameof(TgsAuthorizeAttribute)}!");
37
38 MethodName = methodName;
39 Roles = authorizeAttribute.Roles;
40 }
41 }
42}
Helper for using the AuthorizeAttribute with the Api.Rights system.
Inherits the roles of TgsAuthorizeAttributes for REST endpoints.
TgsRestAuthorizeAttribute(string methodName)
Initializes a new instance of the TgsRestAuthorizeAttribute<TAuthority> class.
Business logic for interating with the server.
Definition IAuthority.cs:9