コード例 #1
0
        protected virtual async Task <ApplicationAuthConfigurationDto> GetAuthConfigAsync()
        {
            Logger.LogDebug("Executing AbpApplicationConfigurationAppService.GetAuthConfigAsync()");

            var authConfig = new ApplicationAuthConfigurationDto();

            var policyNames = await _abpAuthorizationPolicyProvider.GetPoliciesNamesAsync().ConfigureAwait(false);

            Logger.LogDebug($"GetPoliciesNamesAsync returns {policyNames.Count} items.");

            foreach (var policyName in policyNames)
            {
                authConfig.Policies[policyName] = true;

                Logger.LogDebug($"_authorizationService.IsGrantedAsync? {policyName}");

                if (await _authorizationService.IsGrantedAsync(policyName).ConfigureAwait(false))
                {
                    authConfig.GrantedPolicies[policyName] = true;
                }
            }

            Logger.LogDebug("Executed AbpApplicationConfigurationAppService.GetAuthConfigAsync()");

            return(authConfig);
        }
コード例 #2
0
        public async Task <ApplicationAuthConfigurationDto> GetAuthConfigAsync()
        {
            var authConfig = new ApplicationAuthConfigurationDto();


            foreach (var policyName in await _abpAuthorizationPolicyProvider.GetPoliciesNamesAsync())
            {
                authConfig.Policies[policyName] = true;

                if (await _authorizationService.IsGrantedAsync(policyName))
                {
                    authConfig.GrantedPolicies[policyName] = true;
                }
            }

            foreach (var group in _permissionDefinitionManager.GetGroups())
            {
                authConfig.Policies[group.Name] = true;


                authConfig.GrantedPolicies[group.Name] = true;
            }

            return(authConfig);
        }
コード例 #3
0
        protected virtual async Task <Func <T, bool> > BuildPredicate <T>() where T : IMenuItem
        {
            var policyNames = await _abpAuthorizationPolicyProvider.GetPoliciesNamesAsync();

            var predicate = new Func <T, bool>(m =>
                                               !m.RequiredPermissionNames.Any() || m.RequiredPermissionNames.
                                               Any(p => policyNames.Contains(p) &&
                                                   _authorizationService.IsGrantedAsync(p).GetAwaiter().GetResult()));

            return(predicate);
        }
コード例 #4
0
        protected virtual async Task <ApplicationAuthConfigurationDto> GetAuthConfig()
        {
            var authConfig = new ApplicationAuthConfigurationDto();

            foreach (var policyName in await _abpAuthorizationPolicyProvider.GetPoliciesNamesAsync())
            {
                authConfig.Policies[policyName] = true;

                if (await _authorizationService.IsGrantedAsync(policyName))
                {
                    authConfig.GrantedPolicies[policyName] = true;
                }
            }

            return(authConfig);
        }
コード例 #5
0
    protected virtual async Task <ApplicationAuthConfigurationDto> GetAuthConfigAsync()
    {
        var authConfig = new ApplicationAuthConfigurationDto();

        var policyNames = await _abpAuthorizationPolicyProvider.GetPoliciesNamesAsync();

        var abpPolicyNames   = new List <string>();
        var otherPolicyNames = new List <string>();

        foreach (var policyName in policyNames)
        {
            if (await _defaultAuthorizationPolicyProvider.GetPolicyAsync(policyName) == null && _permissionDefinitionManager.GetOrNull(policyName) != null)
            {
                abpPolicyNames.Add(policyName);
            }
            else
            {
                otherPolicyNames.Add(policyName);
            }
        }

        foreach (var policyName in otherPolicyNames)
        {
            authConfig.Policies[policyName] = true;

            if (await _authorizationService.IsGrantedAsync(policyName))
            {
                authConfig.GrantedPolicies[policyName] = true;
            }
        }

        var result = await _permissionChecker.IsGrantedAsync(abpPolicyNames.ToArray());

        foreach (var(key, value) in result.Result)
        {
            authConfig.Policies[key] = true;
            if (value == PermissionGrantResult.Granted)
            {
                authConfig.GrantedPolicies[key] = true;
            }
        }

        return(authConfig);
    }
コード例 #6
0
        public virtual async Task <GetMenuResultDto> GetListAsync()
        {
            var rootMenus = _menuRepository.Where(
                x => x.MenuType == MenuEnumType.Menu
                )
                            .OrderBy(x => x.Sort)
                            .ToList()
                            .Where(x => !x.ParentId.HasValue).ToList(); // 根节点

            var menuDtos = new List <VueMenu>();

            foreach (var menu in rootMenus)
            {
                var isGranted = await _userMenuGrantChecker.CheckAsync(_principalAccessor.Principal, menu);

                if (isGranted)
                {
                    var dto = ObjectMapper.Map <Menu, VueMenu>(menu);
                    menuDtos.Add(dto);
                    FilterChildrenMenuRecursively(menu, dto);
                }
            }

            var permissionGrants = new List <string>();
            var policyNames      = await _abpAuthorizationPolicyProvider.GetPoliciesNamesAsync();

            foreach (var policyName in policyNames)
            {
                if (await _authorizationService.IsGrantedAsync(policyName))
                {
                    permissionGrants.Add(policyName);
                }
            }

            return(new GetMenuResultDto
            {
                Menus = menuDtos,
                PermissionGrants = permissionGrants
            });
        }