Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zlt2000
microservices-platform
提交
7b5089a6
microservices-platform
项目概览
zlt2000
/
microservices-platform
8 个月 前同步成功
通知
16
Star
4
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
microservices-platform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7b5089a6
编写于
1月 29, 2023
作者:
J
jarvis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 1. 兼容旧系统,将权限改成默认读取全部数据2. 配置修改,将原来scopeColumn改成creatorIdColumnName3.添加SYS开头的不进行权限控制的配置
上级
c69049d0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
10 deletion
+36
-10
zlt-commons/zlt-common-core/src/main/java/com/central/common/datascope/mp/sql/handler/CreatorDataScopeSqlHandler.java
.../datascope/mp/sql/handler/CreatorDataScopeSqlHandler.java
+7
-5
zlt-commons/zlt-common-core/src/main/java/com/central/common/properties/DataScopeProperties.java
...va/com/central/common/properties/DataScopeProperties.java
+29
-5
未找到文件。
zlt-commons/zlt-common-core/src/main/java/com/central/common/datascope/mp/sql/handler/CreatorDataScopeSqlHandler.java
浏览文件 @
7b5089a6
...
...
@@ -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
.
get
ScopeColumn
(),
user
.
getId
());
// 1. 如果没有配置角色的情况默认采用只读
全部
的记录
// 2. 如果有配置角色的话判断是否存在有ALL
获取null
的情况,如果没有ALL的话读取个人创建记录
String
.
format
(
"%s.%s = '%s'"
,
ALIAS_SYNBOL
,
dataScopeProperties
.
get
CreatorIdColumnName
(),
user
.
getId
());
}
}
zlt-commons/zlt-common-core/src/main/java/com/central/common/properties/DataScopeProperties.java
浏览文件 @
7b5089a6
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.
Lis
t
;
import
java.util.
HashSe
t
;
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录