From a3636433955d2c81c3f5d538b9bd65e246dc4c57 Mon Sep 17 00:00:00 2001 From: zlt2000 Date: Mon, 13 Feb 2023 22:13:01 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E7=94=A8=E6=88=B7=E3=80=81?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E3=80=81=E8=8F=9C=E5=8D=95=E3=80=81=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 14 +++++++++++ .../DataScopeInnerInterceptor.java | 25 ++++++++++++------- .../properties/DataScopeProperties.java | 9 ++++++- zlt-uaa/src/main/resources/application.yml | 9 ++++++- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/zlt-business/user-center/src/main/resources/application.yml b/zlt-business/user-center/src/main/resources/application.yml index f9a8c71b..ce00a785 100644 --- a/zlt-business/user-center/src/main/resources/application.yml +++ b/zlt-business/user-center/src/main/resources/application.yml @@ -38,6 +38,20 @@ zlt: - com.central.user.mapper.SysRoleMapper.findAll # 用户列表显示用户所关联的所有角色 - 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: # enabled: true diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/datascope/mp/interceptor/DataScopeInnerInterceptor.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/datascope/mp/interceptor/DataScopeInnerInterceptor.java index af2b048f..114d1fa6 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/datascope/mp/interceptor/DataScopeInnerInterceptor.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/datascope/mp/interceptor/DataScopeInnerInterceptor.java @@ -68,15 +68,22 @@ public class DataScopeInnerInterceptor implements InnerInterceptor { @Override 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())){ - PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql); - String sql = boundSql.getSql(); - try { - Select select = explainQuerySql(sql); - reform(select.getSelectBody()); - mpBs.sql(select.toString()); - } catch (JSQLParserException e) { - throw new RuntimeException(e); + //为空时:所有sql都添加权限控制 + if (CollUtil.isEmpty(dataScopeProperties.getIncludeSqls()) + //有值时:只有配置的sql添加权限控制 + || dataScopeProperties.getIncludeSqls().contains(ms.getId())) { + //判断排除的sql + if(CollUtil.isEmpty(dataScopeProperties.getIgnoreSqls()) + || !dataScopeProperties.getIgnoreSqls().contains(ms.getId())){ + PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql); + String sql = boundSql.getSql(); + try { + Select select = explainQuerySql(sql); + reform(select.getSelectBody()); + mpBs.sql(select.toString()); + } catch (JSQLParserException e) { + throw new RuntimeException(e); + } } } } diff --git a/zlt-commons/zlt-common-core/src/main/java/com/central/common/properties/DataScopeProperties.java b/zlt-commons/zlt-common-core/src/main/java/com/central/common/properties/DataScopeProperties.java index 7d72dfe6..0b0e5e0a 100644 --- a/zlt-commons/zlt-common-core/src/main/java/com/central/common/properties/DataScopeProperties.java +++ b/zlt-commons/zlt-common-core/src/main/java/com/central/common/properties/DataScopeProperties.java @@ -43,11 +43,18 @@ public class DataScopeProperties { * 指定某几个表接受权限控制,仅enabled=true,默认当开启时全部表 */ private Set includeTables = Collections.singleton("*"); + /** + * 指定某几条sql执行权限控制,仅enabled=true生效 + * 1. 为空时:所有sql都添加权限控制 + * 2. 有值时:只有配置的sql添加权限控制 + */ + private Set includeSqls = Collections.emptySet(); /** * 指定需要的字段名 */ - private String creatorIdColumnName; + private String creatorIdColumnName = "creator_id"; + public void setIgnoreSqls(Set ignoreSqls) { Set ingoreSet = new HashSet<>(); ingoreSet.addAll(INGORE_SQL_ID); diff --git a/zlt-uaa/src/main/resources/application.yml b/zlt-uaa/src/main/resources/application.yml index 0527d6b4..26f3caeb 100644 --- a/zlt-uaa/src/main/resources/application.yml +++ b/zlt-uaa/src/main/resources/application.yml @@ -37,4 +37,11 @@ zlt: tenant: enable: true ignoreTables: - - oauth_client_details \ No newline at end of file + - oauth_client_details + # 数据权限 + datascope: + enabled: true + enabledSqlDebug: true + includeSqls: + # 应用列表 + - com.central.oauth.mapper.ClientMapper.findList \ No newline at end of file