FirstTimeOrIgnoreParentalControlSetupHandler.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Threading.Tasks;
  2. using Jellyfin.Api.Auth.IgnoreParentalControlPolicy;
  3. using MediaBrowser.Common.Configuration;
  4. using MediaBrowser.Common.Net;
  5. using MediaBrowser.Controller.Library;
  6. using Microsoft.AspNetCore.Authorization;
  7. using Microsoft.AspNetCore.Http;
  8. namespace Jellyfin.Api.Auth.FirstTimeOrIgnoreParentalControlSetupPolicy
  9. {
  10. /// <summary>
  11. /// Ignore parental control schedule and allow before startup wizard has been completed.
  12. /// </summary>
  13. public class FirstTimeOrIgnoreParentalControlSetupHandler : BaseAuthorizationHandler<IgnoreParentalControlRequirement>
  14. {
  15. private readonly IConfigurationManager _configurationManager;
  16. /// <summary>
  17. /// Initializes a new instance of the <see cref="FirstTimeOrIgnoreParentalControlSetupHandler"/> class.
  18. /// </summary>
  19. /// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
  20. /// <param name="networkManager">Instance of the <see cref="INetworkManager"/> interface.</param>
  21. /// <param name="httpContextAccessor">Instance of the <see cref="IHttpContextAccessor"/> interface.</param>
  22. /// <param name="configurationManager">Instance of the <see cref="IConfigurationManager"/> interface.</param>
  23. public FirstTimeOrIgnoreParentalControlSetupHandler(
  24. IUserManager userManager,
  25. INetworkManager networkManager,
  26. IHttpContextAccessor httpContextAccessor,
  27. IConfigurationManager configurationManager)
  28. : base(userManager, networkManager, httpContextAccessor)
  29. {
  30. _configurationManager = configurationManager;
  31. }
  32. /// <inheritdoc />
  33. protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, IgnoreParentalControlRequirement requirement)
  34. {
  35. if (!_configurationManager.CommonConfiguration.IsStartupWizardCompleted)
  36. {
  37. context.Succeed(requirement);
  38. return Task.CompletedTask;
  39. }
  40. var validated = ValidateClaims(context.User, ignoreSchedule: true);
  41. if (validated)
  42. {
  43. context.Succeed(requirement);
  44. }
  45. else
  46. {
  47. context.Fail();
  48. }
  49. return Task.CompletedTask;
  50. }
  51. }
  52. }