Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ApiKey.cs
1using System;
2using System.Text.RegularExpressions;
7
9{
10 [CollectionName("ApiKeys")]
11 [TypeName(TypeNameSerialization.None)]
12 [ArchivingTime]
13 [Index("Key")]
14 [Index("Owner", "Key")]
15 public class ApiKey
16 {
17 internal static readonly Regex UnitTests = new Regex(@"Waher[.]Service[.]IoTBroker[.]Test[.](LegalIdentitiesTests|SmartContractsTests|AgentTests)",
18 RegexOptions.Compiled | RegexOptions.Singleline);
19 private static readonly ICallStackCheck[] approvedSources = Assert.Convert(new object[]
20 {
21 typeof(XmppServerModule).Assembly,
22 typeof(Persistence.NeuroLedger.NeuroLedgerProvider).Assembly,
23 typeof(NeuroLedger.NeuroLedgerModule).Assembly,
24 typeof(Content.Markdown.Web.MarkdownToHtmlConverter),
25 typeof(Content.Markdown.Web.WebScript.WsToX),
26 typeof(Content.Markdown.MarkdownDocument),
27 Account.FromSaveUnsaved,
28 Account.FromUpdateObject
29 });
30 private static readonly ICallStackCheck[] approvedSourcesTest = Assert.Convert(new object[]
31 {
32 typeof(XmppServerModule).Assembly,
33 typeof(Persistence.NeuroLedger.NeuroLedgerProvider).Assembly,
34 typeof(NeuroLedger.NeuroLedgerModule).Assembly,
35 typeof(Content.Markdown.Web.MarkdownToHtmlConverter),
36 typeof(Content.Markdown.Web.WebScript.WsToX),
37 typeof(Content.Markdown.MarkdownDocument),
38 Account.FromSaveUnsaved,
39 Account.FromUpdateObject,
40 "System.Threading.PortableThreadPool+WorkerThread",
41 UnitTests
42 });
43
44 private string objectId = null;
45 private string key = string.Empty;
46 private string secret = string.Empty;
47 private string owner = string.Empty;
49 private DateTime created = DateTime.MinValue;
50 private DateTime firstAccount = DateTime.MinValue;
51 private DateTime lastAccount = DateTime.MinValue;
52 private long maxAccounts = 0;
53 private long nrCreated = 0;
54 private long nrDeleted = 0;
55
56 public ApiKey()
57 {
58 }
59
60 [ObjectId]
61 public string ObjectId
62 {
63 get => this.objectId;
64 set => this.objectId = value;
65 }
66
67 public string Key
68 {
69 get => this.key;
70 set => this.key = value;
71 }
72
73 [DefaultValueStringEmpty]
74 public string Secret
75 {
76 get
77 {
78 Assert.CallFromSource((DomainConfiguration.Instance?.UseDomainName ?? false) ? approvedSources : approvedSourcesTest);
79 return this.secret;
80 }
81
82 set
83 {
84 if (!string.IsNullOrEmpty(this.secret))
85 Assert.CallFromSource((DomainConfiguration.Instance?.UseDomainName ?? false) ? approvedSources : approvedSourcesTest);
86
87 this.secret = value;
88 }
89 }
90
91 public string Owner
92 {
93 get => this.owner;
94 set => this.owner = value;
95 }
96
97 [DefaultValueStringEmpty]
98 public CaseInsensitiveString EMail
99 {
100 get => this.eMail;
101 set => this.eMail = value;
102 }
103
104 [DefaultValueDateTimeMinValue]
105 public DateTime Created
106 {
107 get => this.created;
108 set => this.created = value;
109 }
110
111 [DefaultValueDateTimeMinValue]
112 public DateTime FirstAccount
113 {
114 get => this.firstAccount;
115 set => this.firstAccount = value;
116 }
117
118 [DefaultValueDateTimeMinValue]
119 public DateTime LastAccount
120 {
121 get => this.lastAccount;
122 set => this.lastAccount = value;
123 }
124
125 [DefaultValue(0L)]
126 public long MaxAccounts
127 {
128 get => this.maxAccounts;
129 set => this.maxAccounts = value;
130 }
131
132 [DefaultValue(0L)]
133 public long NrCreated
134 {
135 get => this.nrCreated;
136 set => this.nrCreated = value;
137 }
138
139 [DefaultValue(0L)]
140 public long NrDeleted
141 {
142 get => this.nrDeleted;
143 set => this.nrDeleted = value;
144 }
145 }
146}
static DomainConfiguration Instance
Current instance of configuration.
bool UseDomainName
If the server uses a domain name.
Represents a case-insensitive string.
static readonly CaseInsensitiveString Empty
Empty case-insensitive string
Static class containing methods that can be used to make sure calls are made from appropriate locatio...
Definition: Assert.cs:15
static ICallStackCheck[] Convert(params object[] Sources)
Converts an array of objects into an array of ICallStackCheck objects, assuming each listed source is...
Definition: Assert.cs:99
static void CallFromSource(params string[] Sources)
Makes sure the call is made from one of the listed sources.
Definition: Assert.cs:54
Contains information about a broker account.
Definition: Account.cs:41
Service Module hosting the XMPP broker and its components.
Interface for call stack checks.
TypeNameSerialization
How the type name should be serialized.