diff options
| author | crobibero <cody@robibe.ro> | 2020-06-25 16:22:04 -0600 |
|---|---|---|
| committer | crobibero <cody@robibe.ro> | 2020-06-25 16:22:04 -0600 |
| commit | 18f7f5aec7eb303d7bcee8462166abbf52dc6325 (patch) | |
| tree | e9e43b0438e25ed105bce21ba0735d7e337f6b7e /Jellyfin.Api/Auth/LocalAccessPolicy/LocalAccessHandler.cs | |
| parent | 6767c47ccdede27a374ea21b3013fe32ee356f01 (diff) | |
| parent | 7bd91727791d5723e779e63b913e8650380048ce (diff) | |
Merge remote-tracking branch 'upstream/api-migration' into api-environment
Diffstat (limited to 'Jellyfin.Api/Auth/LocalAccessPolicy/LocalAccessHandler.cs')
| -rw-r--r-- | Jellyfin.Api/Auth/LocalAccessPolicy/LocalAccessHandler.cs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Jellyfin.Api/Auth/LocalAccessPolicy/LocalAccessHandler.cs b/Jellyfin.Api/Auth/LocalAccessPolicy/LocalAccessHandler.cs new file mode 100644 index 000000000..af73352bc --- /dev/null +++ b/Jellyfin.Api/Auth/LocalAccessPolicy/LocalAccessHandler.cs @@ -0,0 +1,44 @@ +using System.Threading.Tasks; +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Library; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; + +namespace Jellyfin.Api.Auth.LocalAccessPolicy +{ + /// <summary> + /// Local access handler. + /// </summary> + public class LocalAccessHandler : BaseAuthorizationHandler<LocalAccessRequirement> + { + /// <summary> + /// Initializes a new instance of the <see cref="LocalAccessHandler"/> 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 LocalAccessHandler( + IUserManager userManager, + INetworkManager networkManager, + IHttpContextAccessor httpContextAccessor) + : base(userManager, networkManager, httpContextAccessor) + { + } + + /// <inheritdoc /> + protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, LocalAccessRequirement requirement) + { + var validated = ValidateClaims(context.User, localAccessOnly: true); + if (!validated) + { + context.Fail(); + } + else + { + context.Succeed(requirement); + } + + return Task.CompletedTask; + } + } +} |
