4using System.Threading.Tasks;
31 public const string AgentNamespace =
"https://waher.se/Schema/BrokerAgent.xsd";
33 private readonly Dictionary<Type, Expression> patternMatches;
42 params KeyValuePair<Type, Expression>[] PatternMatches)
43 : base(
"/Agent/" + AgentResourceName)
45 this.patternMatches =
new Dictionary<Type, Expression>();
47 foreach (KeyValuePair<Type, Expression> P
in PatternMatches)
48 this.patternMatches[P.Key] = P.Value;
60 return Task.CompletedTask;
70 return Task.CompletedTask;
102 if (this.authenticationSchemes is
null)
104 if (accounts is
null)
113 return this.authenticationSchemes;
141 bool RequireEncryption = !(DomainConfiguration.Instance is
null) &&
144 int MinStrength = RequireEncryption ? 128 : 0;
160 private static Accounts accounts =
null;
197 set => factory = value;
230 Type T = Content.
Decoded.GetType();
232 if (!this.patternMatches.TryGetValue(T, out
Expression Pattern))
239 Dictionary<string, IElement> Matches =
new Dictionary<string, IElement>();
274 if (MustBeEnabled && !User.Account.Enabled)
301 if (MustBeEnabled && !User.Account.Enabled)
315 DateTime? Next = await this.api.
Auditor.GetEarliestLoginOpportunity(Request.
RemoteEndPoint,
"HTTPS");
319 DateTime TP = Next.Value;
320 DateTime Today = DateTime.Today;
321 StringBuilder sb =
new StringBuilder();
323 if (Next.Value == DateTime.MaxValue)
325 sb.Append(
"This endpoint (");
327 sb.Append(
") has been blocked from the system.");
331 sb.Append(
"Too many failed login attempts in a row registered. Try again after ");
332 sb.Append(TP.ToLongTimeString());
334 if (TP.Date != Today)
336 if (TP.Date == Today.AddDays(1))
337 sb.Append(
" tomorrow");
341 sb.Append(TP.ToShortDateString());
345 sb.Append(
". Remote Endpoint: ");
365 if (ex is Networking.XMPP.StanzaErrors.BadRequestException)
367 else if (ex is Networking.XMPP.StanzaErrors.ConflictException)
369 else if (ex is Networking.XMPP.StanzaErrors.ForbiddenException)
371 else if (ex is Networking.XMPP.StanzaErrors.FeatureNotImplementedException)
372 return new Networking.HTTP.NotImplementedException(ex.Message);
373 else if (ex is Networking.XMPP.StanzaErrors.GoneException)
375 else if (ex is Networking.XMPP.StanzaErrors.InternalServerErrorException)
377 else if (ex is Networking.XMPP.StanzaErrors.ItemNotFoundException)
379 else if (ex is Networking.XMPP.StanzaErrors.NotAllowedException)
381 else if (ex is Networking.XMPP.StanzaErrors.ResourceConstraintException)
383 else if (ex is Networking.XMPP.StanzaErrors.ServiceUnavailableException)
385 else if (ex is Networking.XMPP.StanzaErrors.NotAuthorizedException)
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Exception Error
Error response.
Static class managing the runtime environment of the IoT Gateway.
static CaseInsensitiveString Domain
Domain name.
static HttpServer HttpServer
HTTP Server
static bool HasDomain
If a domain name is configured.
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< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
Represets a response of an HTTP client request.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
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
A chunked list is a linked list of chunks of objects of type T .
void Add(T Item)
Adds an item to the collection.
T[] ToArray()
Returns an array containing all elements of the collection.
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
async Task< Dictionary< string, IElement > > CheckInput(HttpRequest Request, HttpResponse Response)
Checks if content matches specification in resource.
Task Register(HttpServer WebServer, AgentApi AgentApi)
Registers the resource on a web server.
static Accounts Accounts
Reference to available accounts.
static JwtFactory Factory
JWT Factory
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
HttpAuthenticationScheme[] CreateAuthenticationSchemes(IUserSource Users)
Creates a set of authentication schemes for the resource.
virtual void AddAuthenticationSchemes(IUserSource Users, ChunkedList< HttpAuthenticationScheme > Schemes)
Adds authentication schemes to the resource.
static AccountUser GetAuthenticatedUser(HttpRequest Request, bool MustBeEnabled)
Gets the authenticated user object, if one exists.
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
HttpAuthenticationScheme[] AuthenticationSchemes
Array of authentication schemes used for the resource.
async Task CheckBlocks(HttpRequest Request)
Checks if the client is blocked.
static Exception ToHttpException(HttpRequest Request, XmppException ex)
Tries to convert an XMPP Exception to an HTTP Exception.
Service Module hosting the XMPP broker and its components.
Basic interface for all types of elements.
Interface for data sources containing users.
Interface for agent resources.
DigestAlgorithm
Digest algorithm
ClientCertificates
Client Certificate Options
PatternMatchResult
Status result of a pattern matching operation.