mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-31 16:02:29 +01:00
4da6654440
Added caching to ConfigFileProvider,
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
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; }
|
|
}
|
|
|
|
public class AuthenticationService : IAuthenticationService
|
|
{
|
|
private readonly IConfigFileProvider _configFileProvider;
|
|
private static readonly NzbDroneUser AnonymousUser = new NzbDroneUser { UserName = "Anonymous" };
|
|
|
|
|
|
public AuthenticationService(IConfigFileProvider configFileProvider)
|
|
{
|
|
_configFileProvider = configFileProvider;
|
|
}
|
|
|
|
public AuthenticationType AuthenticationType
|
|
{
|
|
get { return _configFileProvider.AuthenticationType; }
|
|
}
|
|
|
|
public IUserIdentity Validate(string username, string password)
|
|
{
|
|
if (AuthenticationType == AuthenticationType.Anonymous)
|
|
{
|
|
return AnonymousUser;
|
|
}
|
|
|
|
if (_configFileProvider.BasicAuthUsername.Equals(username) &&
|
|
_configFileProvider.BasicAuthPassword.Equals(password))
|
|
{
|
|
return new NzbDroneUser { UserName = username };
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|