Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CustomPrivileges.cs
1using System;
2
4{
8 public class CustomPrivileges<T> : IAuthorization<T>
9 {
10 private readonly Func<T, string[]> calculatePrivileges;
16 public CustomPrivileges(Func<T, string[]> CalculatePrivileges)
17 {
18 if (CalculatePrivileges is null)
19 throw new ArgumentNullException(nameof(CalculatePrivileges));
20
21 this.calculatePrivileges = CalculatePrivileges;
22 }
23
30 public bool IsAuthorized(T Resource, IHasPrivileges User)
31 {
32 string[] Privileges = this.calculatePrivileges(Resource);
33 int i, c = Privileges.Length;
34
35 for (i = 0; i < c; i++)
36 {
37 if (!User.HasPrivilege(Privileges[i]))
38 return false;
39 }
40
41 return true;
42 }
43 }
44}
Authorization based on a custom privileges.
bool IsAuthorized(T Resource, IHasPrivileges User)
Checks if an user or object is authorized to perform an action.
CustomPrivileges(Func< T, string[]> CalculatePrivileges)
Authorization based on a custom privileges.
Basic authorization interface for objects of type T .
Interface for objects that have privileges.
bool HasPrivilege(string Privilege)
If the object has a given privilege.