Added auth methods

This commit is contained in:
Thorsten Sommer 2024-12-04 21:22:39 +01:00
parent 4027e4f862
commit 4781fc68fe
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
5 changed files with 88 additions and 0 deletions

View File

@ -1,4 +1,5 @@
@attribute [Route(Routes.ASSISTANT_EDI)]
@using MudExtensions
@inherits AssistantBaseCore
<MudText Typo="Typo.body1" Class="mb-3">
@ -45,4 +46,23 @@
}
</MudStack>
<MudStack Row="@false" AlignItems="AlignItems.Stretch" Class="mb-3">
<MudSelectExtended
T="Auth"
ShrinkLabel="@true"
MultiSelection="@true"
MultiSelectionTextFunc="@this.GetMultiSelectionAuthText"
@bind-SelectedValues="@this.selectedAuthenticationMethods"
Validation="@this.ValidateAuthenticationMethods"
Label="Authentication method(s)"
Variant="Variant.Outlined"
Margin="Margin.Dense">
@foreach (var authMethod in Enum.GetValues<Auth>())
{
<MudSelectItemExtended Value="@authMethod">@authMethod.Name()</MudSelectItemExtended>
}
</MudSelectExtended>
<MudTextField T="string" @bind-Text="@this.authDescription" ShrinkLabel="@true" Label="Describe how you planned the authentication" Validation="@this.ValidateAuthDescription" Variant="Variant.Outlined" Margin="Margin.Normal" Lines="3" AutoGrow="@true" MaxLines="6" UserAttributes="@USER_INPUT_ATTRIBUTES"/>
</MudStack>
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>

View File

@ -46,6 +46,8 @@ public partial class AssistantEDI : AssistantBaseCore
private string otherProgrammingLanguage = string.Empty;
private DataSources selectedDataSource = DataSources.NONE;
private string otherDataSource = string.Empty;
private IEnumerable<Auth> selectedAuthenticationMethods = new HashSet<Auth>();
private string authDescription = string.Empty;
private string? ValidateProgrammingLanguage(ProgrammingLanguages language)
{
@ -90,4 +92,36 @@ public partial class AssistantEDI : AssistantBaseCore
return null;
}
private string? ValidateAuthenticationMethods(Auth _)
{
var authenticationMethods = (this.selectedAuthenticationMethods as HashSet<Auth>)!;
if(authenticationMethods.Count == 0)
return "Please select at least one authentication method for the EDI server.";
return null;
}
private string? ValidateAuthDescription(string description)
{
var authenticationMethods = (this.selectedAuthenticationMethods as HashSet<Auth>)!;
if(authenticationMethods.Any(n => n == Auth.NONE) && authenticationMethods.Count > 1 && string.IsNullOrWhiteSpace(this.authDescription))
return "Please describe how the selected authentication methods should be used. Especially, explain for what data the NONE method (public access) is used.";
if(authenticationMethods.Count > 1 && string.IsNullOrWhiteSpace(this.authDescription))
return "Please describe how the selected authentication methods should be used.";
return null;
}
private string GetMultiSelectionAuthText(List<Auth> selectedValues)
{
if(selectedValues.Count == 0)
return "Please select at least one authentication method";
if(selectedValues.Count == 1)
return $"You have selected 1 authentication method";
return $"You have selected {selectedValues.Count} authentication methods";
}
}

View File

@ -0,0 +1,9 @@
namespace AIStudio.Assistants.EDI;
public enum Auth
{
NONE,
KERBEROS,
USERNAME_PASSWORD,
TOKEN,
}

View File

@ -0,0 +1,15 @@
namespace AIStudio.Assistants.EDI;
public static class AuthExtensions
{
public static string Name(this Auth auth) => auth switch
{
Auth.NONE => "No login necessary: useful for public data sources",
Auth.KERBEROS => "Login by single-sign-on (SSO) using Kerberos: very complex to implement and to operate, useful for many users",
Auth.USERNAME_PASSWORD => "Login by username and password: simple to implement and to operate, useful for few users; easy to use for users",
Auth.TOKEN => "Login by token: simple to implement and to operate, useful for few users; unusual for many users",
_ => "Unknown login method"
};
}

View File

@ -30,6 +30,16 @@ public sealed class DataEDI
/// </summary>
public string PreselectedOtherDataSource { get; set; } = string.Empty;
/// <summary>
/// Preselect any authentication methods?
/// </summary>
public HashSet<Auth> PreselectedAuthMethods { get; set; } = [];
/// <summary>
/// Do you want to preselect any authentication description?
/// </summary>
public string PreselectedAuthDescription { get; set; } = string.Empty;
/// <summary>
/// The minimum confidence level required for a provider to be considered.
/// </summary>