2020-06-15 11:49:54 -07:00
|
|
|
|
using System.Threading.Tasks;
|
2020-08-06 07:17:45 -07:00
|
|
|
|
using MediaBrowser.Common.Configuration;
|
2020-06-15 11:49:54 -07:00
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
2020-08-06 16:59:48 -07:00
|
|
|
|
namespace Jellyfin.Api.Auth.FirstTimeOrIgnoreParentalControlSetupPolicy
|
2020-06-15 11:49:54 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2020-08-06 16:59:48 -07:00
|
|
|
|
/// Ignore parental control schedule and allow before startup wizard has been completed.
|
2020-06-15 11:49:54 -07:00
|
|
|
|
/// </summary>
|
2020-08-09 12:51:25 -07:00
|
|
|
|
public class FirstTimeOrIgnoreParentalControlSetupHandler : BaseAuthorizationHandler<FirstTimeOrIgnoreParentalControlSetupRequirement>
|
2020-06-15 11:49:54 -07:00
|
|
|
|
{
|
2020-08-06 07:17:45 -07:00
|
|
|
|
private readonly IConfigurationManager _configurationManager;
|
|
|
|
|
|
2020-06-15 11:49:54 -07:00
|
|
|
|
/// <summary>
|
2020-08-06 16:59:48 -07:00
|
|
|
|
/// Initializes a new instance of the <see cref="FirstTimeOrIgnoreParentalControlSetupHandler"/> class.
|
2020-06-15 11:49:54 -07: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 07:17:45 -07:00
|
|
|
|
/// <param name="configurationManager">Instance of the <see cref="IConfigurationManager"/> interface.</param>
|
2020-08-06 16:59:48 -07:00
|
|
|
|
public FirstTimeOrIgnoreParentalControlSetupHandler(
|
2020-06-15 11:49:54 -07:00
|
|
|
|
IUserManager userManager,
|
|
|
|
|
INetworkManager networkManager,
|
2020-08-06 07:17:45 -07:00
|
|
|
|
IHttpContextAccessor httpContextAccessor,
|
|
|
|
|
IConfigurationManager configurationManager)
|
2020-06-15 11:49:54 -07:00
|
|
|
|
: base(userManager, networkManager, httpContextAccessor)
|
|
|
|
|
{
|
2020-08-06 07:17:45 -07:00
|
|
|
|
_configurationManager = configurationManager;
|
2020-06-15 11:49:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2020-08-09 12:51:25 -07:00
|
|
|
|
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, FirstTimeOrIgnoreParentalControlSetupRequirement requirement)
|
2020-06-15 11:49:54 -07:00
|
|
|
|
{
|
2020-08-06 16:59:48 -07:00
|
|
|
|
if (!_configurationManager.CommonConfiguration.IsStartupWizardCompleted)
|
|
|
|
|
{
|
|
|
|
|
context.Succeed(requirement);
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-15 11:49:54 -07:00
|
|
|
|
var validated = ValidateClaims(context.User, ignoreSchedule: true);
|
2020-08-06 16:59:48 -07:00
|
|
|
|
if (validated)
|
2020-08-06 07:17:45 -07:00
|
|
|
|
{
|
|
|
|
|
context.Succeed(requirement);
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-06-15 11:49:54 -07:00
|
|
|
|
{
|
|
|
|
|
context.Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|