Exemplo n.º 1
0
        public async Task <bool> IsEnabledAsync(PermissionDefinition permission)
        {
            using (var scope = ServiceProvider.CreateScope())
            {
                var context = new PermissionStateContext
                {
                    Permission      = permission,
                    ServiceProvider = scope.ServiceProvider.GetRequiredService <ICachedServiceProvider>()
                };

                foreach (var provider in permission.StateProviders)
                {
                    if (!await provider.IsEnabledAsync(context))
                    {
                        return(false);
                    }
                }

                foreach (IPermissionStateProvider provider in Options.GlobalStateProviders.Select(x => ServiceProvider.GetRequiredService(x)))
                {
                    if (!await provider.IsEnabledAsync(context))
                    {
                        return(false);
                    }
                }

                return(true);
            }
        }
        public PermissionValueCheckContext([NotNull] PermissionDefinition permission, [CanBeNull] ClaimsPrincipal principal)
        {
            Check.NotNull(permission, nameof(permission));

            Permission = permission;
            Principal  = principal;
        }
        public static PermissionDefinition AddStateProviders(
            [NotNull] this PermissionDefinition permissionDefinition,
            [NotNull] params IPermissionStateProvider[] permissionStateProviders)
        {
            Check.NotNull(permissionDefinition, nameof(permissionDefinition));
            Check.NotNull(permissionStateProviders, nameof(permissionStateProviders));

            permissionDefinition.StateProviders.AddRange(permissionStateProviders);

            return(permissionDefinition);
        }
Exemplo n.º 4
0
        protected virtual void AddPermissionToDictionaryRecursively(
            Dictionary <string, PermissionDefinition> permissions,
            PermissionDefinition permission)
        {
            if (permissions.ContainsKey(permission.Name))
            {
                throw new AbpException("Duplicate permission name: " + permission.Name);
            }

            permissions[permission.Name] = permission;

            foreach (var child in permission.Children)
            {
                AddPermissionToDictionaryRecursively(permissions, child);
            }
        }