AuthenticatedAttribute.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma warning disable CS1591
  2. using System;
  3. using MediaBrowser.Model.Services;
  4. using Microsoft.AspNetCore.Http;
  5. namespace MediaBrowser.Controller.Net
  6. {
  7. public class AuthenticatedAttribute : Attribute, IHasRequestFilter, IAuthenticationAttributes
  8. {
  9. public static IAuthService AuthService { get; set; }
  10. /// <summary>
  11. /// Gets or sets the roles.
  12. /// </summary>
  13. /// <value>The roles.</value>
  14. public string Roles { get; set; }
  15. /// <summary>
  16. /// Gets or sets a value indicating whether [escape parental control].
  17. /// </summary>
  18. /// <value><c>true</c> if [escape parental control]; otherwise, <c>false</c>.</value>
  19. public bool EscapeParentalControl { get; set; }
  20. /// <summary>
  21. /// Gets or sets a value indicating whether [allow before startup wizard].
  22. /// </summary>
  23. /// <value><c>true</c> if [allow before startup wizard]; otherwise, <c>false</c>.</value>
  24. public bool AllowBeforeStartupWizard { get; set; }
  25. public bool AllowLocal { get; set; }
  26. /// <summary>
  27. /// The request filter is executed before the service.
  28. /// </summary>
  29. /// <param name="request">The http request wrapper.</param>
  30. /// <param name="response">The http response wrapper.</param>
  31. /// <param name="requestDto">The request DTO.</param>
  32. public void RequestFilter(IRequest request, HttpResponse response, object requestDto)
  33. {
  34. AuthService.Authenticate(request, this);
  35. }
  36. /// <summary>
  37. /// Order in which Request Filters are executed.
  38. /// &lt;0 Executed before global request filters
  39. /// &gt;0 Executed after global request filters
  40. /// </summary>
  41. /// <value>The priority.</value>
  42. public int Priority => 0;
  43. public string[] GetRoles()
  44. {
  45. return (Roles ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  46. }
  47. public bool IgnoreLegacyAuth { get; set; }
  48. public bool AllowLocalOnly { get; set; }
  49. }
  50. public interface IAuthenticationAttributes
  51. {
  52. bool EscapeParentalControl { get; }
  53. bool AllowBeforeStartupWizard { get; }
  54. bool AllowLocal { get; }
  55. bool AllowLocalOnly { get; }
  56. string[] GetRoles();
  57. bool IgnoreLegacyAuth { get; }
  58. }
  59. }