From a86b71899ec52c44ddc6c3018e8cc5e9d7ff4d62 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Thu, 27 Dec 2018 18:27:57 -0500 Subject: Add GPL modules --- .../Net/AuthenticatedAttribute.cs | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 MediaBrowser.Controller/Net/AuthenticatedAttribute.cs (limited to 'MediaBrowser.Controller/Net/AuthenticatedAttribute.cs') diff --git a/MediaBrowser.Controller/Net/AuthenticatedAttribute.cs b/MediaBrowser.Controller/Net/AuthenticatedAttribute.cs new file mode 100644 index 0000000000..2f31b8e665 --- /dev/null +++ b/MediaBrowser.Controller/Net/AuthenticatedAttribute.cs @@ -0,0 +1,69 @@ +using System; +using MediaBrowser.Model.Services; + +namespace MediaBrowser.Controller.Net +{ + public class AuthenticatedAttribute : Attribute, IHasRequestFilter, IAuthenticationAttributes + { + public static IAuthService AuthService { get; set; } + + /// + /// Gets or sets the roles. + /// + /// The roles. + public string Roles { get; set; } + + /// + /// Gets or sets a value indicating whether [escape parental control]. + /// + /// true if [escape parental control]; otherwise, false. + public bool EscapeParentalControl { get; set; } + + /// + /// Gets or sets a value indicating whether [allow before startup wizard]. + /// + /// true if [allow before startup wizard]; otherwise, false. + public bool AllowBeforeStartupWizard { get; set; } + + public bool AllowLocal { get; set; } + + /// + /// The request filter is executed before the service. + /// + /// The http request wrapper + /// The http response wrapper + /// The request DTO + public void RequestFilter(IRequest request, IResponse response, object requestDto) + { + AuthService.Authenticate(request, this); + } + + /// + /// Order in which Request Filters are executed. + /// <0 Executed before global request filters + /// >0 Executed after global request filters + /// + /// The priority. + public int Priority + { + get { return 0; } + } + + public string[] GetRoles() + { + return (Roles ?? string.Empty).Split(new []{ ',' }, StringSplitOptions.RemoveEmptyEntries); + } + + public bool AllowLocalOnly { get; set; } + } + + public interface IAuthenticationAttributes + { + bool EscapeParentalControl { get; } + bool AllowBeforeStartupWizard { get; } + bool AllowLocal { get; } + bool AllowLocalOnly { get; } + + string[] GetRoles(); + } +} -- cgit v1.2.3