This commit is contained in:
BaronGreenback 2021-04-11 17:17:05 +01:00
parent af027b6283
commit fb7587dd84
3 changed files with 10 additions and 12 deletions

View File

@ -1,25 +1,23 @@
using System.Threading.Tasks;
using Jellyfin.Api.Auth;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Library;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
namespace Jellyfin.Api.Auth.NetworkAccessPolicy
namespace Jellyfin.Api.Auth.LocalNetworkAccessPolicy
{
/// <summary>
/// Local access handler.
/// </summary>
public class NetworkAccessHandler : BaseAuthorizationHandler<NetworkAccessRequirement>
public class LocalNetworkAccessHandler : BaseAuthorizationHandler<LocalNetworkAccessRequirement>
{
/// <summary>
/// Initializes a new instance of the <see cref="NetworkAccessHandler"/> class.
/// Initializes a new instance of the <see cref="LocalNetworkAccessHandler"/> class.
/// </summary>
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
/// <param name="networkManager">Instance of the <see cref="INetworkManager"/> interface.</param>
/// <param name="httpContextAccessor">Instance of the <see cref="IHttpContextAccessor"/> interface.</param>
public NetworkAccessHandler(
public LocalNetworkAccessHandler(
IUserManager userManager,
INetworkManager networkManager,
IHttpContextAccessor httpContextAccessor)
@ -28,7 +26,7 @@ namespace Jellyfin.Api.Auth.NetworkAccessPolicy
}
/// <inheritdoc />
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, NetworkAccessRequirement requirement)
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, LocalNetworkAccessRequirement requirement)
{
var ip = HttpContextAccessor.HttpContext?.Connection.RemoteIpAddress;

View File

@ -1,11 +1,11 @@
using Microsoft.AspNetCore.Authorization;
namespace Jellyfin.Api.Auth.NetworkAccessPolicy
namespace Jellyfin.Api.Auth.LocalNetworkAccessPolicy
{
/// <summary>
/// The local network authorization requirement.
/// </summary>
public class NetworkAccessRequirement : IAuthorizationRequirement
public class LocalNetworkAccessRequirement : IAuthorizationRequirement
{
}
}

View File

@ -15,7 +15,7 @@ using Jellyfin.Api.Auth.FirstTimeSetupOrElevatedPolicy;
using Jellyfin.Api.Auth.IgnoreParentalControlPolicy;
using Jellyfin.Api.Auth.LocalAccessOrRequiresElevationPolicy;
using Jellyfin.Api.Auth.LocalAccessPolicy;
using Jellyfin.Api.Auth.NetworkAccessPolicy;
using Jellyfin.Api.Auth.LocalNetworkAccessPolicy;
using Jellyfin.Api.Auth.RequiresElevationPolicy;
using Jellyfin.Api.Auth.SyncPlayAccessPolicy;
using Jellyfin.Api.Constants;
@ -62,7 +62,7 @@ namespace Jellyfin.Server.Extensions
serviceCollection.AddSingleton<IAuthorizationHandler, IgnoreParentalControlHandler>();
serviceCollection.AddSingleton<IAuthorizationHandler, FirstTimeOrIgnoreParentalControlSetupHandler>();
serviceCollection.AddSingleton<IAuthorizationHandler, LocalAccessHandler>();
serviceCollection.AddSingleton<IAuthorizationHandler, NetworkAccessHandler>();
serviceCollection.AddSingleton<IAuthorizationHandler, LocalNetworkAccessHandler>();
serviceCollection.AddSingleton<IAuthorizationHandler, LocalAccessOrRequiresElevationHandler>();
serviceCollection.AddSingleton<IAuthorizationHandler, RequiresElevationHandler>();
serviceCollection.AddSingleton<IAuthorizationHandler, SyncPlayAccessHandler>();
@ -164,7 +164,7 @@ namespace Jellyfin.Server.Extensions
policy =>
{
policy.AddAuthenticationSchemes(AuthenticationSchemes.CustomAuthentication);
policy.AddRequirements(new NetworkAccessRequirement());
policy.AddRequirements(new LocalNetworkAccessRequirement());
});
});
}