Cleaned up auth settings

This commit is contained in:
kay.one 2013-07-14 00:00:50 -07:00
commit 0c5827fb41
11 changed files with 112 additions and 105 deletions

View file

@ -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;
}
}
}
}

View file

@ -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 };
}