Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz4j Spring R7
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7后台标准模板
iBiz4j Spring R7
提交
35c235c7
提交
35c235c7
编写于
5月 27, 2020
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
简化权限校验
上级
5b286bc3
变更
2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
54 行增加
和
42 行删除
+54
-42
%ITEM%Resource.java.ftl
...YS_PKGPATH%/%SYSAPI_PKGPATH%/rest/%ITEM%Resource.java.ftl
+6
-6
AuthPermissionEvaluator.java.ftl
...S_PKGPATH%/util/security/AuthPermissionEvaluator.java.ftl
+48
-36
未找到文件。
SLN/%PUBPRJ%-provider/%PUBPRJ%-provider-%SYSAPI_PKGPATH%/src/main/java/%SYS_PKGPATH%/%SYSAPI_PKGPATH%/rest/%ITEM%Resource.java.ftl
浏览文件 @
35c235c7
...
...
@@ -630,16 +630,16 @@ public class ${itemCodeName}Resource {
<#
macro
SecurityAnnotation
deaction
>
<#
if
noDEPrefield
>
@
PreAuthorize
(
"hasAnyAuthority('ROLE_SUPERADMIN','${sys.codeName}-${de.codeName}-${deaction.codeName}-all')"
)
@
PreAuthorize
(
"hasAnyAuthority('ROLE_SUPERADMIN','${sys.codeName}-${de.codeName}-${deaction.codeName}-all')"
)
<#
else
>
<#
if
deaction
.
codeName
?
lower_case
==
'create'
||
deaction
.
codeName
?
lower_case
==
'save'
>
@
PreAuthorize
(
"hasPermission(this.${itemCodeNameLC}Mapping.toDomain(#${itemCodeNameLC}dto),'${sys.codeName}-${de.codeName}-${deaction.codeName}')"
)
@
PreAuthorize
(
"hasPermission(this.${itemCodeNameLC}Mapping.toDomain(#${itemCodeNameLC}dto),'${sys.codeName}-${de.codeName}-${deaction.codeName}')"
)
<#
elseif
deaction
.
codeName
?
lower_case
==
'update'
||
deaction
.
codeName
?
lower_case
==
'remove'
>
@
PreAuthorize
(
"hasPermission(this.${deCodeNameLC}Service.get(#${itemCodeNameLC + keyCNLC}),'${sys.codeName}-${de.codeName}-${deaction.codeName}')"
)
@
PreAuthorize
(
"hasPermission(this.${deCodeNameLC}Service.get(#${itemCodeNameLC + keyCNLC}),'${sys.codeName}-${de.codeName}-${deaction.codeName}')"
)
<#
elseif
deaction
.
codeName
?
lower_case
==
'get'
>
@
PostAuthorize
(
"hasPermission(this.${itemCodeNameLC}Mapping.toDomain(returnObject.body),'${sys.codeName}-${de.codeName}-${deaction.codeName}')"
)
@
PostAuthorize
(
"hasPermission(this.${itemCodeNameLC}Mapping.toDomain(returnObject.body),'${sys.codeName}-${de.codeName}-${deaction.codeName}')"
)
<#
else
>
@
PreAuthorize
(
"hasAnyAuthority('ROLE_SUPERADMIN','${sys.codeName}-${de.codeName}-${deaction.codeName}-all')"
)
@
PreAuthorize
(
"hasAnyAuthority('ROLE_SUPERADMIN','${sys.codeName}-${de.codeName}-${deaction.codeName}-all')"
)
</#
if
>
</#
if
>
</#
macro
>
...
...
@@ -648,7 +648,7 @@ public class ${itemCodeName}Resource {
<#
if
deaction
.
codeName
?
lower_case
==
'Remove'
>
//
<#
else
>
//
@
PreAuthorize
(
"hasPermission(this.${itemCodeNameLC}Mapping.toDomain(#${itemCodeNameLC}dtos),'${sys.codeName}-${de.codeName}-${deaction.codeName}')"
)
@
PreAuthorize
(
"hasPermission(this.${itemCodeNameLC}Mapping.toDomain(#${itemCodeNameLC}dtos),'${sys.codeName}-${de.codeName}-${deaction.codeName}')"
)
</#
if
>
</#
macro
>
...
...
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/security/AuthPermissionEvaluator.java.ftl
浏览文件 @
35c235c7
...
...
@@ -26,7 +26,10 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
@
Value
(
"${r'${ibiz.enablePermissionValid:false}'}"
)
boolean
enablePermissionValid
;
//
是否开启权限校验
/**
*
实体主键标识
*/
private
String
keyFieldTag
=
"keyfield"
;
/**
*
实体行为鉴权
*
@
param
authentication
...
...
@@ -42,18 +45,18 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
return
true
;
String
strAction
=
String
.
valueOf
(
action
);
Set
<
String
>
entityDataRange
=
getAuthorities
(
authentication
,
strAction
);
if
(
entityDataRange
.
size
()==
0
)
Set
<
String
>
userAuthorities
=
getAuthorities
(
authentication
,
strAction
);
if
(
userAuthorities
.
size
()==
0
)
return
false
;
//
拥有全部数据访问权限时,则跳过权限检查
if
(
isAllData
(
strAction
,
entityDataRange
)){
if
(
isAllData
(
strAction
,
userAuthorities
)){
return
true
;
}
if
(
entity
instanceof
ArrayList
){
List
<
EntityBase
>
entities
=
(
List
<
EntityBase
>)
entity
;
for
(
EntityBase
entityBase
:
entities
){
boolean
result
=
actionValid
(
entityBase
,
strAction
,
entityDataRange
);
boolean
result
=
actionValid
(
entityBase
,
strAction
,
userAuthorities
);
if
(
!result){
return
false
;
}
...
...
@@ -61,7 +64,7 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
}
else
{
EntityBase
entityBase
=
(
EntityBase
)
entity
;
return
actionValid
(
entityBase
,
strAction
,
entityDataRange
);
return
actionValid
(
entityBase
,
strAction
,
userAuthorities
);
}
return
true
;
}
...
...
@@ -80,15 +83,15 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
*/
private
Set
<
String
>
getAuthorities
(
Authentication
authentication
,
String
action
){
Collection
authorities
=
authentication
.
getAuthorities
();
Set
<
String
>
entityDataRange
=
new
HashSet
();
Set
<
String
>
userAuthorities
=
new
HashSet
();
Iterator
var2
=
authorities
.
iterator
();
while
(
var2
.
hasNext
())
{
GrantedAuthority
authority
=
(
GrantedAuthority
)
var2
.
next
();
if
(
authority
.
getAuthority
().
contains
(
action
))
entityDataRange
.
add
(
authority
.
getAuthority
());
userAuthorities
.
add
(
authority
.
getAuthority
());
}
return
entityDataRange
;
return
userAuthorities
;
}
/**
...
...
@@ -109,10 +112,10 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
/**
*
实体行为权限校验
*
@
param
entity
*
@
param
entityDataRange
*
@
param
userAuthorities
*
@
return
*/
private
boolean
actionValid
(
EntityBase
entity
,
String
action
,
Set
<
String
>
entityDataRange
){
private
boolean
actionValid
(
EntityBase
entity
,
String
action
,
Set
<
String
>
userAuthorities
){
Map
<
String
,
String
>
permissionField
=
getPermissionField
(
entity
);//
获取组织、部门预置属性
String
orgField
=
permissionField
.
get
(
"orgfield"
);
...
...
@@ -132,47 +135,56 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
Set
<
String
>
userOrg
=
new
HashSet
<>();
Set
<
String
>
userOrgDept
=
new
HashSet
<>();
for
(
String
permissionCond
:
entityDataRange
){
if
(
permissionCond
.
endsWith
(
"curorg"
)){
//
本单位
for
(
String
authority
:
userAuthorities
){
if
(
authority
.
endsWith
(
"curorg"
)){
//
本单位
userOrg
.
add
(
authenticationUser
.
getOrgid
());
}
else
if
(
permissionCond
.
endsWith
(
"porg"
)){//
上级单位
else
if
(
authority
.
endsWith
(
"porg"
)){//
上级单位
userOrg
.
addAll
(
orgParent
);
}
else
if
(
permissionCond
.
endsWith
(
"sorg"
)){//
下级单位
else
if
(
authority
.
endsWith
(
"sorg"
)){//
下级单位
userOrg
.
addAll
(
orgChild
);
}
else
if
(
permissionCond
.
endsWith
(
"curorgdept"
)){//
本部门
else
if
(
authority
.
endsWith
(
"curorgdept"
)){//
本部门
userOrgDept
.
add
(
authenticationUser
.
getMdeptid
());
}
else
if
(
permissionCond
.
endsWith
(
"porgdept"
)){//
上级部门
else
if
(
authority
.
endsWith
(
"porgdept"
)){//
上级部门
userOrgDept
.
addAll
(
orgDeptParent
);
}
else
if
(
permissionCond
.
endsWith
(
"sorgdept"
)){//
下级部门
else
if
(
authority
.
endsWith
(
"sorgdept"
)){//
下级部门
userOrgDept
.
addAll
(
orgDeptChild
);
}
}
if
(
action
.
endsWith
(
"Create"
)){
if
(
!ObjectUtils.isEmpty(orgFieldValue) && !userOrg.contains(orgFieldValue))
return
false
;
if
(
!ObjectUtils.isEmpty(orgDeptFieldValue) && !userOrgDept.contains(orgDeptFieldValue))
return
false
;
if
(
!ObjectUtils.isEmpty(crateManFieldValue) && !crateManFieldValue.equals(authenticationUser.getUserid()))
return
false
;
return
true
;
if
(
action
.
endsWith
(
"Save"
)){
String
keyFieldName
=
permissionField
.
get
(
keyFieldTag
);
Object
srfKey
=
entity
.
get
(
keyFieldName
);
if
(
ObjectUtils
.
isEmpty
(
srfKey
))
action
=
"Create"
;
else
action
=
"Update"
;
}
else
{
if
(
!ObjectUtils.isEmpty(orgFieldValue) && userOrg.contains(orgFieldValue))
return
true
;
if
(
!ObjectUtils.isEmpty(orgDeptFieldValue) && userOrgDept.contains(orgDeptFieldValue))
return
true
;
if
(
!ObjectUtils.isEmpty(crateManFieldValue) && crateManFieldValue.equals(authenticationUser.getUserid()))
return
true
;
return
false
;
}
if
(
action
.
endsWith
(
"Create"
)){
if
(
!ObjectUtils.isEmpty(orgFieldValue) && !userOrg.contains(orgFieldValue))
return
false
;
if
(
!ObjectUtils.isEmpty(orgDeptFieldValue) && !userOrgDept.contains(orgDeptFieldValue))
return
false
;
if
(
!ObjectUtils.isEmpty(crateManFieldValue) && !authenticationUser.getUserid().equals(crateManFieldValue))
return
false
;
return
true
;
}
else
{
if
(
!ObjectUtils.isEmpty(orgFieldValue) && userOrg.contains(orgFieldValue))
return
true
;
if
(
!ObjectUtils.isEmpty(orgDeptFieldValue) && userOrgDept.contains(orgDeptFieldValue))
return
true
;
if
(
!ObjectUtils.isEmpty(crateManFieldValue) && authenticationUser.getUserid().equals(crateManFieldValue))
return
true
;
return
false
;
}
}
/**
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录