AuthenticatedAttribute.cs 2.2 KB

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