up
Some checks failed
Build Test Deploy / build-test (push) Has been cancelled
Build Test Deploy / authority-container (push) Has been cancelled
Build Test Deploy / docs (push) Has been cancelled
Build Test Deploy / deploy (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Some checks failed
Build Test Deploy / build-test (push) Has been cancelled
Build Test Deploy / authority-container (push) Has been cancelled
Build Test Deploy / docs (push) Has been cancelled
Build Test Deploy / deploy (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,21 @@
|
||||
using Ablera.Serdica.Authorization;
|
||||
using Ablera.Serdica.Authorization.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ablera.Serdica.DependencyInjection;
|
||||
|
||||
public static class AuthorizationServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddSerdicaAuthorization(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
return services
|
||||
.Configure<RolesConfig>(configuration.GetSection(nameof(RolesConfig)))
|
||||
.AddSingleton<GroupsUtilities>();
|
||||
}
|
||||
}
|
||||
34
inspiration/Ablera.Serdica.Authorization/GroupsUtilities.cs
Normal file
34
inspiration/Ablera.Serdica.Authorization/GroupsUtilities.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Ablera.Serdica.Authorization.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ablera.Serdica.Authorization;
|
||||
public class GroupsUtilities
|
||||
{
|
||||
private readonly string[] KnownRoles;
|
||||
|
||||
public GroupsUtilities(IOptions<RolesConfig> rolesOptions)
|
||||
{
|
||||
RolesConfig value = rolesOptions.Value;
|
||||
if (value == null)
|
||||
{
|
||||
KnownRoles = new string[0];
|
||||
return;
|
||||
}
|
||||
|
||||
KnownRoles = (from x in value.UserRoles.Concat(value.OperationsRoles).Concat(value.UnderwriterRoles).Concat(value.OrganizationAdminRoles)
|
||||
.Concat(value.SuperUserRoles)
|
||||
select x.ToUpper()).ToArray();
|
||||
}
|
||||
|
||||
public string[] GetGroupsByRole(string[] roles)
|
||||
{
|
||||
var source = KnownRoles.Intersect(roles);
|
||||
if (!source.Any())
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
|
||||
return source.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ablera.Serdica.Authorization.Models;
|
||||
|
||||
public class RolesConfig
|
||||
{
|
||||
public string[] UserRoles { get; init; } = ["USER", "UR_USER"];
|
||||
public string[] AgentRoles { get; init; } = ["AGENT", "UR_AGENT"];
|
||||
public string[] OrganizationAdminRoles { get; init; } = ["ORGANIZATION_ADMIN", "UR_LDAP_ADMIN", "UR_ORG_ADMIN"];
|
||||
public string[] OperationsRoles { get; init; } = ["OPERATIONS", "UR_OPERATIONS"];
|
||||
public string[] UnderwriterRoles { get; init; } = ["UNDERWRITER", "UR_UNDERWRITER"];
|
||||
public string[] SuperUserRoles { get; init; } = ["ADMIN", "DBA", "GOD", "UR_GOD"];
|
||||
public string[] ExclusiveAgentRoles { get; init; } = ["UR_EXCLUSIVE_AGENT"];
|
||||
}
|
||||
Reference in New Issue
Block a user