tgstation-server 6.1.2
The /tg/station 13 server suite
Loading...
Searching...
No Matches
TgsAuthorizeAttribute.cs
Go to the documentation of this file.
1using System;
2
3using Microsoft.AspNetCore.Authorization;
4using Microsoft.AspNetCore.Mvc;
5using Microsoft.AspNetCore.Mvc.Filters;
6using Microsoft.Extensions.DependencyInjection;
7using Microsoft.Extensions.Logging;
8
11
13{
17#pragma warning disable CA1019
18 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
20 {
24 public RightsType? RightsType { get; }
25
30 {
31 }
32
38 {
39 Roles = RightsHelper.RoleNames(requiredRights);
40 RightsType = Api.Rights.RightsType.Administration;
41 }
42
48 {
49 Roles = RightsHelper.RoleNames(requiredRights);
50 RightsType = Api.Rights.RightsType.InstanceManager;
51 }
52
58 {
59 Roles = RightsHelper.RoleNames(requiredRights);
60 RightsType = Api.Rights.RightsType.Repository;
61 }
62
67 public TgsAuthorizeAttribute(EngineRights requiredRights)
68 {
69 Roles = RightsHelper.RoleNames(requiredRights);
70 RightsType = Api.Rights.RightsType.Engine;
71 }
72
78 {
79 Roles = RightsHelper.RoleNames(requiredRights);
80 RightsType = Api.Rights.RightsType.DreamMaker;
81 }
82
88 {
89 Roles = RightsHelper.RoleNames(requiredRights);
90 RightsType = Api.Rights.RightsType.DreamDaemon;
91 }
92
97 public TgsAuthorizeAttribute(ChatBotRights requiredRights)
98 {
99 Roles = RightsHelper.RoleNames(requiredRights);
100 RightsType = Api.Rights.RightsType.ChatBots;
101 }
102
108 {
109 Roles = RightsHelper.RoleNames(requiredRights);
110 RightsType = Api.Rights.RightsType.Configuration;
111 }
112
118 {
119 Roles = RightsHelper.RoleNames(requiredRights);
120 RightsType = Api.Rights.RightsType.InstancePermissionSet;
121 }
122
124 public void OnAuthorization(AuthorizationFilterContext context)
125 {
126 var services = context.HttpContext.RequestServices;
127 var authenticationContext = services.GetRequiredService<IAuthenticationContext>();
128 var logger = services.GetRequiredService<ILogger<TgsAuthorizeAttribute>>();
129
130 if (!authenticationContext.Valid)
131 {
132 logger.LogTrace("authenticationContext is invalid!");
133 context.Result = new UnauthorizedResult();
134 return;
135 }
136
137 if (authenticationContext.User.Require(x => x.Enabled))
138 return;
139
140 logger.LogTrace("authenticationContext is for a disabled user!");
141 context.Result = new ForbidResult();
142 }
143 }
144}
Helper for using the AuthorizeAttribute with the Api.Rights system.
TgsAuthorizeAttribute(InstanceManagerRights requiredRights)
Initializes a new instance of the TgsAuthorizeAttribute class.
TgsAuthorizeAttribute(ChatBotRights requiredRights)
Initializes a new instance of the TgsAuthorizeAttribute class.
TgsAuthorizeAttribute(DreamDaemonRights requiredRights)
Initializes a new instance of the TgsAuthorizeAttribute class.
TgsAuthorizeAttribute(RepositoryRights requiredRights)
Initializes a new instance of the TgsAuthorizeAttribute class.
TgsAuthorizeAttribute(EngineRights requiredRights)
Initializes a new instance of the TgsAuthorizeAttribute class.
TgsAuthorizeAttribute(ConfigurationRights requiredRights)
Initializes a new instance of the TgsAuthorizeAttribute class.
TgsAuthorizeAttribute()
Initializes a new instance of the TgsAuthorizeAttribute class.
void OnAuthorization(AuthorizationFilterContext context)
TgsAuthorizeAttribute(AdministrationRights requiredRights)
Initializes a new instance of the TgsAuthorizeAttribute class.
TgsAuthorizeAttribute(InstancePermissionSetRights requiredRights)
Initializes a new instance of the TgsAuthorizeAttribute class.
TgsAuthorizeAttribute(DreamMakerRights requiredRights)
Initializes a new instance of the TgsAuthorizeAttribute class.
Represents the currently authenticated Models.User.
ChatBotRights
Rights for chat bots.
ConfigurationRights
Rights for Models.IConfigurationFiles.
DreamMakerRights
Rights for deployment.
RightsType
The type of rights a model uses.
Definition: RightsType.cs:7
EngineRights
Rights for engine version management.
Definition: EngineRights.cs:10
RepositoryRights
Rights for the git repository.
InstancePermissionSetRights
Rights for an Models.Instance.
DreamDaemonRights
Rights for managing DreamDaemon.
InstanceManagerRights
Rights for managing Models.Instances.
AdministrationRights
Administration rights for the server.