feat: 1. 兼容旧系统,将权限改成默认读取全部数据2. 配置修改,将原来scopeColumn改成creatorIdColumnName3.添加SYS开头的不进行权限控制的配置
This commit is contained in:
+7
-5
@@ -12,6 +12,7 @@ import com.central.common.properties.DataScopeProperties;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 个人权限的处理器
|
* 个人权限的处理器
|
||||||
@@ -37,12 +38,13 @@ public class CreatorDataScopeSqlHandler implements SqlHandler{
|
|||||||
SysUser user = LoginUserContextHolder.getUser();
|
SysUser user = LoginUserContextHolder.getUser();
|
||||||
Assert.notNull(user, "登陆人不能为空");
|
Assert.notNull(user, "登陆人不能为空");
|
||||||
List<SysRole> roleList = userService.findRolesByUserId(user.getId());
|
List<SysRole> roleList = userService.findRolesByUserId(user.getId());
|
||||||
return StrUtil.isBlank(dataScopeProperties.getScopeColumn())
|
return StrUtil.isBlank(dataScopeProperties.getCreatorIdColumnName())
|
||||||
||(CollUtil.isNotEmpty(roleList)&& roleList.stream().anyMatch(item-> DataScope.ALL.equals(item.getDataScope())))
|
||CollUtil.isEmpty(roleList)
|
||||||
|
|| roleList.stream().anyMatch(item-> Objects.nonNull(item.getDataScope()) || DataScope.ALL.equals(item.getDataScope()))
|
||||||
? DO_NOTHING:
|
? DO_NOTHING:
|
||||||
// 这里确保有配置权限范围控制的字段
|
// 这里确保有配置权限范围控制的字段
|
||||||
// 1. 如果没有配置角色的情况默认采用只读个人创建的记录
|
// 1. 如果没有配置角色的情况默认采用只读全部的记录
|
||||||
// 2. 如果有配置角色的话判断是否存在有ALL的情况,如果没有ALL的话读取个人创建记录
|
// 2. 如果有配置角色的话判断是否存在有ALL获取null的情况,如果没有ALL的话读取个人创建记录
|
||||||
String.format("%s.%s = '%s'", ALIAS_SYNBOL, dataScopeProperties.getScopeColumn(), user.getId());
|
String.format("%s.%s = '%s'", ALIAS_SYNBOL, dataScopeProperties.getCreatorIdColumnName(), user.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-5
@@ -1,11 +1,12 @@
|
|||||||
package com.central.common.properties;
|
package com.central.common.properties;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,7 +15,7 @@ import java.util.Set;
|
|||||||
* @author jarvis create by 2023/1/8
|
* @author jarvis create by 2023/1/8
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "zlt.datascope")
|
@ConfigurationProperties(prefix = "zlt.datascope")
|
||||||
@Data
|
@Getter
|
||||||
public class DataScopeProperties {
|
public class DataScopeProperties {
|
||||||
/**
|
/**
|
||||||
* 是否开启权限控制
|
* 是否开启权限控制
|
||||||
@@ -23,7 +24,7 @@ public class DataScopeProperties {
|
|||||||
/**
|
/**
|
||||||
* 在includeTables的匹配符中过滤某几个表不需要权限的,仅enabled=true
|
* 在includeTables的匹配符中过滤某几个表不需要权限的,仅enabled=true
|
||||||
*/
|
*/
|
||||||
private Set<String> ignoreTables = Collections.emptySet();
|
private Set<String> ignoreTables = Collections.singleton("SYS*");
|
||||||
/**
|
/**
|
||||||
* 指定某几条sql不执行权限控制, 仅enabled=true生效
|
* 指定某几条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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user