f40409a688
Tracking IDs are review bookkeeping that rots in shipped source; the rationale they tagged is kept. Comment-only change (CommentChecker 458 -> 16 false positives).
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
|
|
namespace ZB.MOM.WW.MxGateway.Server.Dashboard;
|
|
|
|
/// <summary>
|
|
/// Handler for <see cref="AuthenticatedDashboardRoleRequirement"/>: succeeds only when the caller
|
|
/// is authenticated AND holds one of the requirement's roles. It reads no options at all, which
|
|
/// is the point — there is no configuration value that can turn this into a bypass.
|
|
/// </summary>
|
|
public sealed class AuthenticatedDashboardRoleHandler
|
|
: AuthorizationHandler<AuthenticatedDashboardRoleRequirement>
|
|
{
|
|
/// <inheritdoc />
|
|
protected override Task HandleRequirementAsync(
|
|
AuthorizationHandlerContext context,
|
|
AuthenticatedDashboardRoleRequirement requirement)
|
|
{
|
|
if (context.User.Identity?.IsAuthenticated != true)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
foreach (string role in requirement.RequiredRoles)
|
|
{
|
|
if (context.User.IsInRole(role))
|
|
{
|
|
context.Succeed(requirement);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|