Class AuthorizationMetadataService
- Namespace
- Htmx.Components.Services
- Assembly
- Htmx.Components.dll
Implements authorization metadata extraction and evaluation with caching capabilities.
public class AuthorizationMetadataService : IAuthorizationMetadataService
- Inheritance
-
AuthorizationMetadataService
- Implements
- Inherited Members
- Extension Methods
Constructors
AuthorizationMetadataService(IAuthorizationService, IMemoryCache, IOptions<AuthorizationMetadataSettings>, IRoleService?)
Initializes a new instance of the AuthorizationMetadataService class.
public AuthorizationMetadataService(IAuthorizationService authorizationService, IMemoryCache cache, IOptions<AuthorizationMetadataSettings> settings, IRoleService? roleService = null)
Parameters
authorizationService
IAuthorizationServiceThe authorization service for evaluating policies.
cache
IMemoryCacheThe memory cache for storing authorization metadata and results.
settings
IOptions<AuthorizationMetadataSettings>The configuration settings for the service.
roleService
IRoleServiceThe optional role service for role-based authorization checks.
Methods
GetMetadataAsync(ControllerActionDescriptor)
Extracts authorization metadata from a controller action descriptor with caching.
public Task<AuthorizationMetadata> GetMetadataAsync(ControllerActionDescriptor descriptor)
Parameters
descriptor
ControllerActionDescriptorThe controller action descriptor to analyze.
Returns
- Task<AuthorizationMetadata>
A task that represents the asynchronous operation. The task result contains the authorization metadata.
IsAuthorizedAsync(ControllerActionDescriptor, ClaimsPrincipal)
Determines whether the specified user is authorized to access the controller action. Evaluates authentication requirements, authorization policies, and role-based permissions.
public Task<bool> IsAuthorizedAsync(ControllerActionDescriptor descriptor, ClaimsPrincipal user)
Parameters
descriptor
ControllerActionDescriptorThe controller action descriptor to check authorization for.
user
ClaimsPrincipalThe claims principal representing the user.
Returns
- Task<bool>
A task that represents the asynchronous operation. The task result is true if the user is authorized; otherwise, false.
Exceptions
- InvalidOperationException
Thrown when role-based authorization is required but no IRoleService is registered.