2013-05-22 05:55:53 +00:00
|
|
|
|
using Nancy.Authentication.Basic;
|
2013-05-22 00:58:57 +00:00
|
|
|
|
using Nancy.Security;
|
|
|
|
|
using NzbDrone.Common;
|
2013-05-22 05:55:53 +00:00
|
|
|
|
using NzbDrone.Common.Model;
|
2013-05-22 00:58:57 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Authentication
|
|
|
|
|
{
|
|
|
|
|
public class AuthenticationValidator : IUserValidator
|
|
|
|
|
{
|
|
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
|
|
|
|
|
|
|
|
|
public AuthenticationValidator(IConfigFileProvider configFileProvider)
|
|
|
|
|
{
|
|
|
|
|
_configFileProvider = configFileProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IUserIdentity Validate(string username, string password)
|
|
|
|
|
{
|
2013-05-22 05:55:53 +00:00
|
|
|
|
if (_configFileProvider.AuthenticationType == AuthenticationType.Anonymous)
|
|
|
|
|
{
|
|
|
|
|
return new NzbDroneUser { UserName = "Anonymous" };
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-22 00:58:57 +00:00
|
|
|
|
if (_configFileProvider.BasicAuthUsername.Equals(username) &&
|
|
|
|
|
_configFileProvider.BasicAuthPassword.Equals(password))
|
|
|
|
|
{
|
2013-05-22 05:55:53 +00:00
|
|
|
|
return new NzbDroneUser { UserName = username };
|
2013-05-22 00:58:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|