Exemple #1
0
        protected async Task <bool> UserHasPermission(params Guid[] permissionIds)
        {
            if (!permissionIds.Any())
            {
                return(true);
            }

            var roleClaims = User.FindAll(c => c.Type == ClaimTypes.Role);

            foreach (var roleClaim in roleClaims)
            {
                if (Guid.TryParse(roleClaim.Value, out Guid roleId))
                {
                    var rolePermissions = await _rolePermissionsCache.GetPermissions(roleId);

                    if (permissionIds.Any(rolePermissions.Contains))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #2
0
        public async Task <IEnumerable <Guid> > GetEffectivePermissions(Guid userId)
        {
            var roleIds = (await _userRoleRepository.GetByUser(userId)).Select(ur => ur.RoleId).ToArray();

            return(await _rolePermissionsCache.GetPermissions(roleIds));
        }