2014-07-02 04:57:18 +00:00
|
|
|
|
using ServiceStack.Web;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Net
|
|
|
|
|
{
|
|
|
|
|
public class AuthenticatedAttribute : Attribute, IHasRequestFilter
|
|
|
|
|
{
|
|
|
|
|
public IAuthService AuthService { get; set; }
|
|
|
|
|
|
2014-08-31 19:15:33 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether or not to allow local unauthenticated access.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [allow local]; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool AllowLocal { get; set; }
|
|
|
|
|
|
2014-07-02 04:57:18 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The request filter is executed before the service.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The http request wrapper</param>
|
|
|
|
|
/// <param name="response">The http response wrapper</param>
|
|
|
|
|
/// <param name="requestDto">The request DTO</param>
|
|
|
|
|
public void RequestFilter(IRequest request, IResponse response, object requestDto)
|
|
|
|
|
{
|
2014-08-31 19:15:33 +00:00
|
|
|
|
AuthService.Authenticate(request, response, requestDto, AllowLocal);
|
2014-07-02 04:57:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A new shallow copy of this filter is used on every request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>IHasRequestFilter.</returns>
|
|
|
|
|
public IHasRequestFilter Copy()
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Order in which Request Filters are executed.
|
|
|
|
|
/// <0 Executed before global request filters
|
|
|
|
|
/// >0 Executed after global request filters
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The priority.</value>
|
|
|
|
|
public int Priority
|
|
|
|
|
{
|
|
|
|
|
get { return 0; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|