| | | 1 | | using Syki.Shared.Auth; |
| | | 2 | | |
| | | 3 | | namespace Syki.Back.Auth; |
| | | 4 | | |
| | | 5 | | public static partial class Policies |
| | | 6 | | { |
| | 2 | 7 | | public static List<PolicyMetadata> Adm = []; |
| | | 8 | | |
| | | 9 | | public const string GetUsers = nameof(GetUsers); |
| | | 10 | | public const string CreateUser = nameof(CreateUser); |
| | | 11 | | |
| | | 12 | | public const string GetRoles = nameof(GetRoles); |
| | | 13 | | public const string CreateRole = nameof(CreateRole); |
| | | 14 | | public const string UpdateRole = nameof(UpdateRole); |
| | | 15 | | public const string GetFeatures = nameof(GetFeatures); |
| | | 16 | | public const string GetPolicies = nameof(GetPolicies); |
| | | 17 | | |
| | | 18 | | public const string GetDomainEvents = nameof(GetDomainEvents); |
| | | 19 | | public const string GetDomainEvent = nameof(GetDomainEvent); |
| | | 20 | | |
| | | 21 | | public const string GetCommands = nameof(GetCommands); |
| | | 22 | | public const string GetCommand = nameof(GetCommand); |
| | | 23 | | public const string ReprocessCommand = nameof(ReprocessCommand); |
| | | 24 | | |
| | | 25 | | public const string GetCommandBatches = nameof(GetCommandBatches); |
| | | 26 | | public const string GetCommandBatch = nameof(GetCommandBatch); |
| | | 27 | | public const string GetCommandBatchCommands = nameof(GetCommandBatchCommands); |
| | | 28 | | |
| | | 29 | | public const string GetAuditTrails = nameof(GetAuditTrails); |
| | | 30 | | public const string GetAuditTrail = nameof(GetAuditTrail); |
| | | 31 | | public const string GetAuditTrailOperations = nameof(GetAuditTrailOperations); |
| | | 32 | | |
| | | 33 | | public static AuthorizationBuilder AddAdmPolicy(this AuthorizationBuilder builder, string name, params SykiFeature[] |
| | | 34 | | { |
| | 36 | 35 | | Adm.Add(new() { Name = name, Features = features.ToList() }); |
| | | 36 | | |
| | 72 | 37 | | var ids = features.Select(x => x.Id).ToList(); |
| | | 38 | | |
| | 72 | 39 | | return builder.AddPolicy(name, policy => policy |
| | 72 | 40 | | .RequireAuthenticatedUser() |
| | 0 | 41 | | .RequireAssertion(x => x.User.Features.Any(f => ids.Contains(f))) |
| | 72 | 42 | | .AddAuthenticationSchemes(AuthenticationConfigs.BearerScheme)); |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | public static AuthorizationBuilder AddAdmPolicies(this AuthorizationBuilder builder) |
| | | 46 | | { |
| | 2 | 47 | | builder |
| | 2 | 48 | | .AddAdmPolicy(GetUsers, FeaturesStore.ViewUsers) |
| | 2 | 49 | | .AddAdmPolicy(CreateUser, FeaturesStore.CreateUser); |
| | | 50 | | |
| | 2 | 51 | | builder |
| | 2 | 52 | | .AddAdmPolicy(GetRoles, FeaturesStore.ViewRoles) |
| | 2 | 53 | | .AddAdmPolicy(CreateRole, FeaturesStore.CreateRole) |
| | 2 | 54 | | .AddAdmPolicy(UpdateRole, FeaturesStore.UpdateRole) |
| | 2 | 55 | | .AddAdmPolicy(GetFeatures, FeaturesStore.ViewFeatures) |
| | 2 | 56 | | .AddAdmPolicy(GetPolicies, FeaturesStore.ViewPolicies); |
| | | 57 | | |
| | 2 | 58 | | builder |
| | 2 | 59 | | .AddAdmPolicy(GetDomainEvents, FeaturesStore.ViewDomainEvents) |
| | 2 | 60 | | .AddAdmPolicy(GetDomainEvent, FeaturesStore.ViewDomainEventDetails) |
| | 2 | 61 | | .AddAdmPolicy(GetCommands, FeaturesStore.ViewCommands) |
| | 2 | 62 | | .AddAdmPolicy(GetCommand, FeaturesStore.ViewCommandDetails) |
| | 2 | 63 | | .AddAdmPolicy(ReprocessCommand, FeaturesStore.ReprocessCommand) |
| | 2 | 64 | | .AddAdmPolicy(GetCommandBatches, FeaturesStore.ViewCommandBatches) |
| | 2 | 65 | | .AddAdmPolicy(GetCommandBatch, FeaturesStore.ViewCommandBatchDetails) |
| | 2 | 66 | | .AddAdmPolicy(GetCommandBatchCommands, FeaturesStore.ViewCommandBatchDetails); |
| | | 67 | | |
| | 2 | 68 | | builder |
| | 2 | 69 | | .AddAdmPolicy(GetAuditTrails, FeaturesStore.ViewAuditTrails) |
| | 2 | 70 | | .AddAdmPolicy(GetAuditTrail, FeaturesStore.ViewAuditTrailDetails) |
| | 2 | 71 | | .AddAdmPolicy(GetAuditTrailOperations, FeaturesStore.ViewAuditTrails); |
| | | 72 | | |
| | 2 | 73 | | return builder; |
| | | 74 | | } |
| | | 75 | | } |