jellyfin/MediaBrowser.Controller/Net/AuthenticatedAttribute.cs

79 lines
2.5 KiB
C#
Raw Normal View History

using ServiceStack.Web;
using System;
2014-10-28 16:17:55 -07:00
using System.Collections.Generic;
2014-09-14 10:42:23 -07:00
using System.Linq;
namespace MediaBrowser.Controller.Net
{
2014-11-14 19:31:03 -07:00
public class AuthenticatedAttribute : Attribute, IHasRequestFilter, IAuthenticationAttributes
{
public IAuthService AuthService { get; set; }
2014-10-28 16:17:55 -07:00
/// <summary>
/// Gets or sets the roles.
/// </summary>
/// <value>The roles.</value>
2014-09-14 10:42:23 -07:00
public string Roles { get; set; }
2014-10-28 16:17:55 -07: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-14 19:31:03 -07: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; }
/// <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-11-14 19:31:03 -07:00
var serviceRequest = new ServiceStackServiceRequest(request);
AuthService.Authenticate(serviceRequest, this);
}
/// <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.
/// &lt;0 Executed before global request filters
/// &gt;0 Executed after global request filters
/// </summary>
/// <value>The priority.</value>
public int Priority
{
get { return 0; }
}
2014-10-28 16:17:55 -07:00
public IEnumerable<string> GetRoles()
{
return (Roles ?? string.Empty).Split(',')
.Where(i => !string.IsNullOrWhiteSpace(i));
}
}
2014-11-14 19:31:03 -07:00
public interface IAuthenticationAttributes
2014-10-28 16:17:55 -07:00
{
bool EscapeParentalControl { get; }
2014-11-14 19:31:03 -07:00
bool AllowBeforeStartupWizard { get; }
2014-10-28 16:17:55 -07:00
IEnumerable<string> GetRoles();
}
}