Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ReadyForApproval.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
11using Waher.Script;
16
18{
23 {
28 : base("Legal/ReadyForApproval",
29 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
30 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
31 {
32 }
33
34 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(ReadyForApproval).Namespace + ".JSON.ReadyForApproval.req");
35 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(ReadyForApproval).Namespace + ".XML.ReadyForApproval.req");
36
45 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
46 {
48 CaseInsensitiveString LegalId = (string)Parameters["PLegalId"].AssociatedObjectValue;
49 int i = LegalId.IndexOf('@');
50 if (i < 0)
51 throw new BadRequestException("Invalid Legal ID.");
52
53 using (Semaphore Semaphore = await Semaphores.BeginRead("iotid:" + LegalId.LowerCase))
54 {
55 LegalIdentity Identity = await LegalComponent.GetLocalLegalIdentity(LegalId)
56 ?? throw new NotFoundException("Legal identity not found.");
57
58 if (Identity.Account != User.UserName)
59 throw new ForbiddenException("Only allowed to ready your own legal identities.");
60
61 if (Identity.State != IdentityState.Created)
62 throw new ForbiddenException("Identity must be in a Created state.");
63
64 IAccount Account = await XmppServerModule.GetAccountAsync(Identity.Account)
65 ?? throw new ForbiddenException("Account has been removed.");
66
67 if (!Account.Enabled)
68 throw new ForbiddenException("Account has been disabled.");
69
70 XmppServerModule.Legal?.CheckAuthenticityOfIdentity(Identity, Identity.GetTags(),
72 Account as DataStorage.Account);
73
74 await Response.Return(new NamedDictionary<string, object>("AckResponse", AgentNamespace));
75 }
76 }
77
78 }
79}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:15
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Definition: Resources.cs:96
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:126
static CaseInsensitiveString Domain
Domain name.
Definition: Gateway.cs:2354
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...
Represents an HTTP request.
Definition: HttpRequest.cs:18
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:21
async Task Return(object Object)
Returns an object to the client. This method can only be called once per response,...
The server has not found anything matching the Request-URI. No indication is given of whether the con...
XmppAddress MainDomain
Main/principal domain address
Definition: Component.cs:86
Contains information about one XMPP address.
Definition: XmppAddress.cs:9
Represents a case-insensitive string.
string LowerCase
Lower-case representation of the case-insensitive string.
int IndexOf(CaseInsensitiveString value, StringComparison comparisonType)
Reports the zero-based index of the first occurrence of the specified string in the current System....
Represents a named semaphore, i.e. an object, identified by a name, that allows single concurrent wri...
Definition: Semaphore.cs:19
Static class of application-wide semaphores that can be used to order access to editable objects.
Definition: Semaphores.cs:16
static async Task< Semaphore > BeginRead(string Key)
Waits until the semaphore identified by Key is ready for reading. Each call to BeginRead must be fol...
Definition: Semaphores.cs:53
Class managing a script expression.
Definition: Expression.cs:39
Contains information about a broker account.
Definition: Account.cs:28
bool Enabled
If account is enabled
Definition: Account.cs:287
Account()
Contains information about a broker account.
Definition: Account.cs:72
Abstract base class for agent resources supporting the POST method.
static AccountUser AssertUserAuthenticated(HttpRequest Request)
Makes sure the request is made by an authenticated API user.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd
Service Module hosting the XMPP broker and its components.
Interface for XMPP user accounts.
Definition: IAccount.cs:9