提交 7b5089a6 编写于 作者: J jarvis

feat: 1. 兼容旧系统,将权限改成默认读取全部数据2. 配置修改,将原来scopeColumn改成creatorIdColumnName3.添加SYS开头的不进行权限控制的配置

上级 c69049d0
......@@ -12,6 +12,7 @@ import com.central.common.properties.DataScopeProperties;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Objects;
/**
* 个人权限的处理器
......@@ -37,12 +38,13 @@ public class CreatorDataScopeSqlHandler implements SqlHandler{
SysUser user = LoginUserContextHolder.getUser();
Assert.notNull(user, "登陆人不能为空");
List<SysRole> roleList = userService.findRolesByUserId(user.getId());
return StrUtil.isBlank(dataScopeProperties.getScopeColumn())
||(CollUtil.isNotEmpty(roleList)&& roleList.stream().anyMatch(item-> DataScope.ALL.equals(item.getDataScope())))
return StrUtil.isBlank(dataScopeProperties.getCreatorIdColumnName())
||CollUtil.isEmpty(roleList)
|| roleList.stream().anyMatch(item-> Objects.nonNull(item.getDataScope()) || DataScope.ALL.equals(item.getDataScope()))
? DO_NOTHING:
// 这里确保有配置权限范围控制的字段
// 1. 如果没有配置角色的情况默认采用只读个人创建的记录
// 2. 如果有配置角色的话判断是否存在有ALL的情况,如果没有ALL的话读取个人创建记录
String.format("%s.%s = '%s'", ALIAS_SYNBOL, dataScopeProperties.getScopeColumn(), user.getId());
// 1. 如果没有配置角色的情况默认采用只读全部的记录
// 2. 如果有配置角色的话判断是否存在有ALL获取null的情况,如果没有ALL的话读取个人创建记录
String.format("%s.%s = '%s'", ALIAS_SYNBOL, dataScopeProperties.getCreatorIdColumnName(), user.getId());
}
}
package com.central.common.properties;
import cn.hutool.core.collection.CollUtil;
import lombok.Data;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
/**
......@@ -14,7 +15,7 @@ import java.util.Set;
* @author jarvis create by 2023/1/8
*/
@ConfigurationProperties(prefix = "zlt.datascope")
@Data
@Getter
public class DataScopeProperties {
/**
* 是否开启权限控制
......@@ -23,7 +24,7 @@ public class DataScopeProperties {
/**
* 在includeTables的匹配符中过滤某几个表不需要权限的,仅enabled=true
*/
private Set<String> ignoreTables = Collections.emptySet();
private Set<String> ignoreTables = Collections.singleton("SYS*");
/**
* 指定某几条sql不执行权限控制, 仅enabled=true生效
*/
......@@ -36,5 +37,28 @@ public class DataScopeProperties {
/**
* 指定需要的字段名
*/
private String scopeColumn;
private String creatorIdColumnName;
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public void setIgnoreTables(Set<String> ignoreTables) {
HashSet<String> ignoreSet = new HashSet<>();
CollUtil.addAll(ignoreSet, ignoreTables);
CollUtil.addAll(ignoreSet, this.ignoreTables);
this.ignoreTables = ignoreSet;
}
public void setIgnoreSqls(Set<String> ignoreSqls) {
this.ignoreSqls = ignoreSqls;
}
public void setIncludeTables(Set<String> includeTables) {
this.includeTables = includeTables;
}
public void setCreatorIdColumnName(String creatorIdColumnName) {
this.creatorIdColumnName = creatorIdColumnName;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册