2
0

AuthenticatedAttribute.cs 2.2 KB

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