file dl auth
This commit is contained in:
parent
00933170a4
commit
b7dfffc15d
5 changed files with 81 additions and 41 deletions
|
|
@ -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 ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue