jellyfin-server/Jellyfin.Api/Auth/IgnoreParentalControlOrFirstTimeSetupPolicy/IgnoreParentalControlOrFirstTimeSetupHandler.cs

52 lines
2.1 KiB
C#
Raw Normal View History

using System.Threading.Tasks;
2020-08-06 14:17:45 +00:00
using Jellyfin.Api.Auth.IgnoreParentalControlPolicy;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Library;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
2020-08-06 14:17:45 +00:00
namespace Jellyfin.Api.Auth.IgnoreParentalControlOrFirstTimeSetupPolicy
{
/// <summary>
/// Escape schedule controls handler.
/// </summary>
2020-08-06 14:17:45 +00:00
public class IgnoreParentalControlOrFirstTimeSetupHandler : BaseAuthorizationHandler<IgnoreParentalControlRequirement>
{
2020-08-06 14:17:45 +00:00
private readonly IConfigurationManager _configurationManager;
/// <summary>
2020-08-06 14:17:45 +00:00
/// Initializes a new instance of the <see cref="IgnoreParentalControlOrFirstTimeSetupHandler"/> class.
/// </summary>
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
/// <param name="networkManager">Instance of the <see cref="INetworkManager"/> interface.</param>
/// <param name="httpContextAccessor">Instance of the <see cref="IHttpContextAccessor"/> interface.</param>
2020-08-06 14:17:45 +00:00
/// <param name="configurationManager">Instance of the <see cref="IConfigurationManager"/> interface.</param>
public IgnoreParentalControlOrFirstTimeSetupHandler(
IUserManager userManager,
INetworkManager networkManager,
2020-08-06 14:17:45 +00:00
IHttpContextAccessor httpContextAccessor,
IConfigurationManager configurationManager)
: base(userManager, networkManager, httpContextAccessor)
{
2020-08-06 14:17:45 +00:00
_configurationManager = configurationManager;
}
/// <inheritdoc />
2020-08-06 14:17:45 +00:00
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, IgnoreParentalControlRequirement requirement)
{
var validated = ValidateClaims(context.User, ignoreSchedule: true);
2020-08-06 14:17:45 +00:00
if (validated || !_configurationManager.CommonConfiguration.IsStartupWizardCompleted)
{
context.Succeed(requirement);
}
else
{
context.Fail();
}
return Task.CompletedTask;
}
}
}