2020-06-15 11:49:54 -07:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
2020-08-06 07:17:45 -07:00
|
|
|
|
namespace Jellyfin.Api.Auth.IgnoreParentalControlPolicy
|
2020-06-15 11:49:54 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Escape schedule controls handler.
|
|
|
|
|
/// </summary>
|
2020-08-06 07:17:45 -07:00
|
|
|
|
public class IgnoreParentalControlHandler : BaseAuthorizationHandler<IgnoreParentalControlRequirement>
|
2020-06-15 11:49:54 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2020-08-06 07:17:45 -07:00
|
|
|
|
/// Initializes a new instance of the <see cref="IgnoreParentalControlHandler"/> 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
|
|
|
|
public IgnoreParentalControlHandler(
|
2020-06-15 11:49:54 -07:00
|
|
|
|
IUserManager userManager,
|
|
|
|
|
INetworkManager networkManager,
|
|
|
|
|
IHttpContextAccessor httpContextAccessor)
|
|
|
|
|
: base(userManager, networkManager, httpContextAccessor)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2020-08-06 07:17:45 -07:00
|
|
|
|
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, IgnoreParentalControlRequirement requirement)
|
2020-06-15 11:49:54 -07:00
|
|
|
|
{
|
|
|
|
|
var validated = ValidateClaims(context.User, ignoreSchedule: true);
|
2020-10-14 16:58:46 -07:00
|
|
|
|
if (validated)
|
|
|
|
|
{
|
|
|
|
|
context.Succeed(requirement);
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-06-15 11:49:54 -07:00
|
|
|
|
{
|
|
|
|
|
context.Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|