Fix more review comments
This commit is contained in:
parent
2af5922af0
commit
47a4f2f387
|
@ -236,6 +236,21 @@ namespace Emby.Server.Implementations
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IServiceProvider ServiceProvider { get; set; }
|
public IServiceProvider ServiceProvider { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the http port for the webhost.
|
||||||
|
/// </summary>
|
||||||
|
public int HttpPort { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the https port for the webhost.
|
||||||
|
/// </summary>
|
||||||
|
public int HttpsPort { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the content root for the webhost.
|
||||||
|
/// </summary>
|
||||||
|
public string ContentRoot { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the server configuration manager.
|
/// Gets the server configuration manager.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1604,12 +1619,6 @@ namespace Emby.Server.Implementations
|
||||||
? Environment.MachineName
|
? Environment.MachineName
|
||||||
: ServerConfigurationManager.Configuration.ServerName;
|
: ServerConfigurationManager.Configuration.ServerName;
|
||||||
|
|
||||||
public int HttpPort { get; private set; }
|
|
||||||
|
|
||||||
public int HttpsPort { get; private set; }
|
|
||||||
|
|
||||||
public string ContentRoot { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Shuts down.
|
/// Shuts down.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -51,7 +51,7 @@ namespace Jellyfin.Api.Auth
|
||||||
new Claim(ClaimTypes.Name, user.Name),
|
new Claim(ClaimTypes.Name, user.Name),
|
||||||
new Claim(
|
new Claim(
|
||||||
ClaimTypes.Role,
|
ClaimTypes.Role,
|
||||||
value: user.Policy.IsAdministrator ? UserRole.Administrator : UserRole.User)
|
value: user.Policy.IsAdministrator ? UserRoles.Administrator : UserRoles.User)
|
||||||
};
|
};
|
||||||
var identity = new ClaimsIdentity(claims, Scheme.Name);
|
var identity = new ClaimsIdentity(claims, Scheme.Name);
|
||||||
var principal = new ClaimsPrincipal(identity);
|
var principal = new ClaimsPrincipal(identity);
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace Jellyfin.Api.Auth.FirstTimeSetupOrElevatedPolicy
|
||||||
{
|
{
|
||||||
context.Succeed(firstTimeSetupOrElevatedRequirement);
|
context.Succeed(firstTimeSetupOrElevatedRequirement);
|
||||||
}
|
}
|
||||||
else if (context.User.IsInRole(UserRole.Administrator))
|
else if (context.User.IsInRole(UserRoles.Administrator))
|
||||||
{
|
{
|
||||||
context.Succeed(firstTimeSetupOrElevatedRequirement);
|
context.Succeed(firstTimeSetupOrElevatedRequirement);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace Jellyfin.Api.Auth.RequiresElevationPolicy
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, RequiresElevationRequirement requirement)
|
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, RequiresElevationRequirement requirement)
|
||||||
{
|
{
|
||||||
if (context.User.IsInRole(UserRole.Administrator))
|
if (context.User.IsInRole(UserRoles.Administrator))
|
||||||
{
|
{
|
||||||
context.Succeed(requirement);
|
context.Succeed(requirement);
|
||||||
}
|
}
|
||||||
|
|
13
Jellyfin.Api/Constants/AuthenticationSchemes.cs
Normal file
13
Jellyfin.Api/Constants/AuthenticationSchemes.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
namespace Jellyfin.Api.Constants
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Authentication schemes for user authentication in the API.
|
||||||
|
/// </summary>
|
||||||
|
public static class AuthenticationSchemes
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Scheme name for the custom legacy authentication.
|
||||||
|
/// </summary>
|
||||||
|
public const string CustomAuthentication = "CustomAuthentication";
|
||||||
|
}
|
||||||
|
}
|
18
Jellyfin.Api/Constants/Policies.cs
Normal file
18
Jellyfin.Api/Constants/Policies.cs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
namespace Jellyfin.Api.Constants
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Policies for the API authorization.
|
||||||
|
/// </summary>
|
||||||
|
public static class Policies
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Policy name for requiring first time setup or elevated privileges.
|
||||||
|
/// </summary>
|
||||||
|
public const string FirstTimeSetupOrElevated = "FirstTimeOrElevated";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Policy name for requiring elevated privileges.
|
||||||
|
/// </summary>
|
||||||
|
public const string RequiresElevation = "RequiresElevation";
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ namespace Jellyfin.Api.Constants
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constants 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class UserRole
|
public static class UserRoles
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Guest user.
|
/// Guest user.
|
|
@ -1,5 +1,6 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Api.Constants;
|
||||||
using Jellyfin.Api.Models.StartupDtos;
|
using Jellyfin.Api.Models.StartupDtos;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
|
@ -11,7 +12,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The startup wizard controller.
|
/// The startup wizard controller.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize(Policy = "FirstTimeSetupOrElevated")]
|
[Authorize(Policy = Policies.FirstTimeSetupOrElevated)]
|
||||||
public class StartupController : BaseJellyfinApiController
|
public class StartupController : BaseJellyfinApiController
|
||||||
{
|
{
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
<!-- Code analysers-->
|
<!-- Code analysers-->
|
||||||
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.7" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.7" PrivateAssets="All" />
|
||||||
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" />
|
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
|
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
|
||||||
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" />
|
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
|
|
|
@ -2,6 +2,7 @@ using Jellyfin.Api;
|
||||||
using Jellyfin.Api.Auth;
|
using Jellyfin.Api.Auth;
|
||||||
using Jellyfin.Api.Auth.FirstTimeSetupOrElevatedPolicy;
|
using Jellyfin.Api.Auth.FirstTimeSetupOrElevatedPolicy;
|
||||||
using Jellyfin.Api.Auth.RequiresElevationPolicy;
|
using Jellyfin.Api.Auth.RequiresElevationPolicy;
|
||||||
|
using Jellyfin.Api.Constants;
|
||||||
using Jellyfin.Api.Controllers;
|
using Jellyfin.Api.Controllers;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
@ -27,17 +28,17 @@ namespace Jellyfin.Server.Extensions
|
||||||
return serviceCollection.AddAuthorizationCore(options =>
|
return serviceCollection.AddAuthorizationCore(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy(
|
options.AddPolicy(
|
||||||
"RequiresElevation",
|
Policies.RequiresElevation,
|
||||||
policy =>
|
policy =>
|
||||||
{
|
{
|
||||||
policy.AddAuthenticationSchemes("CustomAuthentication");
|
policy.AddAuthenticationSchemes(AuthenticationSchemes.CustomAuthentication);
|
||||||
policy.AddRequirements(new RequiresElevationRequirement());
|
policy.AddRequirements(new RequiresElevationRequirement());
|
||||||
});
|
});
|
||||||
options.AddPolicy(
|
options.AddPolicy(
|
||||||
"FirstTimeSetupOrElevated",
|
Policies.FirstTimeSetupOrElevated,
|
||||||
policy =>
|
policy =>
|
||||||
{
|
{
|
||||||
policy.AddAuthenticationSchemes("CustomAuthentication");
|
policy.AddAuthenticationSchemes(AuthenticationSchemes.CustomAuthentication);
|
||||||
policy.AddRequirements(new FirstTimeSetupOrElevatedRequirement());
|
policy.AddRequirements(new FirstTimeSetupOrElevatedRequirement());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -50,8 +51,8 @@ namespace Jellyfin.Server.Extensions
|
||||||
/// <returns>The updated service collection.</returns>
|
/// <returns>The updated service collection.</returns>
|
||||||
public static AuthenticationBuilder AddCustomAuthentication(this IServiceCollection serviceCollection)
|
public static AuthenticationBuilder AddCustomAuthentication(this IServiceCollection serviceCollection)
|
||||||
{
|
{
|
||||||
return serviceCollection.AddAuthentication("CustomAuthentication")
|
return serviceCollection.AddAuthentication(AuthenticationSchemes.CustomAuthentication)
|
||||||
.AddScheme<AuthenticationSchemeOptions, CustomAuthenticationHandler>("CustomAuthentication", null);
|
.AddScheme<AuthenticationSchemeOptions, CustomAuthenticationHandler>(AuthenticationSchemes.CustomAuthentication, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user