diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 3b9ea41219..4fd08258af 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -231,7 +231,10 @@ namespace Emby.Server.Implementations } } - public IServiceProvider ServiceProvider; + /// + /// Gets or sets the service provider. + /// + public IServiceProvider ServiceProvider { get; set; } /// /// Gets the server configuration manager. @@ -835,7 +838,7 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(authContext); serviceCollection.AddSingleton(new SessionContext(UserManager, authContext, SessionManager)); - AuthService = new AuthService(LoggerFactory, authContext, ServerConfigurationManager, SessionManager, NetworkManager); + AuthService = new AuthService(LoggerFactory.CreateLogger(), authContext, ServerConfigurationManager, SessionManager, NetworkManager); serviceCollection.AddSingleton(AuthService); SubtitleEncoder = new MediaBrowser.MediaEncoding.Subtitles.SubtitleEncoder(LibraryManager, LoggerFactory, ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer, HttpClient, MediaSourceManager, ProcessFactory); diff --git a/Emby.Server.Implementations/HttpServer/Security/AuthService.cs b/Emby.Server.Implementations/HttpServer/Security/AuthService.cs index 81dab83d5e..594f464989 100644 --- a/Emby.Server.Implementations/HttpServer/Security/AuthService.cs +++ b/Emby.Server.Implementations/HttpServer/Security/AuthService.cs @@ -22,13 +22,13 @@ namespace Emby.Server.Implementations.HttpServer.Security private readonly INetworkManager _networkManager; public AuthService( - ILoggerFactory loggerFactory, + ILogger logger, IAuthorizationContext authorizationContext, IServerConfigurationManager config, ISessionManager sessionManager, INetworkManager networkManager) { - _logger = loggerFactory.CreateLogger(); + _logger = logger; _authorizationContext = authorizationContext; _config = config; _sessionManager = sessionManager; diff --git a/Jellyfin.Api/Auth/CustomAuthenticationHandler.cs b/Jellyfin.Api/Auth/CustomAuthenticationHandler.cs index a753d60838..6ca992c61b 100644 --- a/Jellyfin.Api/Auth/CustomAuthenticationHandler.cs +++ b/Jellyfin.Api/Auth/CustomAuthenticationHandler.cs @@ -1,7 +1,7 @@ using System.Security.Claims; using System.Text.Encodings.Web; using System.Threading.Tasks; -using Jellyfin.Api.Enums; +using Jellyfin.Api.Constants; using MediaBrowser.Controller.Net; using Microsoft.AspNetCore.Authentication; using Microsoft.Extensions.Logging; @@ -51,7 +51,7 @@ namespace Jellyfin.Api.Auth new Claim(ClaimTypes.Name, user.Name), new Claim( ClaimTypes.Role, - value: user.Policy.IsAdministrator ? UserRole.Administrator.ToString() : UserRole.User.ToString()) + value: user.Policy.IsAdministrator ? UserRole.Administrator : UserRole.User) }; var identity = new ClaimsIdentity(claims, Scheme.Name); var principal = new ClaimsPrincipal(identity); diff --git a/Jellyfin.Api/Auth/FirstTimeSetupOrElevatedPolicy/FirstTimeSetupOrElevatedHandler.cs b/Jellyfin.Api/Auth/FirstTimeSetupOrElevatedPolicy/FirstTimeSetupOrElevatedHandler.cs index f07e568dea..2450e7bc73 100644 --- a/Jellyfin.Api/Auth/FirstTimeSetupOrElevatedPolicy/FirstTimeSetupOrElevatedHandler.cs +++ b/Jellyfin.Api/Auth/FirstTimeSetupOrElevatedPolicy/FirstTimeSetupOrElevatedHandler.cs @@ -1,5 +1,5 @@ using System.Threading.Tasks; -using Jellyfin.Api.Enums; +using Jellyfin.Api.Constants; using MediaBrowser.Common.Configuration; using Microsoft.AspNetCore.Authorization; @@ -28,7 +28,7 @@ namespace Jellyfin.Api.Auth.FirstTimeSetupOrElevatedPolicy { context.Succeed(firstTimeSetupOrElevatedRequirement); } - else if (context.User.IsInRole(UserRole.Administrator.ToString())) + else if (context.User.IsInRole(UserRole.Administrator)) { context.Succeed(firstTimeSetupOrElevatedRequirement); } diff --git a/Jellyfin.Api/Auth/RequiresElevationPolicy/RequiresElevationHandler.cs b/Jellyfin.Api/Auth/RequiresElevationPolicy/RequiresElevationHandler.cs index 8674f3e262..108c29a2cc 100644 --- a/Jellyfin.Api/Auth/RequiresElevationPolicy/RequiresElevationHandler.cs +++ b/Jellyfin.Api/Auth/RequiresElevationPolicy/RequiresElevationHandler.cs @@ -1,5 +1,5 @@ using System.Threading.Tasks; -using Jellyfin.Api.Enums; +using Jellyfin.Api.Constants; using Microsoft.AspNetCore.Authorization; namespace Jellyfin.Api.Auth.RequiresElevationPolicy @@ -12,7 +12,7 @@ namespace Jellyfin.Api.Auth.RequiresElevationPolicy /// protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, RequiresElevationRequirement requirement) { - if (context.User.IsInRole(UserRole.Administrator.ToString())) + if (context.User.IsInRole(UserRole.Administrator)) { context.Succeed(requirement); } diff --git a/Jellyfin.Api/Enums/UserRole.cs b/Jellyfin.Api/Constants/UserRole.cs similarity index 51% rename from Jellyfin.Api/Enums/UserRole.cs rename to Jellyfin.Api/Constants/UserRole.cs index 05826d9f41..b1da615575 100644 --- a/Jellyfin.Api/Enums/UserRole.cs +++ b/Jellyfin.Api/Constants/UserRole.cs @@ -1,23 +1,23 @@ -namespace Jellyfin.Api.Enums +namespace Jellyfin.Api.Constants { /// - /// Enum for user roles used in the authentication and authorization for the API. + /// Constants for user roles used in the authentication and authorization for the API. /// - public enum UserRole + public static class UserRole { /// /// Guest user. /// - Guest = 0, + public const string Guest = "Guest"; /// /// Regular user with no special privileges. /// - User = 1, + public const string User = "User"; /// /// Administrator user with elevated privileges. /// - Administrator = 2 + public const string Administrator = "Administrator"; } } diff --git a/Jellyfin.Api/Jellyfin.Api.csproj b/Jellyfin.Api/Jellyfin.Api.csproj index 1cc23c07b4..6ad97b60f3 100644 --- a/Jellyfin.Api/Jellyfin.Api.csproj +++ b/Jellyfin.Api/Jellyfin.Api.csproj @@ -19,7 +19,7 @@ - +