|
@@ -1,5 +1,4 @@
|
|
-using System.Collections.Generic;
|
|
|
|
-using MediaBrowser.Controller.Configuration;
|
|
|
|
|
|
+using MediaBrowser.Controller.Configuration;
|
|
using MediaBrowser.Controller.Library;
|
|
using MediaBrowser.Controller.Library;
|
|
using MediaBrowser.Controller.Net;
|
|
using MediaBrowser.Controller.Net;
|
|
using MediaBrowser.Controller.Session;
|
|
using MediaBrowser.Controller.Session;
|
|
@@ -45,8 +44,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
|
|
public void Authenticate(IRequest request,
|
|
public void Authenticate(IRequest request,
|
|
IResponse response,
|
|
IResponse response,
|
|
object requestDto,
|
|
object requestDto,
|
|
- bool allowLocal,
|
|
|
|
- string[] roles)
|
|
|
|
|
|
+ IAuthenticated authAttribtues)
|
|
{
|
|
{
|
|
if (HostContext.HasValidAuthSecret(request))
|
|
if (HostContext.HasValidAuthSecret(request))
|
|
return;
|
|
return;
|
|
@@ -54,16 +52,15 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
|
|
//ExecuteBasic(req, res, requestDto); //first check if session is authenticated
|
|
//ExecuteBasic(req, res, requestDto); //first check if session is authenticated
|
|
//if (res.IsClosed) return; //AuthenticateAttribute already closed the request (ie auth failed)
|
|
//if (res.IsClosed) return; //AuthenticateAttribute already closed the request (ie auth failed)
|
|
|
|
|
|
- ValidateUser(request, allowLocal, roles);
|
|
|
|
|
|
+ ValidateUser(request, response, authAttribtues);
|
|
}
|
|
}
|
|
|
|
|
|
- private void ValidateUser(IRequest req, bool allowLocal,
|
|
|
|
- IEnumerable<string> roles)
|
|
|
|
|
|
+ private void ValidateUser(IRequest req, IResponse response, IAuthenticated authAttribtues)
|
|
{
|
|
{
|
|
// This code is executed before the service
|
|
// This code is executed before the service
|
|
var auth = AuthorizationContext.GetAuthorizationInfo(req);
|
|
var auth = AuthorizationContext.GetAuthorizationInfo(req);
|
|
|
|
|
|
- if (!allowLocal || !req.IsLocal)
|
|
|
|
|
|
+ if (!authAttribtues.AllowLocal || !req.IsLocal)
|
|
{
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(auth.Token) ||
|
|
if (!string.IsNullOrWhiteSpace(auth.Token) ||
|
|
!_config.Configuration.InsecureApps2.Contains(auth.Client ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
|
!_config.Configuration.InsecureApps2.Contains(auth.Client ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
|
@@ -91,12 +88,17 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
|
|
throw new AuthenticationException("User account has been disabled.");
|
|
throw new AuthenticationException("User account has been disabled.");
|
|
}
|
|
}
|
|
|
|
|
|
- if (!user.Configuration.IsAdministrator && !user.IsParentalScheduleAllowed())
|
|
|
|
|
|
+ if (!user.Configuration.IsAdministrator &&
|
|
|
|
+ !authAttribtues.EscapeParentalControl &&
|
|
|
|
+ !user.IsParentalScheduleAllowed())
|
|
{
|
|
{
|
|
|
|
+ response.AddHeader("X-Application-Error-Code", "ParentalControl");
|
|
throw new AuthenticationException("This user account is not allowed access at this time.");
|
|
throw new AuthenticationException("This user account is not allowed access at this time.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ var roles = authAttribtues.GetRoles().ToList();
|
|
|
|
+
|
|
if (roles.Contains("admin", StringComparer.OrdinalIgnoreCase))
|
|
if (roles.Contains("admin", StringComparer.OrdinalIgnoreCase))
|
|
{
|
|
{
|
|
if (user == null || !user.Configuration.IsAdministrator)
|
|
if (user == null || !user.Configuration.IsAdministrator)
|