file dl auth

This commit is contained in:
Paul Schneider 2019-08-04 11:45:00 +02:00
commit b7dfffc15d
5 changed files with 81 additions and 41 deletions

View file

@ -1,18 +1,30 @@
using Microsoft.AspNet.Authorization;
using Yavsc.Services;
using Yavsc.ViewModels.Auth;
namespace Yavsc.AuthorizationHandlers
{
public class ViewFileHandler : AuthorizationHandler<ViewRequirement, ViewFileContext>
{
protected override void Handle(AuthorizationContext context, ViewRequirement requirement, ViewFileContext fileContext)
{
namespace Yavsc.AuthorizationHandlers {
public class ViewFileHandler : AuthorizationHandler<ViewRequirement, ViewFileContext> {
IFileSystemAuthManager _authManager;
public ViewFileHandler (IFileSystemAuthManager authManager) {
_authManager = authManager;
}
protected override void Handle (AuthorizationContext context, ViewRequirement requirement, ViewFileContext fileContext) {
// TODO file access rules
if (fileContext.Path.StartsWith("/pub/"))
context.Succeed(requirement);
if (fileContext.Path.StartsWith ("/pub/"))
context.Succeed (requirement);
else {
// TODO use "/blog/{num}/" path to link to blog access list
context.Succeed(requirement);
if (!fileContext.Path.StartsWith ("/"))
context.Fail ();
else {
var rights = _authManager.GetFilePathAccess (context.User, fileContext.Path.Substring (1));
if ((rights & FileAccessRight.Read) > 0)
context.Succeed (requirement);
else context.Fail ();
}
}
}
}