diff options
| author | crobibero <cody@robibe.ro> | 2020-06-30 17:53:20 -0600 |
|---|---|---|
| committer | crobibero <cody@robibe.ro> | 2020-06-30 17:53:20 -0600 |
| commit | 14faebc7fe7a5a75d4d39ef0c70e6ff0106e76f3 (patch) | |
| tree | 0552309271dd0ff99c4db6f97ed0051f4d888591 /Jellyfin.Api/Auth/DownloadPolicy/DownloadHandler.cs | |
| parent | 7e94bb786432536e95f4e76ea1f8fe02dd292fef (diff) | |
| parent | d300d80479597faa4a8b6e840f6fcb1efdb63c8c (diff) | |
Merge remote-tracking branch 'upstream/api-migration' into api-livetv
Diffstat (limited to 'Jellyfin.Api/Auth/DownloadPolicy/DownloadHandler.cs')
| -rw-r--r-- | Jellyfin.Api/Auth/DownloadPolicy/DownloadHandler.cs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Jellyfin.Api/Auth/DownloadPolicy/DownloadHandler.cs b/Jellyfin.Api/Auth/DownloadPolicy/DownloadHandler.cs new file mode 100644 index 000000000..fcfa55dfe --- /dev/null +++ b/Jellyfin.Api/Auth/DownloadPolicy/DownloadHandler.cs @@ -0,0 +1,45 @@ +using System.Threading.Tasks; +using Jellyfin.Api.Auth.DefaultAuthorizationPolicy; +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Library; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; + +namespace Jellyfin.Api.Auth.DownloadPolicy +{ + /// <summary> + /// Download authorization handler. + /// </summary> + public class DownloadHandler : BaseAuthorizationHandler<DownloadRequirement> + { + /// <summary> + /// Initializes a new instance of the <see cref="DownloadHandler"/> 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 DownloadHandler( + IUserManager userManager, + INetworkManager networkManager, + IHttpContextAccessor httpContextAccessor) + : base(userManager, networkManager, httpContextAccessor) + { + } + + /// <inheritdoc /> + protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, DownloadRequirement requirement) + { + var validated = ValidateClaims(context.User); + if (validated) + { + context.Succeed(requirement); + } + else + { + context.Fail(); + } + + return Task.CompletedTask; + } + } +} |
