2016-10-25 19:02:04 +00:00
|
|
|
|
using System;
|
|
|
|
|
using MediaBrowser.Model.Services;
|
2014-07-02 04:57:18 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Net
|
|
|
|
|
{
|
2014-11-15 02:31:03 +00:00
|
|
|
|
public class AuthenticatedAttribute : Attribute, IHasRequestFilter, IAuthenticationAttributes
|
2014-07-02 04:57:18 +00:00
|
|
|
|
{
|
2016-11-08 18:44:23 +00:00
|
|
|
|
public static IAuthService AuthService { get; set; }
|
2014-07-02 04:57:18 +00:00
|
|
|
|
|
2014-10-28 23:17:55 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the roles.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The roles.</value>
|
2014-09-14 17:42:23 +00:00
|
|
|
|
public string Roles { get; set; }
|
|
|
|
|
|
2014-10-28 23:17:55 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether [escape parental control].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [escape parental control]; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool EscapeParentalControl { get; set; }
|
|
|
|
|
|
2014-11-15 02:31:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether [allow before startup wizard].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if [allow before startup wizard]; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool AllowBeforeStartupWizard { get; set; }
|
2016-11-08 18:44:23 +00:00
|
|
|
|
|
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)
|
|
|
|
|
{
|
2016-10-25 19:02:04 +00:00
|
|
|
|
var serviceRequest = new ServiceRequest(request);
|
2014-11-15 02:31:03 +00:00
|
|
|
|
|
|
|
|
|
AuthService.Authenticate(serviceRequest, this);
|
2014-07-02 04:57:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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; }
|
|
|
|
|
}
|
2014-10-28 23:17:55 +00:00
|
|
|
|
|
2017-08-30 18:52:29 +00:00
|
|
|
|
public string[] GetRoles()
|
2014-10-28 23:17:55 +00:00
|
|
|
|
{
|
2017-08-09 19:56:38 +00:00
|
|
|
|
return (Roles ?? string.Empty).Split(new []{ ',' }, StringSplitOptions.RemoveEmptyEntries);
|
2014-10-28 23:17:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 02:31:03 +00:00
|
|
|
|
public interface IAuthenticationAttributes
|
2014-10-28 23:17:55 +00:00
|
|
|
|
{
|
|
|
|
|
bool EscapeParentalControl { get; }
|
2014-11-15 02:31:03 +00:00
|
|
|
|
bool AllowBeforeStartupWizard { get; }
|
2014-10-28 23:17:55 +00:00
|
|
|
|
|
2017-08-30 18:52:29 +00:00
|
|
|
|
string[] GetRoles();
|
2014-07-02 04:57:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|