using ServiceStack.Web; using System; using System.Collections.Generic; using System.Linq; namespace MediaBrowser.Controller.Net { public class AuthenticatedAttribute : Attribute, IHasRequestFilter, IAuthenticated { public IAuthService AuthService { get; set; } /// /// Gets or sets a value indicating whether or not to allow local unauthenticated access. /// /// true if [allow local]; otherwise, false. public bool AllowLocal { 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; } /// /// 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, response, requestDto, this); } /// /// A new shallow copy of this filter is used on every request. /// /// IHasRequestFilter. public IHasRequestFilter Copy() { return 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 IEnumerable GetRoles() { return (Roles ?? string.Empty).Split(',') .Where(i => !string.IsNullOrWhiteSpace(i)); } } public interface IAuthenticated { bool EscapeParentalControl { get; } bool AllowLocal { get; } IEnumerable GetRoles(); } }