jellyfin/Jellyfin.Api/Auth/FirstTimeSetupOrElevatedPolicy/FirstTimeSetupOrElevatedHandler.cs
2019-11-23 16:31:02 +01:00

36 lines
1.2 KiB
C#

using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
using Microsoft.AspNetCore.Authorization;
namespace Jellyfin.Api.Auth.FirstTimeSetupOrElevatedPolicy
{
public class FirstTimeSetupOrElevatedHandler : AuthorizationHandler<FirstTimeSetupOrElevatedRequirement>
{
private readonly IConfigurationManager _configurationManager;
public FirstTimeSetupOrElevatedHandler(IConfigurationManager configurationManager)
{
_configurationManager = configurationManager;
}
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, FirstTimeSetupOrElevatedRequirement firstTimeSetupOrElevatedRequirement)
{
if (!_configurationManager.CommonConfiguration.IsStartupWizardCompleted)
{
context.Succeed(firstTimeSetupOrElevatedRequirement);
}
else if (context.User.IsInRole("Administrator"))
{
// TODO user role enum
context.Succeed(firstTimeSetupOrElevatedRequirement);
}
else
{
context.Fail();
}
return Task.CompletedTask;
}
}
}