Ejemplo 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);
        }
Ejemplo 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));
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo 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);
            }
        }
Ejemplo 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);
        }
Ejemplo n.º 8
0
 public abstract Task <PermissionGrantResult> CheckAsync(PermissionValueCheckContext context);
 public abstract Task <PermissionValueProviderGrantInfo> CheckAsync(PermissionValueCheckContext context);