public override async Task <PermissionValueProviderGrantInfo> CheckAsync(PermissionValueCheckContext context)
        {
            var userId = context.Principal?.FindFirst(ClaimTypes.UserId)?.Value;

            if (userId == null)
            {
                return(PermissionValueProviderGrantInfo.NonGranted);
            }

            if (await PermissionStore.IsGrantedAsync(context.Permission.Name, Name, userId))
            {
                return(new PermissionValueProviderGrantInfo(true, userId));
            }

            return(PermissionValueProviderGrantInfo.NonGranted);
        }
        public override async Task <PermissionValueProviderGrantInfo> CheckAsync(PermissionValueCheckContext context)
        {
            var roles = context.Principal?.FindAll(ClaimTypes.Role).Select(c => c.Value).ToArray();

            if (roles == null || !roles.Any())
            {
                return(PermissionValueProviderGrantInfo.NonGranted);
            }

            foreach (var role in roles)
            {
                if (await PermissionStore.IsGrantedAsync(context.Permission.Name, Name, role))
                {
                    return(new PermissionValueProviderGrantInfo(true, role));
                }
            }

            return(PermissionValueProviderGrantInfo.NonGranted);
        }
Пример #3
0
        public virtual async Task <PermissionGrantInfo> CheckAsync(ClaimsPrincipal claimsPrincipal, string name)
        {
            Check.NotNull(name, nameof(name));

            var context = new PermissionValueCheckContext(PermissionDefinitionManager.Get(name), claimsPrincipal);

            foreach (var provider in ValueProviders)
            {
                if (context.Permission.Providers.Any() && !context.Permission.Providers.Contains(provider.Name))
                {
                    continue;
                }

                var result = await provider.CheckAsync(context);

                if (result.IsGranted)
                {
                    return(new PermissionGrantInfo(context.Permission.Name, true, provider.Name, result.ProviderKey));
                }
            }

            return(new PermissionGrantInfo(context.Permission.Name, false));
        }
Пример #4
0
 public abstract Task <PermissionValueProviderGrantInfo> CheckAsync(PermissionValueCheckContext context);