jellyfin-server/Jellyfin.Api/Auth/RequiresElevationPolicy/RequiresElevationHandler.cs
2019-11-24 19:25:46 +01:00

24 lines
727 B
C#

using System.Threading.Tasks;
using Jellyfin.Api.Constants;
using Microsoft.AspNetCore.Authorization;
namespace Jellyfin.Api.Auth.RequiresElevationPolicy
{
/// <summary>
/// Authorization handler for requiring elevated privileges.
/// </summary>
public class RequiresElevationHandler : AuthorizationHandler<RequiresElevationRequirement>
{
/// <inheritdoc />
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, RequiresElevationRequirement requirement)
{
if (context.User.IsInRole(UserRoles.Administrator))
{
context.Succeed(requirement);
}
return Task.CompletedTask;
}
}
}