Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AdminService.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
3using Waher.Events;
5using Waher.Script;
7
9{
14 {
15 private readonly HttpAuthenticationScheme[] authenticationSchemes;
16
22 public AdminService(string ResourceName, params HttpAuthenticationScheme[] AuthenticationSchemes)
23 : base(ResourceName)
24 {
25 this.authenticationSchemes = AuthenticationSchemes;
26 }
27
31 public override bool HandlesSubPaths => false;
32
36 public override bool UserSessions => true;
37
41 public bool AllowsPOST => true;
42
49 public async Task POST(HttpRequest Request, HttpResponse Response)
50 {
51 IUser User = null;
52
53 if (Request.Session is null ||
54 !Request.Session.TryGetVariable("User", out Variable v) ||
55 ((User = v.ValueObject as IUser) is null) ||
56 !User.HasPrivilege("Admin"))
57 {
58 throw ForbiddenException.AccessDenied(this.ResourceName, User?.UserName, "Admin");
59 }
60
61 object Obj = Request.HasData ? await Request.DecodeDataAsync() : null;
62 string s = Obj as string;
63 string Tab = Request.Header["X-TAB"];
64
65 if (string.IsNullOrEmpty(Tab))
66 throw new BadRequestException();
67
68 State State = new State(Request.Session, Tab, s, Request.RemoteEndPoint, User);
69 State.Start();
70 }
71
77 {
78 return this.authenticationSchemes;
79 }
80 }
81}
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
static ForbiddenException AccessDenied(string ObjectId, string ActorId, string MissingPrivilege)
Returns a ForbiddenException object, and logs a entry in the event log about the event.
Base class for all HTTP authentication schemes, as defined in RFC-7235: https://datatracker....
Represents an HTTP request.
Definition: HttpRequest.cs:18
HttpRequestHeader Header
Request header.
Definition: HttpRequest.cs:134
string RemoteEndPoint
Remote end-point.
Definition: HttpRequest.cs:195
Variables Session
Contains session states, if the resource requires sessions, or null otherwise.
Definition: HttpRequest.cs:164
async Task< object > DecodeDataAsync()
Decodes data sent in request.
Definition: HttpRequest.cs:95
string ResourceName
Name of resource.
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:21
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
Contains information about a variable.
Definition: Variable.cs:10
virtual bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
Definition: Variables.cs:52
Web service that can be used to execute script on the server.
Definition: AdminService.cs:14
override bool HandlesSubPaths
If the resource handles sub-paths.
Definition: AdminService.cs:31
AdminService(string ResourceName, params HttpAuthenticationScheme[] AuthenticationSchemes)
Web service that can be used to execute script on the server.
Definition: AdminService.cs:22
override HttpAuthenticationScheme[] GetAuthenticationSchemes(HttpRequest Request)
Any authentication schemes used to authenticate users before access is granted to the corresponding r...
Definition: AdminService.cs:76
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
Definition: AdminService.cs:49
override bool UserSessions
If the resource uses user sessions.
Definition: AdminService.cs:36
bool AllowsPOST
If the POST method is allowed.
Definition: AdminService.cs:41
POST Interface for HTTP resources.
Basic interface for a user.
Definition: IUser.cs:7
bool HasPrivilege(string Privilege)
If the user has a given privilege.