2using System.Collections.Generic;
4using System.Threading.Tasks;
28 public const string AgentNamespace =
"https://waher.se/Schema/BrokerAgent.xsd";
30 private readonly Dictionary<Type, Expression> patternMatches;
39 params KeyValuePair<Type, Expression>[] PatternMatches)
40 : base(
"/Agent/" + AgentResourceName)
42 this.patternMatches =
new Dictionary<Type, Expression>();
44 foreach (KeyValuePair<Type, Expression> P
in PatternMatches)
45 this.patternMatches[P.Key] = P.Value;
57 return Task.CompletedTask;
67 return Task.CompletedTask;
87 if (this.authenticationSchemes is
null)
95 List<HttpAuthenticationScheme> Schemes =
new List<HttpAuthenticationScheme>();
100 return Schemes.ToArray();
102 this.authenticationSchemes = Schemes.ToArray();
105 return this.authenticationSchemes;
115 bool RequireEncryption = !(DomainConfiguration.Instance is
null) &&
118 int MinStrength = RequireEncryption ? 128 : 0;
134 private static Accounts accounts =
null;
165 set => factory = value;
185 Type T = Decoded.GetType();
187 if (!this.patternMatches.TryGetValue(T, out
Expression Pattern))
191 Dictionary<string, IElement> Matches =
new Dictionary<string, IElement>();
193 switch (Pattern.Root.PatternMatch(E, Matches))
229 if (MustBeEnabled && !User.Account.Enabled)
256 if (MustBeEnabled && !User.Account.Enabled)
270 DateTime? Next = await this.api.
Auditor.GetEarliestLoginOpportunity(Request.
RemoteEndPoint,
"HTTPS");
274 DateTime TP = Next.Value;
275 DateTime Today = DateTime.Today;
276 StringBuilder sb =
new StringBuilder();
278 if (Next.Value == DateTime.MaxValue)
280 sb.Append(
"This endpoint (");
282 sb.Append(
") has been blocked from the system.");
286 sb.Append(
"Too many failed login attempts in a row registered. Try again after ");
287 sb.Append(TP.ToLongTimeString());
289 if (TP.Date != Today)
291 if (TP.Date == Today.AddDays(1))
292 sb.Append(
" tomorrow");
296 sb.Append(TP.ToShortDateString());
300 sb.Append(
". Remote Endpoint: ");
319 if (ex is Networking.XMPP.StanzaErrors.BadRequestException)
321 else if (ex is Networking.XMPP.StanzaErrors.ConflictException)
323 else if (ex is Networking.XMPP.StanzaErrors.ForbiddenException)
325 else if (ex is Networking.XMPP.StanzaErrors.FeatureNotImplementedException)
326 return new Networking.HTTP.NotImplementedException(ex.Message);
327 else if (ex is Networking.XMPP.StanzaErrors.GoneException)
329 else if (ex is Networking.XMPP.StanzaErrors.InternalServerErrorException)
331 else if (ex is Networking.XMPP.StanzaErrors.ItemNotFoundException)
333 else if (ex is Networking.XMPP.StanzaErrors.NotAllowedException)
335 else if (ex is Networking.XMPP.StanzaErrors.ResourceConstraintException)
337 else if (ex is Networking.XMPP.StanzaErrors.ServiceUnavailableException)
339 else if (ex is Networking.XMPP.StanzaErrors.NotAuthorizedException)
Static class managing the runtime environment of the IoT Gateway.
static CaseInsensitiveString Domain
Domain name.
static HttpServer HttpServer
HTTP Server
static DomainConfiguration Instance
Current instance of configuration.
bool UseEncryption
If the server uses server-side encryption.
string Domain
Principal domain name
Basic authentication mechanism, as defined in RFC 2617: https://tools.ietf.org/html/rfc2617
Digest authentication mechanism, as defined in RFC 2617: https://tools.ietf.org/html/rfc2617
mTLS authentication mechanism, where identity is taken from a valid client certificate.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
The request could not be completed due to a conflict with the current state of the resource....
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
The requested resource is no longer available at the server and no forwarding address is known....
Base class for all HTTP authentication schemes, as defined in RFC-7235: https://datatracker....
Represents an HTTP request.
string RemoteEndPoint
Remote end-point.
bool HasData
If the request has data.
IUser User
Authenticated user, if available, or null if not available.
async Task< object > DecodeDataAsync()
Decodes data sent in request.
Implements an HTTP server.
HttpResource Register(HttpResource Resource)
Registers a resource with the server.
bool Unregister(HttpResource Resource)
Unregisters a resource from the server.
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The server encountered an unexpected condition which prevented it from fulfilling the request.
The server has not found anything matching the Request-URI. No indication is given of whether the con...
The client needs to authenticate to gain network access. Intended for use by intercepting proxies use...
The server has not found anything matching the Request-URI. No indication is given of whether the con...
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
The user has sent too many requests in a given amount of time. Intended for use with rate limiting sc...
Base class of XMPP exceptions
Static class that dynamically manages types and interfaces available in the runtime environment.
static bool TryGetModuleParameter(string Name, out object Value)
Tries to get a module parameter value.
Class managing a script expression.
static IElement Encapsulate(object Value)
Encapsulates an object.
Use JWT tokens for authentication. The Bearer scheme defined in RFC 6750 is used: https://tools....
A factory that can create and validate JWT tokens.
bool Disposed
If the factory has been disposed.
static JwtFactory CreateHmacSha256()
Creates a JWT factory that can create and validate JWT tokens using the HMAC-SHA256 algorithm.
Collection of broker accounts
LoginAuditor Auditor
Login auditor
Abstract base class for agent resources
Task Register(HttpServer WebServer, AgentApi AgentApi)
Registers the resource on a web server.
static Accounts Accounts
Reference to available accounts.
Task Unregister(HttpServer WebServer)
Unregisters the resource from a web server.
static AccountUser AssertUserAuthenticated(HttpRequest Request)
Makes sure the request is made by an authenticated API user.
AgentApi Api
Reference to Agent API.
override bool UserSessions
If the resource uses user sessions.
override HttpAuthenticationScheme[] GetAuthenticationSchemes(HttpRequest Request)
Any authentication schemes used to authenticate users before access is granted to the corresponding r...
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd
static Exception ToHttpException(XmppException ex)
Tries to convert an XMPP Exception to an HTTP Exception.
async Task< Dictionary< string, IElement > > AssertMatch(HttpRequest Request)
Checks if content matches specification in resource.
static AccountUser GetAuthenticatedUser(HttpRequest Request, bool MustBeEnabled)
Gets the authenticated user object, if one exists.
virtual void AddAuthenticationSchemes(Accounts Accounts, List< HttpAuthenticationScheme > Schemes)
Adds authentication schemes to the resource.
override bool HandlesSubPaths
If the resource handles sub-paths.
static AccountUser AssertUserAuthenticated(HttpRequest Request, bool MustBeEnabled)
Makes sure the request is made by an authenticated API user.
static AccountUser GetAuthenticatedUser(HttpRequest Request)
Gets the authenticated user object, if one exists.
AgentResource(string AgentResourceName, params KeyValuePair< Type, Expression >[] PatternMatches)
Abstract base class for agent resources
async Task CheckBlocks(HttpRequest Request)
Checks if the client is blocked.
Service Module hosting the XMPP broker and its components.
Basic interface for all types of elements.
Interface for agent resources.
DigestAlgorithm
Digest algorithm
ClientCertificates
Client Certificate Options
PatternMatchResult
Status result of a pattern matching operation.