AuthenticatedAttribute.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using ServiceStack.Web;
  2. using System;
  3. namespace MediaBrowser.Controller.Net
  4. {
  5. public class AuthenticatedAttribute : Attribute, IHasRequestFilter
  6. {
  7. public IAuthService AuthService { get; set; }
  8. /// <summary>
  9. /// Gets or sets a value indicating whether or not to allow local unauthenticated access.
  10. /// </summary>
  11. /// <value><c>true</c> if [allow local]; otherwise, <c>false</c>.</value>
  12. public bool AllowLocal { get; set; }
  13. /// <summary>
  14. /// The request filter is executed before the service.
  15. /// </summary>
  16. /// <param name="request">The http request wrapper</param>
  17. /// <param name="response">The http response wrapper</param>
  18. /// <param name="requestDto">The request DTO</param>
  19. public void RequestFilter(IRequest request, IResponse response, object requestDto)
  20. {
  21. AuthService.Authenticate(request, response, requestDto, AllowLocal);
  22. }
  23. /// <summary>
  24. /// A new shallow copy of this filter is used on every request.
  25. /// </summary>
  26. /// <returns>IHasRequestFilter.</returns>
  27. public IHasRequestFilter Copy()
  28. {
  29. return this;
  30. }
  31. /// <summary>
  32. /// Order in which Request Filters are executed.
  33. /// &lt;0 Executed before global request filters
  34. /// &gt;0 Executed after global request filters
  35. /// </summary>
  36. /// <value>The priority.</value>
  37. public int Priority
  38. {
  39. get { return 0; }
  40. }
  41. }
  42. }