Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz4j Spring R7
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7后台标准模板
iBiz4j Spring R7
提交
e065c04f
提交
e065c04f
编写于
5月 27, 2020
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
简化权限校验
上级
32bb59ee
变更
4
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
125 行增加
和
98 行删除
+125
-98
I%DE%Service.java.ftl
...PKGPATH%/core/%MOD_PKGPATH%/service/I%DE%Service.java.ftl
+15
-0
%DE%ServiceImpl.java.ftl
.../core/%MOD_PKGPATH%/service/impl/%DE%ServiceImpl.java.ftl
+59
-2
%ITEM%Resource.java.ftl
...YS_PKGPATH%/%SYSAPI_PKGPATH%/rest/%ITEM%Resource.java.ftl
+22
-32
AuthPermissionEvaluator.java.ftl
...S_PKGPATH%/util/security/AuthPermissionEvaluator.java.ftl
+29
-64
未找到文件。
SLN/%PUBPRJ%-core/src/main/java/%SYS_PKGPATH%/core/%MOD_PKGPATH%/service/I%DE%Service.java.ftl
浏览文件 @
e065c04f
<#
ibiztemplate
>
TARGET
=
PSDATAENTITY
</#
ibiztemplate
>
<#
assign
deCodeNameCamel
=
srfcaseformat
(
de
.
codeName
,
'l_u2lC'
)>
<#
comment
>
实体是否配置预置属性
</#
comment
>
<#
assign
hasDEPrefield
=
false
>
<#
if
de
.
getPSDEFieldByPDT
(
'ORGID'
,
true
)??
||
de
.
getPSDEFieldByPDT
(
'ORGSECTORID'
,
true
)??
||
de
.
getPSDEFieldByPDT
(
'CREATEMAN'
,
true
)??
>
<#
assign
hasDEPrefield
=
true
>
</#
if
>
<#
if
de
.
getStorageMode
()==
1
||
de
.
getStorageMode
()==
2
||
de
.
getStorageMode
()==
4
||
de
.
getStorageMode
()==
0
>
package
${
pub
.
getPKGCodeName
()}.
core
.${
item
.
getPSSystemModule
().
getCodeName
()?
lower_case
}.
service
;
...
...
@@ -47,6 +53,11 @@ public interface I${item.codeName}Service extends IService<${item.codeName}>{
*/
boolean
execute
(
String
sql
,
Map
param
);
<#
if
hasDEPrefield
>
List
<${
de
.
codeName
}>
get
${
deCodeNameCamel
}
ByIds
(
List
<
String
>
ids
)
;
List
<${
de
.
codeName
}>
get
${
deCodeNameCamel
}
ByEntities
(
List
<${
de
.
codeName
}>
entities
)
;
</#
if
>
}
<#
comment
>
NoSQL
存储
-
MongoDB
</#
comment
>
<#
elseif
de
.
getStorageMode
()==
2
>
...
...
@@ -58,6 +69,10 @@ public interface I${item.codeName}Service{
<@
addIDESerivceBody
/>
<#
if
hasDEPrefield
>
List
<${
de
.
codeName
}>
get
${
deCodeNameCamel
}
ByIds
(
List
<
String
>
ids
)
;
List
<${
de
.
codeName
}>
get
${
deCodeNameCamel
}
ByEntities
(
List
<${
de
.
codeName
}>
entities
)
;
</#
if
>
}
<#
elseif
de
.
getStorageMode
()==
4
>
...
...
SLN/%PUBPRJ%-core/src/main/java/%SYS_PKGPATH%/core/%MOD_PKGPATH%/service/impl/%DE%ServiceImpl.java.ftl
浏览文件 @
e065c04f
<#
ibiztemplate
>
TARGET
=
PSDATAENTITY
</#
ibiztemplate
>
<#
assign
deCodeNameCamel
=
srfcaseformat
(
de
.
codeName
,
'l_u2lC'
)>
<#
comment
>
实体是否配置预置属性
</#
comment
>
<#
assign
hasDEPrefield
=
false
>
<#
if
de
.
getPSDEFieldByPDT
(
'ORGID'
,
true
)??
||
de
.
getPSDEFieldByPDT
(
'ORGSECTORID'
,
true
)??
||
de
.
getPSDEFieldByPDT
(
'CREATEMAN'
,
true
)??
>
<#
assign
hasDEPrefield
=
true
>
</#
if
>
<#
if
de
.
getStorageMode
()==
1
||
de
.
getStorageMode
()==
2
||
de
.
getStorageMode
()==
4
||
de
.
getStorageMode
()==
0
>
<#
comment
>
判断是否有
1
:
N
的主关系,用于填充外键值文本、附加数据
</#
comment
>
<#
assign
hasMinorPSDERs
=
0
>
...
...
@@ -602,6 +608,28 @@ ${deaction.getRender().code}
return
true
;
}
<#
if
hasDEPrefield
>
@
Override
public
List
<${
de
.
codeName
}>
get
${
deCodeNameCamel
}
ByIds
(
List
<
String
>
ids
)
{
return
this
.
listByIds
(
ids
);
}
@
Override
public
List
<${
de
.
codeName
}>
get
${
deCodeNameCamel
}
ByEntities
(
List
<${
de
.
codeName
}>
entities
)
{
List
ids
=
new
ArrayList
();
for
(${
de
.
codeName
}
entity
:
entities
){
Serializable
id
=
entity
.
get
${
srfcaseformat
(
keyfield
.
codeName
,
'l_u2lC'
)?
cap_first
}();
if
(
!ObjectUtils.isEmpty(id)){
ids
.
add
(
id
);
}
}
if
(
ids
.
size
()>
0
)
return
this
.
listByIds
(
ids
);
else
return
entities
;
}
</#
if
>
}
<#
comment
>
NOSQL
存储
</#
comment
>
...
...
@@ -612,7 +640,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
import
org
.
springframework
.
data
.
mongodb
.
core
.
query
.
BasicQuery
;
import
org
.
springframework
.
data
.
mongodb
.
core
.
query
.
Query
;
import
javax
.
annotation
.
Resource
;
import
com
.
mongodb
.
QueryBuilder
;
/**
*
实体
[${
item
.
getLogicName
()}]
服务对象接口实现
*/
...
...
@@ -1037,7 +1065,36 @@ ${deaction.getRender().code}
</#
list
>
</#
if
>
<#
if
hasDEPrefield
>
@
Override
public
List
<${
de
.
codeName
}>
get
${
deCodeNameCamel
}
ByIds
(
List
<
String
>
ids
)
{
QueryBuilder
permissionCond
=
new
QueryBuilder
();
permissionCond
.
and
(
"${keyfield?lower_case}"
).
in
(
ids
);
Query
query
=
new
BasicQuery
(
permissionCond
.
get
().
toString
());
return
mongoTemplate
.
find
(
query
,${
de
.
codeName
}.
class
);
}
@
Override
public
List
<${
de
.
codeName
}>
get
${
deCodeNameCamel
}
ByEntities
(
List
<${
de
.
codeName
}>
entities
)
{
List
ids
=
new
ArrayList
();
for
(${
de
.
codeName
}
entity
:
entities
){
Serializable
id
=
entity
.
get
${
srfcaseformat
(
keyfield
.
codeName
,
'l_u2lC'
)?
cap_first
}();
if
(
!ObjectUtils.isEmpty(id)){
ids
.
add
(
id
);
}
}
if
(
ids
.
size
()>
0
){
QueryBuilder
permissionCond
=
new
QueryBuilder
();
permissionCond
.
and
(
"${keyfield?lower_case}"
).
in
(
ids
);
Query
query
=
new
BasicQuery
(
permissionCond
.
get
().
toString
());
return
mongoTemplate
.
find
(
query
,${
de
.
codeName
}.
class
);
}
else
return
entities
;
}
</#
if
>
}
...
...
SLN/%PUBPRJ%-provider/%PUBPRJ%-provider-%SYSAPI_PKGPATH%/src/main/java/%SYS_PKGPATH%/%SYSAPI_PKGPATH%/rest/%ITEM%Resource.java.ftl
浏览文件 @
e065c04f
...
...
@@ -9,6 +9,7 @@ TARGET=PSDESERVICEAPI
<#
assign
itemCodeName
=
item
.
getCodeName
()>
<#
assign
itemCodeNameLC
=
itemCodeName
?
lower_case
>
<#
assign
deCodeName
=
de
.
getCodeName
()>
<#
assign
deCodeNameCamel
=
srfcaseformat
(
deCodeName
,
'l_u2lC'
)>
<#
assign
deCodeNameLC
=
deCodeName
?
lower_case
>
<#
assign
dePKCodeNameLC
=
srfcaseformat
(
de
.
getKeyPSDEField
().
getCodeName
(),
'l_u2lC'
)>
<#
assign
dePKCodeName
=
(
dePKCodeNameLC
)?
cap_first
>
...
...
@@ -16,11 +17,9 @@ TARGET=PSDESERVICEAPI
<#
assign
itemSysApiCodeName
=
item
.
getPSSysServiceAPI
().
getCodeName
()>
<#
assign
itemSysApiCodeNameLC
=
item
.
getPSSysServiceAPI
().
getCodeName
()?
lower_case
>
<#
assign
keyCNLC
=
"_id"
>
<#
assign
deStorageMode
=
"None"
>
<#
if
de
.
getStorageMode
()==
1
><#
assign
deStorageMode
=
"Sql"
><#
elseif
de
.
getStorageMode
()==
2
><#
assign
deStorageMode
=
"NoSQL"
><#
elseif
de
.
getStorageMode
()==
4
><#
assign
deStorageMode
=
"ServiceApi"
></#
if
>
<#
assign
noDEPrefield
=
true
>
<#
assign
hasDEPrefield
=
false
>
<#
if
de
.
getPSDEFieldByPDT
(
'ORGID'
,
true
)??
||
de
.
getPSDEFieldByPDT
(
'ORGSECTORID'
,
true
)??
||
de
.
getPSDEFieldByPDT
(
'CREATEMAN'
,
true
)??
>
<#
assign
noDEPrefield
=
fals
e
>
<#
assign
hasDEPrefield
=
tru
e
>
</#
if
>
package
${
pubPkgCodeName
}.${
itemSysApiCodeNameLC
}.
rest
;
...
...
@@ -608,47 +607,38 @@ public class ${itemCodeName}Resource {
}
</#
if
>
</#
if
>
<#--<#
comment
>
输出实体资源鉴权注解
[
hasAnyAuthority
]</#
comment
>-->
<#--<#
macro
outputHasAnyAuthorityAnnotation
permissionTag
>-->
<#--@
PreAuthorize
(
"hasAnyAuthority('ROLE_SUPERADMIN','${permissionTag}')"
)-->
<#--</#
macro
>-->
<#--<#
comment
>
输出实体资源鉴权注解
[
hasAnyAuthority
]</#
comment
>-->
<#--<#
macro
outputHasPermissionAnnotation
param1
param2
>-->
<#--@
PreAuthorize
(
"hasPermission(${param1},'${param2}')"
)-->
<#--</#
macro
>-->
<#--<#
comment
>
输出实体批处理权限注解
[
hasAnyAuthority
]</#
comment
>-->
<#--<#
macro
outputBatchPermissionAnnotation
deAction
>-->
<#--<#
if
deAction
==
'Remove'
>-->
<#--//-->
<#--<#
else
>-->
<#--//@
PreAuthorize
(
"hasPermission(this.${itemCodeNameLC}Mapping.toDomain(#${itemCodeNameLC}dtos),'${sys.codeName}-${de.codeName}-${deAction.codeName}')"
)-->
<#--</#
if
>-->
<#--</#
macro
>-->
<#
macro
SecurityAnnotation
deaction
>
<#
if
noDEPrefield
>
<#
if
de
.
getStorageMode
()==
1
||
de
.
getStorageMode
()==
2
>
<#
if
hasDEPrefield
==
false
>
@
PreAuthorize
(
"hasAnyAuthority('ROLE_SUPERADMIN','${sys.codeName}-${de.codeName}-${deaction.codeName}-all')"
)
<#
else
>
<#
if
deaction
.
codeName
?
lower_case
==
'create'
||
deaction
.
codeName
?
lower_case
==
'save'
>
<#
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}')"
)
<#
elseif
deaction
.
codeName
?
lower_case
==
'update'
||
deaction
.
codeName
?
lower_case
==
'remove'
>
<#
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}')"
)
<#
elseif
deaction
.
codeName
?
lower_case
==
'get'
>
<#
elseif
deaction
.
codeName
?
lower_case
==
'get'
>
@
PostAuthorize
(
"hasPermission(this.${itemCodeNameLC}Mapping.toDomain(returnObject.body),'${sys.codeName}-${de.codeName}-${deaction.codeName}')"
)
<#
else
>
<#
else
>
@
PreAuthorize
(
"hasAnyAuthority('ROLE_SUPERADMIN','${sys.codeName}-${de.codeName}-${deaction.codeName}-all')"
)
</#
if
>
</#
if
>
</#
if
>
</#
macro
>
<#
macro
SecurityBatchAnnotation
deaction
>
<#
if
deaction
.
codeName
?
lower_case
==
'remove'
>
//
<#
else
>
<#
if
de
.
getStorageMode
()==
1
||
de
.
getStorageMode
()==
2
>
<#
if
hasDEPrefield
==
false
>
@
PreAuthorize
(
"hasAnyAuthority('ROLE_SUPERADMIN','${sys.codeName}-${de.codeName}-${deaction.codeName}-all')"
)
<#
else
>
<#
if
deaction
.
codeName
?
lower_case
==
'remove'
>
//@
PreAuthorize
(
"hasPermission(this.${deCodeNameLC}Service.get${deCodeNameCamel}ByIds(#ids),'${sys.codeName}-${de.codeName}-${deaction.codeName}')"
)
<#
elseif
deaction
.
codeName
?
lower_case
==
'update'
>
//@
PreAuthorize
(
"hasPermission(this.${deCodeNameLC}Service.get${deCodeNameCamel}ByEntities(this.${itemCodeNameLC}Mapping.toDomain(#${itemCodeNameLC}dtos)),'${sys.codeName}-${de.codeName}-${deaction.codeName}')"
)
<#
else
>
//@
PreAuthorize
(
"hasPermission(this.${itemCodeNameLC}Mapping.toDomain(#${itemCodeNameLC}dtos),'${sys.codeName}-${de.codeName}-${deaction.codeName}')"
)
</#
if
>
</#
if
>
</#
if
>
</#
macro
>
...
...
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/security/AuthPermissionEvaluator.java.ftl
浏览文件 @
e065c04f
...
...
@@ -14,7 +14,6 @@ import org.springframework.security.core.GrantedAuthority;
import
org
.
springframework
.
stereotype
.
Component
;
import
org
.
springframework
.
util
.
ObjectUtils
;
import
java
.
io
.
Serializable
;
import
java
.
lang
.
reflect
.
Field
;
import
java
.
util
.*;
/**
...
...
@@ -26,10 +25,6 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
@
Value
(
"${r'${ibiz.enablePermissionValid:false}'}"
)
boolean
enablePermissionValid
;
//
是否开启权限校验
/**
*
实体主键标识
*/
private
String
keyFieldTag
=
"keyfield"
;
/**
*
实体行为鉴权
*
@
param
authentication
...
...
@@ -58,7 +53,7 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
for
(
EntityBase
entityBase
:
entities
){
boolean
result
=
actionValid
(
entityBase
,
strAction
,
userAuthorities
);
if
(
!result){
return
false
;
return
false
;
}
}
}
...
...
@@ -84,10 +79,9 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
private
Set
<
String
>
getAuthorities
(
Authentication
authentication
,
String
action
){
Collection
authorities
=
authentication
.
getAuthorities
();
Set
<
String
>
userAuthorities
=
new
HashSet
();
Iterator
var2
=
authorities
.
iterator
();
while
(
var2
.
hasNext
())
{
GrantedAuthority
authority
=
(
GrantedAuthority
)
var2
.
next
();
Iterator
it
=
authorities
.
iterator
();
while
(
it
.
hasNext
())
{
GrantedAuthority
authority
=
(
GrantedAuthority
)
it
.
next
();
if
(
authority
.
getAuthority
().
contains
(
action
))
userAuthorities
.
add
(
authority
.
getAuthority
());
}
...
...
@@ -156,35 +150,26 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
}
}
if
(
action
.
endsWith
(
"Save"
)){
String
keyFieldName
=
permissionField
.
get
(
keyFieldTag
);
Object
srfKey
=
entity
.
get
(
keyFieldName
);
if
(
ObjectUtils
.
isEmpty
(
srfKey
))
action
=
"Create"
;
else
action
=
"Update"
;
if
(
action
.
endsWith
(
"Create"
)
||
action
.
endsWith
(
"Save"
)){
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
;
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
;
}
return
false
;
}
}
/**
...
...
@@ -198,44 +183,24 @@ public class AuthPermissionEvaluator implements PermissionEvaluator {
String
orgField
=
"orgid"
;
//
组织属性
String
orgDeptField
=
"orgsecid"
;
//
部门属性
String
createManField
=
"createman"
;
//
创建人属性
String
keyField
=
""
;//
主键属性
DEFieldCacheMap
.
getFieldMap
(
entityBase
.
getClass
().
getName
());
Map
<
Field
,
DEField
>
preFields
=
SearchDEField
(
entityBase
.
getClass
().
getName
());
//
从缓存中获取当前类预置属性
Map
<
String
,
DEField
>
preFields
=
DEFieldCacheMap
.
getDEFields
(
entityBase
.
getClass
());
//
从缓存中获取当前类预置属性
for
(
Map
.
Entry
<
Field
,
DEField
>
entry
:
preFields
.
entrySet
()){
Field
preField
=
entry
.
getKey
();//
获取注解字段
for
(
Map
.
Entry
<
String
,
DEField
>
entry
:
preFields
.
entrySet
()){
String
fieldName
=
entry
.
getKey
();//
获取注解字段
DEField
fieldAnnotation
=
entry
.
getValue
();//
获取注解值
DEPredefinedFieldType
prefieldType
=
fieldAnnotation
.
preType
();
if
(
prefieldType
==
prefieldType
.
ORGID
)//
用户配置系统预置属性
-
组织机构标识
orgField
=
preField
.
getName
()
;
orgField
=
fieldName
;
if
(
prefieldType
==
prefieldType
.
ORGSECTORID
)//
用户配置系统预置属性
-
部门标识
orgDeptField
=
preField
.
getName
()
;
if
(
fieldAnnotation
.
isKeyField
()
)//
用户配置系统预置属性
-
部门标识
keyField
=
preField
.
getName
()
;
orgDeptField
=
fieldName
;
if
(
prefieldType
==
prefieldType
.
CREATEMAN
)//
用户配置系统预置属性
-
部门标识
createManField
=
fieldName
;
}
permissionFiled
.
put
(
"orgfield"
,
orgField
);
permissionFiled
.
put
(
"orgsecfield"
,
orgDeptField
);
permissionFiled
.
put
(
"createmanfield"
,
createManField
);
permissionFiled
.
put
(
"keyfield"
,
keyField
);
return
permissionFiled
;
}
/**
*
获取含有
@
DEField
注解的实体属性
*
@
param
className
do
对象类名
*
@
return
*/
private
Map
<
Field
,
DEField
>
SearchDEField
(
String
className
){
List
<
Field
>
fields
=
DEFieldCacheMap
.
getFields
(
className
);
Map
<
Field
,
DEField
>
deFieldMap
=
new
HashMap
<>();
for
(
Field
field
:
fields
){
DEField
deField
=
field
.
getAnnotation
(
DEField
.
class
);
if
(
!ObjectUtils.isEmpty(deField)) {
deFieldMap
.
put
(
field
,
deField
);
}
}
return
deFieldMap
;
}
}
\ No newline at end of file
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录