Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
108 lines
4.3 KiB
Text
108 lines
4.3 KiB
Text
@page "/Settings/Authentication"
|
|
@using CaseConverter
|
|
@using LANCommander.SDK.Extensions
|
|
@using LANCommander.Server.Settings
|
|
@using LANCommander.Server.UI.Pages.Settings.Authentication.Components
|
|
@using Microsoft.Extensions.Options
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<Index> Logger
|
|
@inject IServiceProvider ServiceProvider
|
|
@inject IOptions<Settings> Settings
|
|
@inject SettingsProvider<Settings> SettingsProvider
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
|
|
<PageHeader Title="Authentication">
|
|
<PageHeaderExtra>
|
|
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
|
|
</PageHeaderExtra>
|
|
</PageHeader>
|
|
|
|
<PageContent>
|
|
<Form Model="Settings.Value" Layout="@FormLayout.Vertical">
|
|
<FormItem Label="Require Account Approval">
|
|
<Switch @bind-Checked="context.Server.Authentication.RequireApproval" />
|
|
</FormItem>
|
|
|
|
<FormItem Label="Token Secret">
|
|
<InputPassword @bind-Value="context.Server.Authentication.TokenSecret" />
|
|
</FormItem>
|
|
<FormItem Label="Token Lifetime">
|
|
<AntDesign.InputNumber @bind-Value="context.Server.Authentication.TokenLifetime" Formatter="FormatTokenLifetime" Min="1" />
|
|
</FormItem>
|
|
|
|
<Divider Text="Password Requirements" />
|
|
|
|
<FormItem Label="Require non-alphanumeric characters">
|
|
<Switch @bind-Checked="@context.Server.Authentication.PasswordRequireNonAlphanumeric" />
|
|
</FormItem>
|
|
<FormItem Label="Require Lowercase characters">
|
|
<Switch @bind-Checked="context.Server.Authentication.PasswordRequireLowercase" />
|
|
</FormItem>
|
|
<FormItem Label="Require Uppercase characters">
|
|
<Switch @bind-Checked="context.Server.Authentication.PasswordRequireUppercase" />
|
|
</FormItem>
|
|
<FormItem Label="Require digits">
|
|
<Switch @bind-Checked="context.Server.Authentication.PasswordRequireDigit" />
|
|
</FormItem>
|
|
<FormItem Label="Minimum Length">
|
|
<AntDesign.InputNumber @bind-Value="context.Server.Authentication.PasswordRequiredLength" Min="1" />
|
|
</FormItem>
|
|
|
|
<Divider Text="Security" />
|
|
|
|
<Collapse>
|
|
<Panel Header="HTTP">
|
|
<FormItem Label="Minimum Same Site Cookie Policy">
|
|
<EnumSelect TEnum="SameSiteMode" @bind-Value="context.Server.Authentication.HttpCookiePolicy.SameSite" />
|
|
</FormItem>
|
|
<FormItem Label="Cookie Secure Policy">
|
|
<EnumSelect TEnum="CookieSecurePolicy" @bind-Value="context.Server.Authentication.HttpCookiePolicy.Secure" />
|
|
</FormItem>
|
|
</Panel>
|
|
|
|
<Panel Header="HTTPS">
|
|
<FormItem Label="Minimum Same Site Cookie Policy">
|
|
<EnumSelect TEnum="SameSiteMode" @bind-Value="context.Server.Authentication.HttpsCookiePolicy.SameSite" />
|
|
</FormItem>
|
|
<FormItem Label="Cookie Secure Policy">
|
|
<EnumSelect TEnum="CookieSecurePolicy" @bind-Value="context.Server.Authentication.HttpsCookiePolicy.Secure" />
|
|
</FormItem>
|
|
</Panel>
|
|
</Collapse>
|
|
</Form>
|
|
|
|
<Divider Text="External Providers" />
|
|
|
|
<ExternalProviderEditor @bind-Values="Settings.Value.Server.Authentication.AuthenticationProviders" />
|
|
</PageContent>
|
|
|
|
@code {
|
|
string FormatTokenLifetime(int value)
|
|
{
|
|
return value.ToString() + " days";
|
|
}
|
|
|
|
void Save()
|
|
{
|
|
try
|
|
{
|
|
SettingsProvider.Update(s =>
|
|
{
|
|
foreach (var authenticationProvider in Settings.Value.Server.Authentication.AuthenticationProviders)
|
|
{
|
|
if (String.IsNullOrWhiteSpace(authenticationProvider.Slug))
|
|
authenticationProvider.Slug = authenticationProvider.Name.ToPascalCase();
|
|
}
|
|
|
|
s.Server.Authentication.AuthenticationProviders = Settings.Value.Server.Authentication.AuthenticationProviders;
|
|
});
|
|
|
|
MessageService.Success("Settings saved!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("An unknown error occurred.");
|
|
Logger.LogError(ex, "An unknown error occurred.");
|
|
}
|
|
}
|
|
}
|