feat:用户、角色、菜单、应用列表增加数据权限

This commit is contained in:
zlt2000
2023-02-13 22:13:01 +08:00
parent 26aac08df2
commit a363643395
4 changed files with 46 additions and 11 deletions
@@ -38,6 +38,20 @@ zlt:
- com.central.user.mapper.SysRoleMapper.findAll - com.central.user.mapper.SysRoleMapper.findAll
# 用户列表显示用户所关联的所有角色 # 用户列表显示用户所关联的所有角色
- com.central.user.mapper.SysUserRoleMapper.findRolesByUserIds - com.central.user.mapper.SysUserRoleMapper.findRolesByUserIds
# 数据权限
datascope:
enabled: true
enabledSqlDebug: true
ignoreTables:
- sys_role_user
- sys_role_menu
includeSqls:
# 用户列表
- com.central.user.mapper.SysUserMapper.findList
# 角色列表
- com.central.user.mapper.SysRoleMapper.findList
# 菜单列表
- com.central.user.mapper.SysMenuMapper.selectList
#审计日志 #审计日志
# audit-log: # audit-log:
# enabled: true # enabled: true
@@ -68,15 +68,22 @@ public class DataScopeInnerInterceptor implements InnerInterceptor {
@Override @Override
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) { public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
if(CollUtil.isEmpty(dataScopeProperties.getIgnoreSqls())|| !dataScopeProperties.getIgnoreSqls().contains(ms.getId())){ //为空时:所有sql都添加权限控制
PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql); if (CollUtil.isEmpty(dataScopeProperties.getIncludeSqls())
String sql = boundSql.getSql(); //有值时:只有配置的sql添加权限控制
try { || dataScopeProperties.getIncludeSqls().contains(ms.getId())) {
Select select = explainQuerySql(sql); //判断排除的sql
reform(select.getSelectBody()); if(CollUtil.isEmpty(dataScopeProperties.getIgnoreSqls())
mpBs.sql(select.toString()); || !dataScopeProperties.getIgnoreSqls().contains(ms.getId())){
} catch (JSQLParserException e) { PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql);
throw new RuntimeException(e); String sql = boundSql.getSql();
try {
Select select = explainQuerySql(sql);
reform(select.getSelectBody());
mpBs.sql(select.toString());
} catch (JSQLParserException e) {
throw new RuntimeException(e);
}
} }
} }
} }
@@ -43,11 +43,18 @@ public class DataScopeProperties {
* 指定某几个表接受权限控制,仅enabled=true,默认当开启时全部表 * 指定某几个表接受权限控制,仅enabled=true,默认当开启时全部表
*/ */
private Set<String> includeTables = Collections.singleton("*"); private Set<String> includeTables = Collections.singleton("*");
/**
* 指定某几条sql执行权限控制,仅enabled=true生效
* 1. 为空时:所有sql都添加权限控制
* 2. 有值时:只有配置的sql添加权限控制
*/
private Set<String> includeSqls = Collections.emptySet();
/** /**
* 指定需要的字段名 * 指定需要的字段名
*/ */
private String creatorIdColumnName; private String creatorIdColumnName = "creator_id";
public void setIgnoreSqls(Set<String> ignoreSqls) { public void setIgnoreSqls(Set<String> ignoreSqls) {
Set<String> ingoreSet = new HashSet<>(); Set<String> ingoreSet = new HashSet<>();
ingoreSet.addAll(INGORE_SQL_ID); ingoreSet.addAll(INGORE_SQL_ID);
+8 -1
View File
@@ -37,4 +37,11 @@ zlt:
tenant: tenant:
enable: true enable: true
ignoreTables: ignoreTables:
- oauth_client_details - oauth_client_details
# 数据权限
datascope:
enabled: true
enabledSqlDebug: true
includeSqls:
# 应用列表
- com.central.oauth.mapper.ClientMapper.findList