mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Implements Authorization system
This commit is contained in:
1 parent
5bfb2ca212
commit
2c9c210e43
68 files changed
+2734
-336
No files matched your search
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Infrastructure.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Defines a contract for accessing the current user's information.
|
||||
/// </summary>
|
||||
public interface ICurrentUserService
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the unique identifier of the currently authenticated user. Returns <see langword="null"/> if no user is authenticated.
|
||||
/// </summary>
|
||||
Guid? UserId { get; }
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.Common.Base;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Infrastructure.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the service for managing authorization.
|
||||
/// </summary>
|
||||
public interface IAuthorizationService
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether the specified user has a specific permission.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the user for whom to check the permission.</param>
|
||||
/// <param name="permission">The name of the permission to check.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> if the user has the specified permission, <see langword="false"/> otherwise.</returns>
|
||||
Task<bool> HasPermissionAsync(Guid userId, string permission, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified user belongs to a specific role.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the user for whom to check the role.</param>
|
||||
/// <param name="role">The name of the role to check.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> if the user is in the specified role, <see langword="false"/> otherwise.</returns>
|
||||
Task<bool> IsInRoleAsync(Guid userId, string role, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Evaluates whether the specified user meets the conditions defined in the specified authorization policy.
|
||||
/// </summary>
|
||||
/// <typeparam name="TAuthorizationPolicy">The type of authorization policy to evaluate.</typeparam>
|
||||
/// <param name="userId">The Id of the user for whom to evaluate the policy.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> if the user satisfies the policy, <see langword="false"/> otherwise.</returns>
|
||||
Task<bool> EvaluatePolicyAsync<TAuthorizationPolicy>(Guid userId, CancellationToken cancellationToken) where TAuthorizationPolicy : IAuthorizationPolicy;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Infrastructure.Authorization.Policies.Common.Base;
|
||||
|
||||
/// <summary>
|
||||
/// Defines a contract for policy evaluation in the application.
|
||||
/// </summary>
|
||||
public interface IAuthorizationPolicy
|
||||
{
|
||||
/// <summary>
|
||||
/// Evaluates a policy for a user identified by <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the user for which to evaluate the policy.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> if the policy evaluation succeeds, <see langword="false"/> otherwise.</returns>
|
||||
Task<bool> EvaluateAsync(Guid userId, CancellationToken cancellationToken);
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.Common.Base;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Infrastructure.Authorization.Policies.Over18;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the Over18 authorization policy.
|
||||
/// </summary>
|
||||
public interface IOver18Policy : IAuthorizationPolicy
|
||||
{
|
||||
}
|
||||
Reference in new issue
Block a user