mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 05:53:33 -07:00
Cleaned up auth settings
This commit is contained in:
parent
e046d2c680
commit
0c5827fb41
11 changed files with 112 additions and 105 deletions
|
@ -1,14 +1,12 @@
|
|||
using Nancy.Authentication.Basic;
|
||||
using Nancy.Security;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Model;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace NzbDrone.Api.Authentication
|
||||
{
|
||||
public interface IAuthenticationService : IUserValidator
|
||||
{
|
||||
AuthenticationType AuthenticationType { get; }
|
||||
bool Enabled { get; }
|
||||
}
|
||||
|
||||
public class AuthenticationService : IAuthenticationService
|
||||
|
@ -22,25 +20,29 @@ namespace NzbDrone.Api.Authentication
|
|||
_configFileProvider = configFileProvider;
|
||||
}
|
||||
|
||||
public AuthenticationType AuthenticationType
|
||||
{
|
||||
get { return _configFileProvider.AuthenticationType; }
|
||||
}
|
||||
|
||||
public IUserIdentity Validate(string username, string password)
|
||||
{
|
||||
if (AuthenticationType == AuthenticationType.Anonymous)
|
||||
if (!Enabled)
|
||||
{
|
||||
return AnonymousUser;
|
||||
}
|
||||
|
||||
if (_configFileProvider.BasicAuthUsername.Equals(username) &&
|
||||
_configFileProvider.BasicAuthPassword.Equals(password))
|
||||
if (_configFileProvider.Username.Equals(username) &&
|
||||
_configFileProvider.Password.Equals(password))
|
||||
{
|
||||
return new NzbDroneUser { UserName = username };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _configFileProvider.AuthenticationEnabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using Nancy;
|
||||
using Nancy.Authentication.Basic;
|
||||
using Nancy.Bootstrapper;
|
||||
using NzbDrone.Common.Model;
|
||||
|
||||
namespace NzbDrone.Api.Authentication
|
||||
{
|
||||
|
@ -28,7 +27,7 @@ namespace NzbDrone.Api.Authentication
|
|||
private Response RequiresAuthentication(NancyContext context)
|
||||
{
|
||||
Response response = null;
|
||||
if (context.CurrentUser == null && _authenticationService.AuthenticationType != AuthenticationType.Anonymous)
|
||||
if (context.CurrentUser == null && _authenticationService.Enabled)
|
||||
{
|
||||
response = new Response { StatusCode = HttpStatusCode.Unauthorized };
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue