2019-01-13 20:01:16 +00:00
|
|
|
using System;
|
2018-12-27 23:27:57 +00:00
|
|
|
using MediaBrowser.Model.Services;
|
2019-07-28 21:53:19 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Net
|
|
|
|
{
|
|
|
|
public class AuthenticatedAttribute : Attribute, IHasRequestFilter, IAuthenticationAttributes
|
|
|
|
{
|
|
|
|
public static IAuthService AuthService { get; set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the roles.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The roles.</value>
|
|
|
|
public string Roles { get; set; }
|
|
|
|
|
|
|
|
/// <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; }
|
|
|
|
|
|
|
|
/// <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; }
|
|
|
|
|
|
|
|
public bool AllowLocal { get; set; }
|
|
|
|
|
|
|
|
/// <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>
|
2019-07-28 21:53:19 +00:00
|
|
|
public void RequestFilter(IRequest request, HttpResponse response, object requestDto)
|
2018-12-27 23:27:57 +00:00
|
|
|
{
|
|
|
|
AuthService.Authenticate(request, 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>
|
2019-01-13 20:31:14 +00:00
|
|
|
public int Priority => 0;
|
2018-12-27 23:27:57 +00:00
|
|
|
|
|
|
|
public string[] GetRoles()
|
|
|
|
{
|
2019-01-13 19:25:32 +00:00
|
|
|
return (Roles ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
2018-12-27 23:27:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool AllowLocalOnly { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface IAuthenticationAttributes
|
|
|
|
{
|
|
|
|
bool EscapeParentalControl { get; }
|
2020-06-15 21:43:52 +00:00
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
bool AllowBeforeStartupWizard { get; }
|
2020-06-15 21:43:52 +00:00
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
bool AllowLocal { get; }
|
2020-06-15 21:43:52 +00:00
|
|
|
|
2018-12-27 23:27:57 +00:00
|
|
|
bool AllowLocalOnly { get; }
|
|
|
|
|
|
|
|
string[] GetRoles();
|
|
|
|
}
|
|
|
|
}
|