Adds library ownership authorization policy

This commit is contained in:
BinaryAlley committed 2026-08-16 04:59:06 -07:00
1 parent 65a630155d
commit a7dfcbe926
23 files changed
+645 -202

No files matched your search

@@ -34,13 +34,14 @@ public interface IAuthorizationService
Task<bool> IsInRoleAsync(Guid userId, string role, CancellationToken cancellationToken);
/// <summary>
/// Evaluates whether the specified user meets the conditions defined in the specified authorization policy.
/// Evaluates whether the specified user meets the conditions defined in the specified authorization policy, against the resource described by <paramref name="context"/>.
/// </summary>
/// <typeparam name="TAuthorizationPolicy">The type of authorization policy to evaluate.</typeparam>
/// <param name="userId">The unique identifier of the user for whom to evaluate the policy.</param>
/// <param name="context">The context describing the resource against which the policy is evaluated. Can be <see langword="null"/> for policies that do not require a resource.</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;
Task<bool> EvaluatePolicyAsync<TAuthorizationPolicy>(Guid userId, PolicyContext? context, CancellationToken cancellationToken) where TAuthorizationPolicy : IAuthorizationPolicy;
/// <summary>
/// Retrieves all authorization roles and permissions of a user identified by <paramref name="userId"/>.
@@ -12,10 +12,11 @@ namespace Lumina.Application.Common.Infrastructure.Authorization.Policies.Common
public interface IAuthorizationPolicy
{
/// <summary>
/// Evaluates a policy for a user identified by <paramref name="userId"/>.
/// Evaluates a policy for a user identified by <paramref name="userId"/> against the resource described by <paramref name="context"/>.
/// </summary>
/// <param name="userId">The unique identifier of the user for which to evaluate the policy.</param>
/// <param name="context">The context describing the resource against which the policy is evaluated. Can be <see langword="null"/> for policies that do not require a resource.</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);
Task<bool> EvaluateAsync(Guid userId, PolicyContext? context, CancellationToken cancellationToken);
}
@@ -0,0 +1,6 @@
namespace Lumina.Application.Common.Infrastructure.Authorization.Policies.Common.Base;
/// <summary>
/// Represents the contextual information required to evaluate an authorization policy against a specific resource.
/// </summary>
public abstract record PolicyContext;
@@ -0,0 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Authorization.Policies.Common.Base;
#endregion
namespace Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
/// <summary>
/// Interface for the library ownership authorization policy.
/// </summary>
public interface ILibraryOwnershipPolicy : IAuthorizationPolicy
{
}
@@ -0,0 +1,14 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Authorization.Policies.Common.Base;
using System;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
/// <summary>
/// Represents the context required to evaluate the library ownership authorization policy.
/// </summary>
/// <param name="LibraryId">The Id of the media library whose access is being evaluated.</param>
[DebuggerDisplay("LibraryId: {LibraryId}")]
public sealed record LibraryOwnershipPolicyContext(Guid LibraryId) : PolicyContext;