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