Implements authorization caching and check in the web client

This commit is contained in:
BinaryAlley committed 2024-12-06 18:46:48 +02:00
1 parent 7bca5b1ba3
commit 8eb1b9f13c
108 files changed
+5931 -73

No files matched your search

@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Domain.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -21,17 +22,22 @@ public class PermissionEntity : IStorageEntity, IAuditableEntity
/// <summary>
/// Gets the name of the permission.
/// </summary>
public required string PermissionName { get; init; }
public required AuthorizationPermission PermissionName { get; init; }
/// <summary>
/// Gets the collection of role permission associations that include this permission.
/// Gets the description of the permission.
/// </summary>
public required ICollection<RolePermissionEntity> RolePermissions { get; init; } = [];
public string? PermissionDescription { get; set; }
/// <summary>
/// Gets the collection of user permission associations that include this permission.
/// Gets or sets the collection of role permission associations that include this permission.
/// </summary>
public required ICollection<UserPermissionEntity> UserPermissions { get; init; } = [];
public ICollection<RolePermissionEntity> RolePermissions { get; set; } = [];
/// <summary>
/// Gets or sets the collection of user permission associations that include this permission.
/// </summary>
public ICollection<UserPermissionEntity> UserPermissions { get; set; } = [];
/// <summary>
/// Gets or sets the time and date when the entity was added.
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Domain.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -21,17 +22,22 @@ public class RoleEntity : IStorageEntity
/// <summary>
/// Gets the name of the role.
/// </summary>
public required string RoleName { get; init; }
public required AuthorizationRole RoleName { get; init; }
/// <summary>
/// Gets the collection of user roles associations that include this role.
/// Gets or sets the description of the role.
/// </summary>
public required ICollection<UserRoleEntity> UserRoles { get; init; } = [];
public string? RoleDescription { get; set; }
/// <summary>
/// Gets the collection of role permission associations that include this role.
/// Gets or sets the collection of user roles associations that include this role.
/// </summary>
public required ICollection<RolePermissionEntity> RolePermissions { get; init; } = [];
public ICollection<UserRoleEntity> UserRoles { get; set; } = [];
/// <summary>
/// Gets or sets the collection of role permission associations that include this role.
/// </summary>
public ICollection<RolePermissionEntity> RolePermissions { get; set; } = [];
/// <summary>
/// Gets or sets the time and date when the entity was added.
@@ -0,0 +1,30 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.Authorization;
/// <summary>
/// Data Transfer object containing all the authorization info of a user.
/// </summary>
[DebuggerDisplay("UserId: {UserId}")]
public class UserAuthorizationEntity
{
/// <summary>
/// Gets the Id of the user.
/// </summary>
public required Guid UserId { get; init; }
/// <summary>
/// Gets the collection of roles associated to the user.
/// </summary>
public required IReadOnlySet<AuthorizationRole> Roles { get; init; }
/// <summary>
/// Gets the collection of permissions associated to the user.
/// </summary>
public required IReadOnlySet<AuthorizationPermission> Permissions { get; init; }
}
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Authorization;
/// <summary>
/// Interface for the repository for authorization permissions.
/// </summary>
public interface IPermissionRepository : IRepository<PermissionEntity>,
IInsertRepositoryAction<PermissionEntity>,
IGetAllRepositoryAction<PermissionEntity>
{
}
@@ -0,0 +1,15 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Authorization;
/// <summary>
/// Interface for the repository for authorization role permissions.
/// </summary>
public interface IRolePermissionRepository : IRepository<RolePermissionEntity>,
IInsertRepositoryAction<RolePermissionEntity>
{
}
@@ -0,0 +1,27 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.Domain.Common.Enums.Authorization;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Authorization;
/// <summary>
/// Interface for the repository for authorization roles.
/// </summary>
public interface IRoleRepository : IRepository<RoleEntity>,
IInsertRepositoryAction<RoleEntity>,
IGetAllRepositoryAction<RoleEntity>
{
/// <summary>
/// Gets a role identified by <paramref name="roleType"/> from the repository, if it exists.
/// </summary>
/// <param name="roleType">The type of role to get.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a <see cref="RoleEntity"/> if found, or an error.</returns>
Task<ErrorOr<RoleEntity?>> GetByNameAsync(AuthorizationRole roleType, CancellationToken cancellationToken);
}
@@ -0,0 +1,15 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Authorization;
/// <summary>
/// Interface for the repository for authorization user roles.
/// </summary>
public interface IUserRoleRepository : IRepository<UserRoleEntity>,
IInsertRepositoryAction<UserRoleEntity>
{
}
@@ -20,7 +20,7 @@ public interface IUserRepository : IRepository<UserEntity>,
IUpdateRepositoryAction<UserEntity>
{
/// <summary>
/// Gets a username identified by <paramref name="username"/> from the repository, if it exists.
/// Gets a user identified by <paramref name="username"/> from the repository, if it exists.
/// </summary>
/// <param name="username">The username of the user to get.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using System;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Seed;
/// <summary>
/// Interface for the service for seeding initial data in the persistence medium.
/// </summary>
public interface IDataSeedService
{
/// <summary>
/// Sets up default authorization permissions in the system.
/// </summary>
/// <param name="adminId">The Id of the admin admin user who will own these permissions.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
Task<ErrorOr<Created>> SetDefaultAuthorizationPermissionsAsync(Guid adminId, CancellationToken cancellationToken);
/// <summary>
/// Sets up default authorization roles in the system.
/// </summary>
/// <param name="userId">The Id of the admin user for whom roles will be set.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
Task<ErrorOr<Created>> SetDefaultAuthorizationRolesAsync(Guid userId, CancellationToken cancellationToken);
/// <summary>
/// Assigns admin role permissions to the admin user.
/// </summary>
/// <param name="userId">The Id of the admin user to receive admin role permissions.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
Task<ErrorOr<Created>> SetAdminRolePermissionsAsync(Guid userId, CancellationToken cancellationToken);
/// <summary>
/// Assigns admin role to the admin user.
/// </summary>
/// <param name="userId">The Id of the admin user to receive the admin role.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
Task<ErrorOr<Created>> SetAdminRoleToAdministratorAccount(Guid userId, CancellationToken cancellationToken);
}