New: Update Nancy to 2.0

This commit is contained in:
ta264 2019-09-12 21:32:51 +01:00
commit 17c9fc419c
44 changed files with 266 additions and 266 deletions

View file

@ -1,12 +1,12 @@
using System;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
using Nancy;
using Nancy.Authentication.Basic;
using Nancy.Authentication.Forms;
using Nancy.Security;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Core.Authentication;
using NzbDrone.Core.Configuration;
using Lidarr.Http.Extensions;
@ -26,9 +26,8 @@ namespace Lidarr.Http.Authentication
public class AuthenticationService : IAuthenticationService
{
private static readonly Logger _authLogger = LogManager.GetLogger("Auth");
private static readonly NzbDroneUser AnonymousUser = new NzbDroneUser { UserName = "Anonymous" };
private const string AnonymousUser = "Anonymous";
private readonly IUserService _userService;
private readonly NancyContext _nancyContext;
private static string API_KEY;
private static AuthenticationType AUTH_METHOD;
@ -36,10 +35,9 @@ namespace Lidarr.Http.Authentication
[ThreadStatic]
private static NancyContext _context;
public AuthenticationService(IConfigFileProvider configFileProvider, IUserService userService, NancyContext nancyContext)
public AuthenticationService(IConfigFileProvider configFileProvider, IUserService userService)
{
_userService = userService;
_nancyContext = nancyContext;
API_KEY = configFileProvider.ApiKey;
AUTH_METHOD = configFileProvider.AuthenticationMethod;
}
@ -80,15 +78,15 @@ namespace Lidarr.Http.Authentication
if (context.CurrentUser != null)
{
LogLogout(context, context.CurrentUser.UserName);
LogLogout(context, context.CurrentUser.Identity.Name);
}
}
public IUserIdentity Validate(string username, string password)
public ClaimsPrincipal Validate(string username, string password)
{
if (AUTH_METHOD == AuthenticationType.None)
{
return AnonymousUser;
return new ClaimsPrincipal(new GenericIdentity(AnonymousUser));
}
var user = _userService.FindUser(username, password);
@ -101,7 +99,7 @@ namespace Lidarr.Http.Authentication
LogSuccess(_context, username);
}
return new NzbDroneUser { UserName = user.Username };
return new ClaimsPrincipal(new GenericIdentity(user.Username));
}
LogFailure(_context, username);
@ -109,18 +107,18 @@ namespace Lidarr.Http.Authentication
return null;
}
public IUserIdentity GetUserFromIdentifier(Guid identifier, NancyContext context)
public ClaimsPrincipal GetUserFromIdentifier(Guid identifier, NancyContext context)
{
if (AUTH_METHOD == AuthenticationType.None)
{
return AnonymousUser;
return new ClaimsPrincipal(new GenericIdentity(AnonymousUser));
}
var user = _userService.FindUser(identifier);
if (user != null)
{
return new NzbDroneUser { UserName = user.Username };
return new ClaimsPrincipal(new GenericIdentity(user.Username));
}
LogInvalidated(_context);