aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/HttpServer/Security/AuthService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Server.Implementations/HttpServer/Security/AuthService.cs')
-rw-r--r--MediaBrowser.Server.Implementations/HttpServer/Security/AuthService.cs42
1 files changed, 23 insertions, 19 deletions
diff --git a/MediaBrowser.Server.Implementations/HttpServer/Security/AuthService.cs b/MediaBrowser.Server.Implementations/HttpServer/Security/AuthService.cs
index a1a68586b..dde61079b 100644
--- a/MediaBrowser.Server.Implementations/HttpServer/Security/AuthService.cs
+++ b/MediaBrowser.Server.Implementations/HttpServer/Security/AuthService.cs
@@ -1,5 +1,5 @@
-using System.Collections.Generic;
-using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Controller.Connect;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Session;
@@ -16,10 +16,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
{
private readonly IServerConfigurationManager _config;
- public AuthService(IUserManager userManager, ISessionManager sessionManager, IAuthorizationContext authorizationContext, IServerConfigurationManager config)
+ public AuthService(IUserManager userManager, ISessionManager sessionManager, IAuthorizationContext authorizationContext, IServerConfigurationManager config, IConnectManager connectManager)
{
AuthorizationContext = authorizationContext;
_config = config;
+ ConnectManager = connectManager;
SessionManager = sessionManager;
UserManager = userManager;
}
@@ -27,6 +28,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
public IUserManager UserManager { get; private set; }
public ISessionManager SessionManager { get; private set; }
public IAuthorizationContext AuthorizationContext { get; private set; }
+ public IConnectManager ConnectManager { get; private set; }
/// <summary>
/// Restrict authentication to a specific <see cref="IAuthProvider"/>.
@@ -45,8 +47,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
public void Authenticate(IRequest request,
IResponse response,
object requestDto,
- bool allowLocal,
- string[] roles)
+ IAuthenticated authAttribtues)
{
if (HostContext.HasValidAuthSecret(request))
return;
@@ -54,24 +55,22 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
//ExecuteBasic(req, res, requestDto); //first check if session is authenticated
//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
var auth = AuthorizationContext.GetAuthorizationInfo(req);
- if (!allowLocal || !req.IsLocal)
+ if (!string.IsNullOrWhiteSpace(auth.Token) ||
+ !_config.Configuration.InsecureApps6.Contains(auth.Client ?? string.Empty, StringComparer.OrdinalIgnoreCase))
{
- if (!string.IsNullOrWhiteSpace(auth.Token) ||
- !_config.Configuration.InsecureApps2.Contains(auth.Client ?? string.Empty, StringComparer.OrdinalIgnoreCase))
+ var valid = IsValidConnectKey(auth.Token);
+
+ if (!valid)
{
- if (!IsValidConnectKey(auth.Token))
- {
- SessionManager.ValidateSecurityToken(auth.Token);
- }
+ SessionManager.ValidateSecurityToken(auth.Token);
}
}
@@ -91,12 +90,17 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
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.");
}
}
+ var roles = authAttribtues.GetRoles().ToList();
+
if (roles.Contains("admin", StringComparer.OrdinalIgnoreCase))
{
if (user == null || !user.Configuration.IsAdministrator)
@@ -120,12 +124,12 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security
private bool IsValidConnectKey(string token)
{
- if (!string.IsNullOrEmpty(token))
+ if (string.IsNullOrEmpty(token))
{
- return UserManager.Users.Any(u => string.Equals(token, u.ConnectAccessKey, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(u.ConnectAccessKey));
+ return false;
}
- return false;
+ return ConnectManager.IsAuthorizationTokenValid(token);
}
protected bool DoHtmlRedirectIfConfigured(IRequest req, IResponse res, bool includeRedirectParam = false)