-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathRequestOrigin.cs
More file actions
83 lines (73 loc) · 2.23 KB
/
RequestOrigin.cs
File metadata and controls
83 lines (73 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Threading.Tasks;
namespace Waher.Things
{
/// <summary>
/// Tokens available in request.
/// </summary>
public class RequestOrigin : IRequestOrigin
{
/// <summary>
/// Empty request origin.
/// </summary>
public static readonly RequestOrigin Empty = new RequestOrigin(string.Empty,
null, null, null, null);
private readonly IRequestOrigin authority;
private readonly string[] deviceTokens;
private readonly string[] serviceTokens;
private readonly string[] userTokens;
private readonly string from;
/// <summary>
/// Tokens available in request.
/// </summary>
/// <param name="From">Address of caller.</param>
/// <param name="DeviceTokens">Device tokens, or null.</param>
/// <param name="ServiceTokens">Service tokens, or null.</param>
/// <param name="UserTokens">User tokens, or null.</param>
/// <param name="Authority">Optional authority for privilege authorization.</param>
public RequestOrigin(string From, string[] DeviceTokens, string[] ServiceTokens, string[] UserTokens,
IRequestOrigin Authority)
{
this.from = From;
this.deviceTokens = DeviceTokens;
this.serviceTokens = ServiceTokens;
this.userTokens = UserTokens;
this.authority = Authority;
}
/// <summary>
/// Address of caller.
/// </summary>
public string From => this.from;
/// <summary>
/// Device tokens, or null.
/// </summary>
public string[] DeviceTokens => this.deviceTokens;
/// <summary>
/// Service tokens, or null.
/// </summary>
public string[] ServiceTokens => this.serviceTokens;
/// <summary>
/// User tokens, or null.
/// </summary>
public string[] UserTokens => this.userTokens;
/// <summary>
/// Optional authority for privilege authorization
/// </summary>
public IRequestOrigin Authority => this.authority;
/// <summary>
/// Origin of request.
/// </summary>
public Task<RequestOrigin> GetOrigin()
{
return Task.FromResult(this);
}
/// <summary>
/// If the origin has a given privilege.
/// </summary>
/// <param name="Privilege">Privilege.</param>
/// <returns>If the origin has the corresponding privilege.</returns>
public bool HasPrivilege(string Privilege)
{
return this.authority?.HasPrivilege(Privilege) ?? false;
}
}
}