| | | 1 | | using System.Collections.Concurrent; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Authorization; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Records the permission each endpoint declares, keyed by endpoint type. |
| | | 7 | | /// </summary> |
| | | 8 | | /// <remarks> |
| | | 9 | | /// The requirement itself is attached as an inline authorization policy, which is not readable back from |
| | | 10 | | /// the endpoint definition. Recording it here keeps the declaration introspectable: it is what lets a |
| | | 11 | | /// deployment answer "what does this endpoint require" without reading source, and it gives tests a way to |
| | | 12 | | /// assert a specific requirement rather than merely that one exists. |
| | | 13 | | /// </remarks> |
| | | 14 | | public static class EndpointPermissionRegistry |
| | | 15 | | { |
| | 1 | 16 | | private static readonly ConcurrentDictionary<Type, Permission> Declared = new(); |
| | | 17 | | |
| | | 18 | | /// <summary>Records that <paramref name="endpointType"/> requires <paramref name="permission"/>.</summary> |
| | 312 | 19 | | public static void Record(Type endpointType, Permission permission) => Declared[endpointType] = permission; |
| | | 20 | | |
| | | 21 | | /// <summary>The permission <paramref name="endpointType"/> declares, if it declares one.</summary> |
| | 0 | 22 | | public static Permission? Find(Type endpointType) => Declared.TryGetValue(endpointType, out var permission) ? permis |
| | | 23 | | |
| | | 24 | | /// <summary>Every recorded declaration.</summary> |
| | 0 | 25 | | public static IReadOnlyDictionary<Type, Permission> All => Declared; |
| | | 26 | | } |