| | | 1 | | using Elsa.Authorization; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Permissions; |
| | | 4 | | using Elsa.ExternalAuthentication.Contracts; |
| | | 5 | | using Elsa.ExternalAuthentication.Models; |
| | | 6 | | using Elsa.ExternalAuthentication.Options; |
| | | 7 | | using Microsoft.Extensions.Options; |
| | | 8 | | |
| | | 9 | | namespace Elsa.ExternalAuthentication.Endpoints.Descriptors; |
| | | 10 | | |
| | | 11 | | /// <summary>Publishes only startup-installed, deployment-allowed extension metadata for generic management editors.</su |
| | | 12 | | internal sealed class ListAdapterDescriptors(IExternalAuthenticationAdapterRegistry registry, IOptions<ExternalAuthentic |
| | | 13 | | { |
| | | 14 | | public override void Configure() |
| | | 15 | | { |
| | | 16 | | Get("/external-authentication/descriptors/adapters"); |
| | | 17 | | RequirePermission(ExternalAuthentication.Permissions.ExternalAuthenticationResourcePermissions.Connections, Core |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | public override Task<IReadOnlyCollection<ExternalAuthenticationAdapterDescriptor>> ExecuteAsync(CancellationToken ca |
| | | 21 | | { |
| | | 22 | | var allowed = options.Value.AllowedAdapterTypes; |
| | | 23 | | IReadOnlyCollection<ExternalAuthenticationAdapterDescriptor> response = registry.ListDescriptors() |
| | | 24 | | .Where(x => allowed.Count == 0 || allowed.Contains(x.Type, StringComparer.Ordinal)) |
| | | 25 | | .OrderBy(x => x.Type, StringComparer.Ordinal) |
| | | 26 | | .ToArray(); |
| | | 27 | | return Task.FromResult(response); |
| | | 28 | | } |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | internal sealed class ListPolicyDescriptors(IUnlinkedIdentityPolicyRegistry registry) : ElsaEndpointWithoutRequest<IRead |
| | | 32 | | { |
| | | 33 | | public override void Configure() |
| | | 34 | | { |
| | | 35 | | Get("/external-authentication/descriptors/policies"); |
| | | 36 | | RequirePermission(ExternalAuthentication.Permissions.ExternalAuthenticationResourcePermissions.Connections, Core |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | public override Task<IReadOnlyCollection<UnlinkedIdentityPolicyDescriptor>> ExecuteAsync(CancellationToken cancellat |
| | | 40 | | { |
| | | 41 | | return Task.FromResult(registry.ListDescriptors()); |
| | | 42 | | } |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | internal sealed class ListPermissionSourceDescriptors(IPermissionGrantSourceRegistry registry) : ElsaEndpointWithoutRequ |
| | | 46 | | { |
| | | 47 | | public override void Configure() |
| | | 48 | | { |
| | | 49 | | Get("/external-authentication/descriptors/permission-sources"); |
| | | 50 | | RequirePermission(ExternalAuthentication.Permissions.ExternalAuthenticationResourcePermissions.Connections, Core |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | public override Task<IReadOnlyCollection<PermissionGrantSourceDescriptor>> ExecuteAsync(CancellationToken cancellati |
| | | 54 | | { |
| | | 55 | | return Task.FromResult(registry.ListDescriptors()); |
| | | 56 | | } |
| | | 57 | | } |
| | | 58 | | |
| | | 59 | | internal sealed class ListExternalUserMatcherDescriptors(IExternalUserMatcherRegistry registry) : ElsaEndpointWithoutReq |
| | | 60 | | { |
| | | 61 | | public override void Configure() |
| | | 62 | | { |
| | | 63 | | Get("/external-authentication/descriptors/user-matchers"); |
| | | 64 | | RequirePermission(ExternalAuthentication.Permissions.ExternalAuthenticationResourcePermissions.Connections, Core |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | public override Task<IReadOnlyCollection<ExternalUserMatcherDescriptor>> ExecuteAsync(CancellationToken cancellation |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | internal sealed record ManagedSecretResolverDescriptor(string Type, string DisplayName); |
| | 0 | 71 | | internal sealed record ManagedSecretResolverDescriptorResponse(IReadOnlyCollection<ManagedSecretResolverDescriptor> Item |
| | | 72 | | |
| | | 73 | | /// <summary>Lists installed managed secret writers without revealing any bound secret reference.</summary> |
| | | 74 | | internal sealed class ListManagedSecretResolverDescriptors(IEnumerable<IManagedSecretBindingWriter> writers) : ElsaEndpo |
| | | 75 | | { |
| | | 76 | | public override void Configure() |
| | | 77 | | { |
| | | 78 | | Get("/external-authentication/descriptors/managed-secret-resolvers"); |
| | | 79 | | RequirePermission(ExternalAuthentication.Permissions.ExternalAuthenticationResourcePermissions.Connections, Core |
| | | 80 | | } |
| | | 81 | | |
| | | 82 | | public override Task<ManagedSecretResolverDescriptorResponse> ExecuteAsync(CancellationToken cancellationToken) => T |
| | | 83 | | writers.Select(x => new ManagedSecretResolverDescriptor(x.ResolverType, x.DisplayName)).OrderBy(x => x.Type, Str |
| | | 84 | | } |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// Lists the permissions a claim mapping may be configured to confer. |
| | | 88 | | /// </summary> |
| | | 89 | | /// <remarks> |
| | | 90 | | /// This serves the core catalog rather than a registry private to this module. Choosing what an external |
| | | 91 | | /// mapping confers means choosing from everything Elsa declares, not just from this module's own resources, |
| | | 92 | | /// and the module's registry only ever held its legacy permission names anyway. |
| | | 93 | | /// </remarks> |
| | | 94 | | internal sealed class ListPermissionDescriptors(IPermissionDescriptorRegistry registry) : ElsaEndpointWithoutRequest<IRe |
| | | 95 | | { |
| | | 96 | | public override void Configure() |
| | | 97 | | { |
| | | 98 | | Get("/external-authentication/descriptors/permissions"); |
| | | 99 | | RequirePermission(ExternalAuthentication.Permissions.ExternalAuthenticationResourcePermissions.Connections, Core |
| | | 100 | | } |
| | | 101 | | |
| | | 102 | | public override Task<IReadOnlyCollection<PermissionDescriptor>> ExecuteAsync(CancellationToken cancellationToken) => |
| | | 103 | | } |