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.Threading.Tasks;
2using Waher.Content;
4using Waher.Script;
6
8{
13 {
14 private readonly HttpAuthenticationScheme[] authenticationSchemes;
15
21 public AdminService(string ResourceName, params HttpAuthenticationScheme[] AuthenticationSchemes)
22 : base(ResourceName)
23 {
24 this.authenticationSchemes = AuthenticationSchemes;
25 }
26
30 public override bool HandlesSubPaths => false;
31
35 public override bool UserSessions => true;
36
40 public bool AllowsPOST => true;
41
48 public async Task POST(HttpRequest Request, HttpResponse Response)
49 {
50 IUser User = null;
51
52 if (Request.Session is null ||
53 !Request.Session.TryGetVariable("User", out Variable v) ||
54 ((User = v.ValueObject as IUser) is null) ||
55 !User.HasPrivilege("Admin"))
56 {
57 await Response.SendResponse(ForbiddenException.AccessDenied(this.ResourceName, User?.UserName, "Admin"));
58 return;
59 }
60
61 object Obj;
62
63 if (Request.HasData)
64 {
65 ContentResponse Content = await Request.DecodeDataAsync();
66
67 if (Content.HasError)
68 {
69 await Response.SendResponse(Content.Error);
70 return;
71 }
72
73 Obj = Content.Decoded;
74 }
75 else
76 Obj = null;
77
78 string s = Obj as string;
79 string Tab = Request.Header["X-TAB"];
80
81 if (string.IsNullOrEmpty(Tab))
82 {
83 await Response.SendResponse(new BadRequestException());
84 return;
85 }
86
87 State State = new State(Request.Session, Tab, s, Request.RemoteEndPoint, User);
88 State.Start();
89 }
90
99 {
100 return this.authenticationSchemes;
101 }
102 }
103}
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Exception Error
Error response.
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)
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:22
HttpRequestHeader Header
Request header.
Definition: HttpRequest.cs:182
string RemoteEndPoint
Remote end-point.
Definition: HttpRequest.cs:243
bool HasData
If the request has data.
Definition: HttpRequest.cs:113
SessionVariables Session
Contains session states, if the resource requires sessions, or null otherwise.
Definition: HttpRequest.cs:212
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
Definition: HttpRequest.cs:139
string ResourceName
Name of resource.
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:23
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
override bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
Contains information about a variable.
Definition: Variable.cs:10
Web service that can be used to execute script on the server.
Definition: AdminService.cs:13
override bool HandlesSubPaths
If the resource handles sub-paths.
Definition: AdminService.cs:30
AdminService(string ResourceName, params HttpAuthenticationScheme[] AuthenticationSchemes)
Web service that can be used to execute script on the server.
Definition: AdminService.cs:21
override HttpAuthenticationScheme[] GetAuthenticationSchemes(HttpRequest Request)
Any authentication schemes used to authenticate users before access is granted to the corresponding r...
Definition: AdminService.cs:98
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
Definition: AdminService.cs:48
override bool UserSessions
If the resource uses user sessions.
Definition: AdminService.cs:35
bool AllowsPOST
If the POST method is allowed.
Definition: AdminService.cs:40
POST Interface for HTTP resources.
bool HasPrivilege(string Privilege)
If the object has a given privilege.
Basic interface for a user.
Definition: IUser.cs:7
string UserName
User Name.
Definition: IUser.cs:12