|
|
|
@ -1,24 +1,28 @@
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Volo.Abp.Security.Claims;
|
|
|
|
|
using Volo.Abp.Users;
|
|
|
|
|
|
|
|
|
|
namespace Volo.Abp.Authorization.Permissions
|
|
|
|
|
{
|
|
|
|
|
public class RolePermissionValueProvider : PermissionValueProvider
|
|
|
|
|
{
|
|
|
|
|
protected ICurrentUser CurrentUser { get; }
|
|
|
|
|
|
|
|
|
|
public const string ProviderName = "Role";
|
|
|
|
|
|
|
|
|
|
public override string Name => ProviderName;
|
|
|
|
|
|
|
|
|
|
public RolePermissionValueProvider(IPermissionStore permissionStore)
|
|
|
|
|
public RolePermissionValueProvider(ICurrentUser currentUser, IPermissionStore permissionStore)
|
|
|
|
|
: base(permissionStore)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
CurrentUser = currentUser;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async Task<PermissionGrantResult> CheckAsync(PermissionValueCheckContext context)
|
|
|
|
|
{
|
|
|
|
|
var roles = context.Principal?.FindAll(AbpClaimTypes.Role).Select(c => c.Value).ToArray();
|
|
|
|
|
var roles = CurrentUser.Roles;
|
|
|
|
|
|
|
|
|
|
if (roles == null || !roles.Any())
|
|
|
|
|
{
|
|
|
|
|
return PermissionGrantResult.Undefined;
|
|
|
|
|