AuthenticatedAttribute.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using MediaBrowser.Model.Services;
  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. /// <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. var serviceRequest = new ServiceRequest(request);
  33. AuthService.Authenticate(serviceRequest, 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
  42. {
  43. get { return 0; }
  44. }
  45. public IEnumerable<string> GetRoles()
  46. {
  47. return (Roles ?? string.Empty).Split(new []{ ',' }, StringSplitOptions.RemoveEmptyEntries);
  48. }
  49. }
  50. public interface IAuthenticationAttributes
  51. {
  52. bool EscapeParentalControl { get; }
  53. bool AllowBeforeStartupWizard { get; }
  54. IEnumerable<string> GetRoles();
  55. }
  56. }