mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 01:24:44 +01:00
revise endpoint attributes
This commit is contained in:
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Controller.Net
|
||||
{
|
||||
public class AuthenticatedAttribute : Attribute, IHasRequestFilter, IAuthenticated
|
||||
public class AuthenticatedAttribute : Attribute, IHasRequestFilter, IAuthenticationAttributes
|
||||
{
|
||||
public IAuthService AuthService { get; set; }
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace MediaBrowser.Controller.Net
|
||||
/// <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; }
|
||||
|
||||
/// <summary>
|
||||
/// The request filter is executed before the service.
|
||||
/// </summary>
|
||||
@@ -29,7 +35,9 @@ namespace MediaBrowser.Controller.Net
|
||||
/// <param name="requestDto">The request DTO</param>
|
||||
public void RequestFilter(IRequest request, IResponse response, object requestDto)
|
||||
{
|
||||
AuthService.Authenticate(request, response, requestDto, this);
|
||||
var serviceRequest = new ServiceStackServiceRequest(request);
|
||||
|
||||
AuthService.Authenticate(serviceRequest, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -60,9 +68,10 @@ namespace MediaBrowser.Controller.Net
|
||||
}
|
||||
}
|
||||
|
||||
public interface IAuthenticated
|
||||
public interface IAuthenticationAttributes
|
||||
{
|
||||
bool EscapeParentalControl { get; }
|
||||
bool AllowBeforeStartupWizard { get; }
|
||||
|
||||
IEnumerable<string> GetRoles();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
using ServiceStack.Web;
|
||||
|
||||
|
||||
namespace MediaBrowser.Controller.Net
|
||||
{
|
||||
public interface IAuthService
|
||||
{
|
||||
void Authenticate(IRequest request,
|
||||
IResponse response,
|
||||
object requestDto,
|
||||
IAuthenticated authAttribtues);
|
||||
void Authenticate(IServiceRequest request,
|
||||
IAuthenticationAttributes authAttribtues);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using ServiceStack.Web;
|
||||
|
||||
|
||||
namespace MediaBrowser.Controller.Net
|
||||
{
|
||||
public interface IAuthorizationContext
|
||||
@@ -9,6 +8,13 @@ namespace MediaBrowser.Controller.Net
|
||||
/// </summary>
|
||||
/// <param name="requestContext">The request context.</param>
|
||||
/// <returns>AuthorizationInfo.</returns>
|
||||
AuthorizationInfo GetAuthorizationInfo(IRequest requestContext);
|
||||
AuthorizationInfo GetAuthorizationInfo(object requestContext);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the authorization information.
|
||||
/// </summary>
|
||||
/// <param name="requestContext">The request context.</param>
|
||||
/// <returns>AuthorizationInfo.</returns>
|
||||
AuthorizationInfo GetAuthorizationInfo(IServiceRequest requestContext);
|
||||
}
|
||||
}
|
||||
|
||||
15
MediaBrowser.Controller/Net/IServiceRequest.cs
Normal file
15
MediaBrowser.Controller/Net/IServiceRequest.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace MediaBrowser.Controller.Net
|
||||
{
|
||||
public interface IServiceRequest
|
||||
{
|
||||
object OriginalRequest { get; }
|
||||
string RemoteIp { get; }
|
||||
NameValueCollection Headers { get; }
|
||||
NameValueCollection QueryString { get; }
|
||||
IDictionary<string,object> Items { get; }
|
||||
void AddResponseHeader(string name, string value);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Session;
|
||||
using ServiceStack.Web;
|
||||
|
||||
namespace MediaBrowser.Controller.Net
|
||||
{
|
||||
public interface ISessionContext
|
||||
{
|
||||
SessionInfo GetSession(IRequest requestContext);
|
||||
|
||||
User GetUser(IRequest requestContext);
|
||||
SessionInfo GetSession(object requestContext);
|
||||
User GetUser(object requestContext);
|
||||
|
||||
SessionInfo GetSession(IServiceRequest requestContext);
|
||||
User GetUser(IServiceRequest requestContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,10 @@ namespace MediaBrowser.Controller.Net
|
||||
/// <param name="requestDto">The request DTO</param>
|
||||
public void RequestFilter(IRequest request, IResponse response, object requestDto)
|
||||
{
|
||||
var serviceRequest = new ServiceStackServiceRequest(request);
|
||||
|
||||
//This code is executed before the service
|
||||
var auth = AuthorizationContext.GetAuthorizationInfo(request);
|
||||
var auth = AuthorizationContext.GetAuthorizationInfo(serviceRequest);
|
||||
|
||||
if (auth != null)
|
||||
{
|
||||
|
||||
21
MediaBrowser.Controller/Net/SecurityException.cs
Normal file
21
MediaBrowser.Controller/Net/SecurityException.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Controller.Net
|
||||
{
|
||||
public class SecurityException : Exception
|
||||
{
|
||||
public SecurityException(string message)
|
||||
: base(message)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SecurityExceptionType SecurityExceptionType { get; set; }
|
||||
}
|
||||
|
||||
public enum SecurityExceptionType
|
||||
{
|
||||
Unauthenticated = 0,
|
||||
ParentalControl = 1
|
||||
}
|
||||
}
|
||||
62
MediaBrowser.Controller/Net/ServiceStackServiceRequest.cs
Normal file
62
MediaBrowser.Controller/Net/ServiceStackServiceRequest.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using ServiceStack.Web;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace MediaBrowser.Controller.Net
|
||||
{
|
||||
public class ServiceStackServiceRequest : IServiceRequest
|
||||
{
|
||||
private readonly IRequest _request;
|
||||
|
||||
public ServiceStackServiceRequest(IRequest request)
|
||||
{
|
||||
_request = request;
|
||||
}
|
||||
|
||||
public object OriginalRequest
|
||||
{
|
||||
get { return _request; }
|
||||
}
|
||||
|
||||
public string RemoteIp
|
||||
{
|
||||
get { return _request.RemoteIp; }
|
||||
}
|
||||
|
||||
private NameValueCollection _headers;
|
||||
public NameValueCollection Headers
|
||||
{
|
||||
get { return _headers ?? (_headers = Get(_request.Headers)); }
|
||||
}
|
||||
|
||||
private NameValueCollection _query;
|
||||
public NameValueCollection QueryString
|
||||
{
|
||||
get { return _query ?? (_query = Get(_request.QueryString)); }
|
||||
}
|
||||
|
||||
private NameValueCollection Get(INameValueCollection coll)
|
||||
{
|
||||
var nv = new NameValueCollection(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (var key in coll.AllKeys)
|
||||
{
|
||||
nv[key] = coll[key];
|
||||
}
|
||||
|
||||
return nv;
|
||||
//return coll.ToNameValueCollection();
|
||||
}
|
||||
|
||||
public IDictionary<string, object> Items
|
||||
{
|
||||
get { return _request.Items; }
|
||||
}
|
||||
|
||||
public void AddResponseHeader(string name, string value)
|
||||
{
|
||||
_request.Response.AddHeader(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user