Esempio n. 1
0
        public virtual async Task <bool> IsGrantedAsync(ClaimsPrincipal claimsPrincipal, string name)
        {
            Check.NotNull(name, nameof(name));

            var isGranted = false;

            var permission = PermissionDefinitionManager.Get(name);
            var context    = new PermissionValueCheckContext(permission, 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 == PermissionGrantResult.Granted)
                {
                    isGranted = true;
                }
                else if (result == PermissionGrantResult.Prohibited)
                {
                    return(false);
                }
            }

            return(isGranted);
        }
Esempio n. 2
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));
        }
Esempio n. 3
0
        public override async Task <PermissionGrantResult> CheckAsync(PermissionValueCheckContext context)
        {
            var userId = context.Principal?.FindFirst(AbpClaimTypes.UserId)?.Value;

            if (userId == null)
            {
                return(PermissionGrantResult.Undefined);
            }

            return(await PermissionStore.IsGrantedAsync(context.Permission.Name, Name, userId)
                ? PermissionGrantResult.Granted
                : PermissionGrantResult.Undefined);
        }
Esempio n. 4
0
        public virtual async Task <bool> IsGrantedAsync(
            ClaimsPrincipal claimsPrincipal,
            string name)
        {
            Check.NotNull(name, nameof(name));

            var permission = PermissionDefinitionManager.Get(name);

            if (!permission.IsEnabled)
            {
                return(false);
            }

            if (!await StateCheckerManager.IsEnabledAsync(permission))
            {
                return(false);
            }

            var multiTenancySide = claimsPrincipal?.GetMultiTenancySide()
                                   ?? CurrentTenant.GetMultiTenancySide();

            if (!permission.MultiTenancySide.HasFlag(multiTenancySide))
            {
                return(false);
            }

            var isGranted = false;
            var context   = new PermissionValueCheckContext(permission, claimsPrincipal);

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

                var result = await provider.CheckAsync(context);

                if (result == PermissionGrantResult.Granted)
                {
                    isGranted = true;
                }
                else if (result == PermissionGrantResult.Prohibited)
                {
                    return(false);
                }
            }

            return(isGranted);
        }
        public override async Task <PermissionValueProviderGrantInfo> CheckAsync(PermissionValueCheckContext context)
        {
            var clientId = context.Principal?.FindFirst(AbpClaimTypes.ClientId)?.Value;

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

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

            return(PermissionValueProviderGrantInfo.NonGranted);
        }
Esempio n. 6
0
        public async override Task <PermissionGrantResult> CheckAsync(PermissionValueCheckContext context)
        {
            var clientId = context.Principal?.FindFirst(AbpClaimTypes.ClientId)?.Value;

            if (clientId == null)
            {
                return(PermissionGrantResult.Undefined);
            }

            using (CurrentTenant.Change(null))
            {
                return(await PermissionStore.IsGrantedAsync(context.Permission.Name, Name, clientId)
                    ? PermissionGrantResult.Granted
                    : PermissionGrantResult.Undefined);
            }
        }
Esempio n. 7
0
        public override async Task <PermissionGrantResult> CheckAsync(PermissionValueCheckContext context)
        {
            var roles = context.Principal?.FindAll(AbpClaimTypes.Role).Select(c => c.Value).ToArray();

            if (roles == null || !roles.Any())
            {
                return(PermissionGrantResult.Undefined);
            }

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

            return(PermissionGrantResult.Undefined);
        }
Esempio n. 8
0
 public abstract Task <PermissionGrantResult> CheckAsync(PermissionValueCheckContext context);
 public abstract Task <PermissionValueProviderGrantInfo> CheckAsync(PermissionValueCheckContext context);