Ejemplo n.º 1
0
        /// <summary>
        /// 权限判断
        /// 当资源未在资源表里时,不允许访问
        /// </summary>
        /// <param name="resourceKey"></param>
        /// <param name="userKey"></param>
        /// <returns></returns>
        public virtual bool HasPermission(string resourceKey, string userKey)
        {
            var userRoleKeys = _permissionStore.GetAllUserRole().Where(a => a.GetUserKey() == userKey).Select(a => a.GetRoleKey());
            var resource     = _permissionStore.GetAllResource().FirstOrDefault(a => a.GetKey() == resourceKey);

            //未纳入到资源表里的资源,如果进入到鉴权过程时,不允许访问。请将不需要做权限控制的资源设置成允许匿名访问,避免进入到鉴权流程
            if (resource == null)
            {
                return(false);
            }
            var resourceRoleKeys = _permissionStore.GetAllRoleResource().Where(a => a.GetResourceKey() == resource.GetKey()).Select(a => a.GetRoleKey());

            return(userRoleKeys.Intersect(resourceRoleKeys).Any());
        }
Ejemplo n.º 2
0
        public PermissionRoleResourceInfo GetRoleResources(string roleKey)
        {
            var roleResourceKeys = _permissionStore.GetAllRoleResource().Where(a => a.GetRoleKey() == roleKey).Select(a => a.GetResourceKey()).Distinct().ToList();

            return(new PermissionRoleResourceInfo
            {
                RoleKey = roleKey,
                ResourceKeys = roleResourceKeys
            });
        }