Open TheTrigger opened 4 years ago
What I did is the following:
Added this to ValidateUserAsync claimList.AddRange(user.Roles.Select(x => new Claim(ClaimTypes.Role, x.ToString())).ToList());
And then added Custom Command Handler with this at the start:
if (!this.Data.FtpUser.Claims.Any(x => x.Value == User.Roles.role_one.ToString().ToLower()) &&
!this.Data.FtpUser.Claims.Any(x => x.Value == User.Roles.role_two.ToString().ToLower())
)
{
throw new Exception("Not Allowed...");
}
Sorry, I don't mean how to authorize a user, but how to setup witch commands that user could call.
I would like to have two users, one read-write
, and another read-only
, any ideas? ty
That is exactly what I explained. Add specific role and check for it in a custom Controller ( i.e. CustomSTORController for disallowing write permission ).
Sorry, I don't get it, I should be able to do this from CustomMembershipProvider
so set the rights claims for MemberValidationResult
...(?) I'm lost
Same issue
You can override the commands you want to control by creating and registering your own. Your commands take precedence. The samples show how to do this command registration.
In my case, i'm checking roles to create folders:
[FtpCommandHandler("MKD")]
public class MkdCommandHandler : FtpCommandHandler
{
public override Task<IFtpResponse> Process(FtpCommand command, CancellationToken cancellationToken)
{
var user = CommandContext.FtpContext.Connection.Features.Get<IAuthorizationInformationFeature>().FtpUser;
var roles = Startup.Settings.Roles;
foreach (var claim in user.Claims)
{
var role = roles.FirstOrDefault(r => r.Name == claim.Value);
if(role?.CanCreateFolder == true)
{
FubarDev.FtpServer.CommandHandlers.MkdCommandHandler mkdCommandHandler = new()
{
CommandContext = this.CommandContext
};
return mkdCommandHandler.Process(command, cancellationToken);
}
}
return Task.FromResult<IFtpResponse>(new FtpResponse(502, $"Not allowed!"));
}
}
How could I make a user be read-only on the filesystem? Working on aspnetcore 3.1
I have te code from the example:
thanks