jellyfin/Jellyfin.Api/Auth/FirstTimeOrIgnoreParentalControlSetupPolicy/FirstTimeOrIgnoreParentalControlSetupHandler.cs

58 lines
2.3 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 23:59:48 +00:00
namespace Jellyfin.Api.Auth.FirstTimeOrIgnoreParentalControlSetupPolicy
{
/// <summary>
2020-08-06 23:59:48 +00:00
/// Ignore parental control schedule and allow before startup wizard has been completed.
/// </summary>
2020-08-06 23:59:48 +00:00
public class FirstTimeOrIgnoreParentalControlSetupHandler : BaseAuthorizationHandler<IgnoreParentalControlRequirement>
{
2020-08-06 14:17:45 +00:00
private readonly IConfigurationManager _configurationManager;
/// <summary>
2020-08-06 23:59:48 +00:00
/// Initializes a new instance of the <see cref="FirstTimeOrIgnoreParentalControlSetupHandler"/> 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>
2020-08-06 23:59:48 +00:00
public FirstTimeOrIgnoreParentalControlSetupHandler(
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)
{
2020-08-06 23:59:48 +00:00
if (!_configurationManager.CommonConfiguration.IsStartupWizardCompleted)
{
context.Succeed(requirement);
return Task.CompletedTask;
}
var validated = ValidateClaims(context.User, ignoreSchedule: true);
2020-08-06 23:59:48 +00:00
if (validated)
2020-08-06 14:17:45 +00:00
{
context.Succeed(requirement);
}
else
{
context.Fail();
}
return Task.CompletedTask;
}
}
}