Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
LegalIdentityUser.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading.Tasks;
5using System.Xml;
7using Waher.Events;
11using Waher.Things;
12
14{
19 {
20 private readonly LegalComponent legalComponent;
21 private readonly LegalIdentity identity;
22 private readonly QuickLoginUser user;
23 private readonly XmppAddress from;
24
33 {
34 this.identity = Identity;
35 this.from = From;
36 this.legalComponent = LegalComponent;
37 this.user = User;
38 }
39
47 public static async Task<LegalIdentityUser> Create(LegalIdentity Identity, XmppAddress From, LegalComponent LegalComponent)
48 {
49 string Xml = null;
50
51 try
52 {
53 Dictionary<string, string> AttachmentUrls = new Dictionary<string, string>();
54 StringBuilder sb = new StringBuilder();
55 Identity.Serialize(sb, true, true, true, true, true, true, true, AttachmentUrls, LegalComponent);
56 XmlDocument Doc = new XmlDocument()
57 {
58 PreserveWhitespace = true
59 };
60
61 Doc.LoadXml(Xml = sb.ToString());
62
63 Networking.XMPP.Contracts.LegalIdentity Identity2 = Networking.XMPP.Contracts.LegalIdentity.Parse(Doc.DocumentElement);
64
65 LegalIdentityInfo IdentityInfo = await QuickLogin.PrepareQuickLoginIdentity(Identity2, "Session", true, null);
66 QuickLoginUser User = new QuickLoginUser(Identity2, string.Empty, IdentityInfo.Properties, IdentityInfo.Attachments);
67
69 }
70 catch (XmlException ex)
71 {
72 ex = XML.AnnotateException(ex, Xml);
73 Log.Exception(ex);
75 }
76 catch (Exception ex)
77 {
78 Log.Exception(ex);
80 }
81 }
82
86 public LegalIdentity Identity => this.identity;
87
91 public XmppAddress From => this.from;
92
96 public QuickLoginUser User => this.user;
97
101 public string UserName => this.identity.Id;
102
106 public string PasswordHash => throw new InvalidOperationException();
107
111 public string PasswordHashType => throw new InvalidOperationException();
112
118 public bool HasPrivilege(string Privilege)
119 {
120 if (Privilege.StartsWith("iotid:"))
121 return this.legalComponent.IsAccessToIdentityAuthorized(this.from.BareJid, Privilege.Substring(6));
122 else if (Privilege.StartsWith("iotsc:"))
123 return this.legalComponent.IsAccessToContractAuthorized(this.from.BareJid, Privilege.Substring(6));
124 else
125 return false;
126 }
127
132 public Task<RequestOrigin> GetOrigin()
133 {
134 return Task.FromResult(new RequestOrigin(this.from.BareJid, null, null, null));
135 }
136
142 public Task<IEnumerable<KeyValuePair<string, object>>> CreateClaims(bool Encrypted)
143 {
144 if (this.user is null)
145 return Task.FromResult<IEnumerable<KeyValuePair<string, object>>>(null);
146 else
147 return this.user.CreateClaims(Encrypted);
148 }
149
156 public Task<string> CreateToken(JwtFactory Factory, bool Encrypted)
157 {
158 if (this.user is null)
159 return Task.FromResult<string>(null);
160 else
161 return this.user.CreateToken(Factory, Encrypted);
162 }
163
164 }
165}
Helps with common XML-related tasks.
Definition: XML.cs:19
static XmlException AnnotateException(XmlException ex)
Creates a new XML Exception object, with reference to the source XML file, for information.
Definition: XML.cs:1588
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Definition: Log.cs:1647
Contains information about one XMPP address.
Definition: XmppAddress.cs:9
A factory that can create and validate JWT tokens.
Definition: JwtFactory.cs:53
Tokens available in request.
Definition: RequestOrigin.cs:9
A User that can participate in distributed operations, where the user is identified using a JWT token...
Interface for requestors that can act as an origin for distributed requests.