feat:权限调整

This commit is contained in:
haoxr 2021-01-11 00:10:39 +08:00
parent 1a9690b862
commit 8afa848a81
6 changed files with 65 additions and 4 deletions

View File

@ -0,0 +1,23 @@
package com.youlai.admin.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.youlai.common.core.base.BaseEntity;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@Accessors(chain = true)
public class SysPermission extends BaseEntity {
@TableId(type = IdType.AUTO)
private Long id;
private String name;
private String permission;
// 拥有资源权限角色ID集合
@TableField(exist = false)
private List<Long> roleIds;
}

View File

@ -0,0 +1,10 @@
package com.youlai.admin.pojo;
import lombok.Data;
import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class SysRolePermission {
private Long roleId;
private Long permissionId;
}

View File

@ -0,0 +1,11 @@
package com.youlai.admin.pojo.vo;
import lombok.Data;
import java.util.List;
@Data
public class PermissionVO {
List<TreeVO> permissions;
List<Long> checkedKeys;
}

View File

@ -0,0 +1,17 @@
package com.youlai.admin.pojo.vo;
import lombok.Data;
import java.util.List;
@Data
public class TreeVO {
private Long id;
private String label;
private List<TreeVO> children;
}

View File

@ -23,7 +23,7 @@ public interface AuthConstants {
/**
* Redis缓存权限规则key
*/
String RESOURCE_ROLES_KEY = "auth:resourceRoles";
String PERMISSION_RULES_KEY = "auth:permission:rules";
/**
* 黑名单token前缀

View File

@ -56,15 +56,15 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
}
// 从缓存取资源权限角色关系列表
Map<Object, Object> resourceRolesMap = redisTemplate.opsForHash().entries(AuthConstants.RESOURCE_ROLES_KEY);
Iterator<Object> iterator = resourceRolesMap.keySet().iterator();
Map<Object, Object> permissionRoles = redisTemplate.opsForHash().entries(AuthConstants.PERMISSION_RULES_KEY);
Iterator<Object> iterator = permissionRoles.keySet().iterator();
// 请求路径匹配到的资源需要的角色权限集合authorities统计
Set<String> authorities = new HashSet<>();
while (iterator.hasNext()) {
String pattern = (String) iterator.next();
if (pathMatcher.match(pattern, path)) {
authorities.addAll(Convert.toList(String.class, resourceRolesMap.get(pattern)));
authorities.addAll(Convert.toList(String.class, permissionRoles.get(pattern)));
}
}