| | | 1 | | using CShells.Features; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | using Elsa.Identity.HostedServices; |
| | | 4 | | using Elsa.Identity.Options; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | using Microsoft.Extensions.DependencyInjection; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Identity.ShellFeatures; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Feature that initializes an admin user from configuration if provided. |
| | | 12 | | /// </summary> |
| | | 13 | | [ShellFeature( |
| | | 14 | | DisplayName = "Default Admin User Initialization", |
| | | 15 | | Description = "Initializes a default admin user from configuration if provided", |
| | | 16 | | DependsOn = ["Identity"])] |
| | | 17 | | [UsedImplicitly] |
| | | 18 | | public class DefaultAdminUserFeature : IShellFeature |
| | | 19 | | { |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets or sets the admin user name. Must be explicitly configured to enable user bootstrap. |
| | | 22 | | /// </summary> |
| | 0 | 23 | | public string AdminUserName { get; set; } = ""; |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Gets or sets the admin user password. Must be explicitly configured to enable user bootstrap. |
| | | 27 | | /// </summary> |
| | 0 | 28 | | public string AdminPassword { get; set; } = ""; |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets or sets the admin role name. |
| | | 32 | | /// </summary> |
| | 0 | 33 | | public string AdminRoleName { get; set; } = "admin"; |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Gets or sets the admin role permissions. |
| | | 37 | | /// </summary> |
| | 0 | 38 | | public ICollection<string> AdminRolePermissions { get; set; } = ["*"]; |
| | | 39 | | |
| | | 40 | | public void ConfigureServices(IServiceCollection services) |
| | | 41 | | { |
| | 0 | 42 | | services.Configure<DefaultAdminUserOptions>(options => |
| | 0 | 43 | | { |
| | 0 | 44 | | options.AdminUserName = AdminUserName; |
| | 0 | 45 | | options.AdminPassword = AdminPassword; |
| | 0 | 46 | | options.AdminRoleName = AdminRoleName; |
| | 0 | 47 | | options.AdminRolePermissions = AdminRolePermissions; |
| | 0 | 48 | | }); |
| | 0 | 49 | | services.AddBackgroundTask<AdminUserInitializer>(); |
| | 0 | 50 | | } |
| | | 51 | | } |