Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzuaa
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzuaa
提交
a96b989b
提交
a96b989b
编写于
5月 14, 2020
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
菜单usr代码
上级
1b27b217
变更
2
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
214 行增加
和
38 行删除
+214
-38
ClientAuthenticationResource.java
...lab/api/rest/extensions/ClientAuthenticationResource.java
+53
-7
PermissionFeignService.java
...n/ibizlab/api/rest/extensions/PermissionFeignService.java
+161
-31
未找到文件。
ibzuaa-provider/ibzuaa-provider-api/src/main/java/cn/ibizlab/api/rest/extensions/ClientAuthenticationResource.java
浏览文件 @
a96b989b
...
...
@@ -14,13 +14,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.util.StringUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -48,6 +46,10 @@ public class ClientAuthenticationResource
* 统一资源标识
*/
private
String
UniResTag
=
"UNIRES"
;
/**
* 菜单项标识
*/
private
String
AppMenuTag
=
"APPMENU"
;
@Autowired
@Qualifier
(
"IBZUSERService"
)
...
...
@@ -107,6 +109,7 @@ public class ClientAuthenticationResource
JSONObject
permissionObj
=
new
JSONObject
();
//数据能力
String
opprivSQL
=
"SELECT\n"
+
"\tT2.pssysmoduleid as sysmodule,\n"
+
"\tT2.psdataentityid as dataentity,\n"
+
...
...
@@ -128,8 +131,7 @@ public class ClientAuthenticationResource
"\t)\n"
+
"AND T1.PERMISSIONTYPE = #{et.param1} "
;
//统一资源
String
uniResSQL
=
"SELECT\n"
+
"\tt2.SYS_PSSYSUNIRESID,\n"
+
"\tt2.SYS_PSSYSUNIRESNAME,\n"
+
...
...
@@ -148,24 +150,68 @@ public class ClientAuthenticationResource
"\t)\n"
+
"AND T1.PERMISSIONTYPE = #{et.param1} "
;
//应用菜单
String
appMenuSQL
=
"SELECT\n"
+
"\tt2.PSAPPPMENUITEMID as MENUITEMID,\n"
+
"\tt2.SYS_PSAPPMENUITEMNAME AS MENUITEMNAME \n"
+
"FROM\n"
+
"\tibzrole_permission T\n"
+
"INNER JOIN ibzpermission T1 ON T.SYS_PERMISSIONID = T1.SYS_PERMISSIONID\n"
+
"INNER JOIN ibzpsappmenuitem T2 on T1.SYS_PERMISSIONID=t2.SYS_PSAPPMENUITEMID\n"
+
"WHERE\n"
+
"\tT.SYS_ROLEID IN (\n"
+
"\t SELECT SYS_ROLEID\n"
+
"\t FROM\n"
+
"\t IBZUSER_ROLE t LEFT JOIN IBZUSER t1 ON t.SYS_USERID=T1.USERID\n"
+
"\t WHERE\n"
+
"\t T1.USERID = #{et.param0}\n"
+
"\t)\n"
+
"AND T1.PERMISSIONTYPE = #{et.param1} "
;
Map
opprivParam
=
new
HashMap
();
opprivParam
.
put
(
"param0"
,
user
.
getUserid
());
opprivParam
.
put
(
"param1"
,
OPPriTag
);
List
<
JSONObject
>
entitiesList
=
permissionService
.
select
(
opprivSQL
,
opprivParam
);
//查询用户权限下的菜单数据
Map
uniresParam
=
new
HashMap
();
uniresParam
.
put
(
"param0"
,
user
.
getUserid
());
uniresParam
.
put
(
"param1"
,
UniResTag
);
List
<
JSONObject
>
uniResList
=
permissionService
.
select
(
uniResSQL
,
uniresParam
);
//查询用户权限下的菜单数据
Map
appMenuParam
=
new
HashMap
();
appMenuParam
.
put
(
"param0"
,
user
.
getUserid
());
appMenuParam
.
put
(
"param1"
,
AppMenuTag
);
List
<
JSONObject
>
entitiesList
=
permissionService
.
select
(
opprivSQL
,
opprivParam
);
//查询用户权限下数据能力
List
<
JSONObject
>
uniResList
=
permissionService
.
select
(
uniResSQL
,
uniresParam
);
//查询用户权限下的统一资源
List
<
JSONObject
>
appMenuItemList
=
permissionService
.
select
(
appMenuSQL
,
appMenuParam
);
//查询用户权限下的菜单项
JSONObject
entities
=
getEntitiesList
(
entitiesList
);
JSONArray
uniRes
=
getUniRes
(
uniResList
);
JSONArray
appMenuItem
=
getAppMenuItem
(
appMenuItemList
);
permissionObj
.
put
(
"entities"
,
entities
);
permissionObj
.
put
(
"unires"
,
uniRes
);
permissionObj
.
put
(
"appmenu"
,
appMenuItem
);
user
.
setPermissionList
(
permissionObj
);
}
/**
* 获取应用菜单
* @param menuItemList
* @return
*/
private
JSONArray
getAppMenuItem
(
List
<
JSONObject
>
menuItemList
)
{
JSONArray
menuItemArr
=
new
JSONArray
();
for
(
int
a
=
0
;
a
<
menuItemList
.
size
();
a
++){
JSONObject
menuItem
=
menuItemList
.
get
(
a
);
JSONObject
newMenuItem
=
new
JSONObject
();
newMenuItem
.
put
(
"menuitemid"
,
menuItem
.
getString
(
"MENUITEMID"
));
newMenuItem
.
put
(
"menuitemname"
,
menuItem
.
getString
(
"MENUITEMNAME"
));
menuItemArr
.
add
(
newMenuItem
);
}
return
menuItemArr
;
}
/**
* 获取统一资源
* @param uniResList
...
...
ibzuaa-provider/ibzuaa-provider-api/src/main/java/cn/ibizlab/api/rest/extensions/PermissionFeignService.java
浏览文件 @
a96b989b
package
cn
.
ibizlab
.
api
.
rest
.
extensions
;
import
cn.ibizlab.core.uaa.domain.SYS_PERMISSION
;
import
cn.ibizlab.core.uaa.domain.SYS_PSAPPMENUITEM
;
import
cn.ibizlab.core.uaa.domain.SYS_PSDEOPPRIV
;
import
cn.ibizlab.core.uaa.domain.SYS_PSSYSUNIRES
;
import
cn.ibizlab.core.uaa.service.ISYS_PERMISSIONService
;
import
cn.ibizlab.core.uaa.service.ISYS_PSAPPMENUITEMService
;
import
cn.ibizlab.core.uaa.service.ISYS_PSDEOPPRIVService
;
import
cn.ibizlab.core.uaa.service.ISYS_PSSYSUNIRESService
;
import
com.alibaba.fastjson.JSONArray
;
...
...
@@ -16,10 +18,8 @@ import org.springframework.validation.annotation.Validated;
import
org.springframework.web.bind.annotation.*
;
import
javax.validation.constraints.NotBlank
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.sql.Timestamp
;
import
java.util.*
;
/**
* 为业务系统提供权限相关服务
...
...
@@ -37,6 +37,10 @@ public class PermissionFeignService {
* 统一资源标识
*/
private
String
UniResTag
=
"UNIRES"
;
/**
* 菜单项标识
*/
private
String
AppMenuTag
=
"APPMENU"
;
/**
* 实体行为操作标识
*/
...
...
@@ -55,12 +59,15 @@ public class PermissionFeignService {
@Autowired
private
ISYS_PSSYSUNIRESService
pssysuniresService
;
@Autowired
private
ISYS_PSAPPMENUITEMService
psappmenuitemService
;
/**
* 拿到业务系统传过来的权限和菜单数据,存入uaa的权限表中
*/
@PostMapping
(
"/uaa/permission/save"
)
public
Map
<
String
,
JsonNode
>
pushSystemPermissionData
(
@RequestBody
Map
<
String
,
Object
>
map
,
@Validated
@NotBlank
(
message
=
"systemid不允许为空"
)
@RequestParam
(
"systemid"
)
String
systemId
){
public
JSONObject
pushSystemPermissionData
(
@RequestBody
Map
<
String
,
Object
>
map
,
@Validated
@NotBlank
(
message
=
"systemid不允许为空"
)
@RequestParam
(
"systemid"
)
String
systemId
){
try
{
//如果map值不为null说明要更新数据,则先将表中该系统标识下的所有数据进行逻辑删除
Map
param
=
new
HashMap
();
param
.
put
(
"param0"
,
systemId
);
...
...
@@ -69,25 +76,126 @@ public class PermissionFeignService {
permissionService
.
execute
(
sql
,
param
);
}
List
<
SYS_PSDEOPPRIV
>
opprivList
=
new
ArrayList
<>();
//数据能力
List
<
SYS_PERMISSION
>
permission_list
=
new
ArrayList
<>();
//权限
List
<
SYS_PERMISSION
>
permission_list
=
new
ArrayList
<>();
//资源
List
<
SYS_PSSYSUNIRES
>
unires_list
=
new
ArrayList
<>();
//统一资源
List
<
SYS_PSAPPMENUITEM
>
menu_list
=
new
ArrayList
<>();
//资源-菜单项集合
if
(
map
.
containsKey
(
"permission"
)){
JSONObject
paramsObj
=
new
JSONObject
(
map
);
JSONObject
capabilityPermissionObj
=
paramsObj
.
getJSONObject
(
"permission"
);
parseDECapability
(
capabilityPermissionObj
,
systemId
,
permission_list
,
opprivList
);
parseUniRes
(
capabilityPermissionObj
,
systemId
,
permission_list
,
unires_list
);
parseAppMenus
(
capabilityPermissionObj
,
systemId
,
permission_list
,
menu_list
);
}
if
(
opprivList
.
size
()>
0
){
opprivService
.
saveOrUpdateBatch
(
opprivList
);
//批量保存数据能力
}
if
(
unires_list
.
size
()>
0
){
pssysuniresService
.
saveOrUpdateBatch
(
unires_list
);
//批量保存统一资源
}
if
(
menu_list
.
size
()>
0
){
psappmenuitemService
.
saveOrUpdateBatch
(
menu_list
);
//批量保存统一资源
}
if
(
permission_list
.
size
()>
0
){
permissionService
.
saveOrUpdateBatch
(
permission_list
);
//批量保存权限资源
}
if
(
unires_list
.
size
()>
0
)
{
pssysuniresService
.
saveOrUpdateBatch
(
unires_list
);
//批量保存统一资源
}
catch
(
Exception
e
)
{
return
error
(
"资源同步失败,失败原因为:"
+
e
);
}
return
null
;
return
success
(
"资源同步成功"
);
}
/**
* 存储菜单资源
* @param capabilityPermissionObj
* @param systemId
* @param permission_list
* @param menu_list
*/
private
void
parseAppMenus
(
JSONObject
capabilityPermissionObj
,
String
systemId
,
List
<
SYS_PERMISSION
>
permission_list
,
List
<
SYS_PSAPPMENUITEM
>
menu_list
)
{
if
(
capabilityPermissionObj
!=
null
)
{
JSONArray
appMenuArr
=
capabilityPermissionObj
.
getJSONArray
(
"appmenus"
);
if
(
appMenuArr
.
size
()>
0
){
for
(
int
a
=
0
;
a
<
appMenuArr
.
size
();
a
++){
JSONObject
App
=
appMenuArr
.
getJSONObject
(
a
);
String
appId
=
App
.
getString
(
"appid"
);
String
appName
=
App
.
getString
(
"appname"
);
if
(
App
.
containsKey
(
"appmenu"
)
&&
App
.
getJSONArray
(
"appmenu"
).
size
()>
0
){
JSONArray
AppMenuArr
=
App
.
getJSONArray
(
"appmenu"
);
for
(
int
b
=
0
;
b
<
AppMenuArr
.
size
();
b
++){
JSONObject
appMenu
=
AppMenuArr
.
getJSONObject
(
b
);
String
appMenuId
=
appMenu
.
getString
(
"menuid"
);
String
appMenuName
=
appMenu
.
getString
(
"menuname"
);
if
(
appMenu
.
containsKey
(
"menuitem"
)&&
appMenu
.
getJSONArray
(
"menuitem"
).
size
()>
0
){
JSONArray
menuItemArr
=
appMenu
.
getJSONArray
(
"menuitem"
);
parseMenuItems
(
menuItemArr
,
""
,
systemId
,
appId
,
appName
,
appMenuId
,
appMenuName
,
permission_list
,
menu_list
);
}
}
}
}
}
}
}
/**
* 解析菜单项集合
* @param menuItemArr
* @param systemId
* @param permission_list
* @param menu_list
*/
private
void
parseMenuItems
(
JSONArray
menuItemArr
,
String
parentMenuItemId
,
String
systemId
,
String
appId
,
String
appName
,
String
appMenuId
,
String
appMenuName
,
List
<
SYS_PERMISSION
>
permission_list
,
List
<
SYS_PSAPPMENUITEM
>
menu_list
){
for
(
int
a
=
0
;
a
<
menuItemArr
.
size
();
a
++){
JSONObject
menuItem
=
menuItemArr
.
getJSONObject
(
a
);
String
menuItemId
=
menuItem
.
getString
(
"id"
);
String
menuItemName
=
menuItem
.
getString
(
"name"
);
if
(
menuItem
.
containsKey
(
"items"
)
&&
menuItem
.
getJSONArray
(
"items"
).
size
()>
0
){
JSONArray
tempMenuItems
=
menuItem
.
getJSONArray
(
"items"
);
parseMenuItems
(
tempMenuItems
,
menuItemId
,
systemId
,
appId
,
appName
,
appMenuId
,
appMenuName
,
permission_list
,
menu_list
);
}
saveMenuItem
(
menuItemId
,
menuItemName
,
parentMenuItemId
,
systemId
,
appId
,
appName
,
appMenuId
,
appMenuName
,
permission_list
,
menu_list
);
}
}
/**
* 保存菜单项
* @param menuItemId
* @param menuItemName
* @param parentMenuItemId
* @param systemId
* @param appId
* @param appName
* @param appMenuId
* @param appMenuName
* @param permission_list
* @param menu_list
*/
private
void
saveMenuItem
(
String
menuItemId
,
String
menuItemName
,
String
parentMenuItemId
,
String
systemId
,
String
appId
,
String
appName
,
String
appMenuId
,
String
appMenuName
,
List
<
SYS_PERMISSION
>
permission_list
,
List
<
SYS_PSAPPMENUITEM
>
menu_list
){
String
sysPermissionId
=
DigestUtils
.
md5DigestAsHex
(
String
.
format
(
"%s%s%s%s"
,
systemId
,
appId
,
appMenuId
,
menuItemId
).
getBytes
());
SYS_PERMISSION
sys_permission
=
new
SYS_PERMISSION
();
sys_permission
.
setPermissionid
(
sysPermissionId
);
sys_permission
.
setPermissionname
(
menuItemName
);
sys_permission
.
setPssystemid
(
systemId
);
sys_permission
.
setPermissiontype
(
AppMenuTag
);
sys_permission
.
setEnable
(
1
);
sys_permission
.
setCreatedate
(
new
Timestamp
(
new
Date
().
getTime
()));
sys_permission
.
setUpdatedate
(
new
Timestamp
(
new
Date
().
getTime
()));
permission_list
.
add
(
sys_permission
);
//存菜单项表
SYS_PSAPPMENUITEM
psAppMenuItem
=
new
SYS_PSAPPMENUITEM
();
psAppMenuItem
.
setAppmenuitemid
(
sysPermissionId
);
psAppMenuItem
.
setAppmenuitemname
(
menuItemName
);
psAppMenuItem
.
setPsappid
(
appId
);
psAppMenuItem
.
setPsappname
(
appName
);
psAppMenuItem
.
setPsappmenuid
(
appMenuId
);
psAppMenuItem
.
setPsappmenuname
(
appMenuName
);
psAppMenuItem
.
setPssystemid
(
systemId
);
psAppMenuItem
.
setPsappmenuitemid
(
menuItemId
);
psAppMenuItem
.
setPsapppmenuitemid
(
parentMenuItemId
);
psAppMenuItem
.
setCreatedate
(
new
Timestamp
(
new
Date
().
getTime
()));
psAppMenuItem
.
setUpdatedate
(
new
Timestamp
(
new
Date
().
getTime
()));
menu_list
.
add
(
psAppMenuItem
);
}
/**
...
...
@@ -122,12 +230,16 @@ public class PermissionFeignService {
sys_permission
.
setPssystemid
(
systemId
);
sys_permission
.
setPermissiontype
(
UniResTag
);
sys_permission
.
setEnable
(
1
);
sys_permission
.
setCreatedate
(
new
Timestamp
(
new
Date
().
getTime
()));
sys_permission
.
setUpdatedate
(
new
Timestamp
(
new
Date
().
getTime
()));
permission_list
.
add
(
sys_permission
);
SYS_PSSYSUNIRES
sys_pssysunires
=
new
SYS_PSSYSUNIRES
();
sys_pssysunires
.
setUniresid
(
uniResId
);
sys_pssysunires
.
setUniresname
(
uniResName
);
sys_pssysunires
.
setUnirescode
(
uniResCode
);
sys_pssysunires
.
setCreatedate
(
new
Timestamp
(
new
Date
().
getTime
()));
sys_pssysunires
.
setUpdatedate
(
new
Timestamp
(
new
Date
().
getTime
()));
unires_list
.
add
(
sys_pssysunires
);
}
...
...
@@ -167,9 +279,10 @@ public class PermissionFeignService {
for
(
int
b
=
0
;
b
<
deActionArray
.
size
();
b
++)
{
JSONObject
deSource
=
deActionArray
.
getJSONObject
(
b
);
String
deActionType
=
deSource
.
getString
(
"type"
);
if
(
permissionType
.
equalsIgnoreCase
(
DEActionType
)
&&
!
StringUtils
.
isEmpty
(
deActionType
)
&&
!
deActionType
.
equalsIgnoreCase
(
"BUILTIN"
))
{
//数据查询与自定义行为不生成预置范围相关数据
if
(
(
permissionType
.
equalsIgnoreCase
(
DEActionType
)
&&
!
deActionType
.
equalsIgnoreCase
(
"BUILTIN"
))
||
(
permissionType
.
equalsIgnoreCase
(
DataSetTag
))
)
{
JSONObject
dataRange
=
new
JSONObject
();
createDataRange
(
entity
,
deSource
,
dataRange
,
permissionType
,
systemId
,
ability_list
,
opprivList
);
//自定义用户行为
createDataRange
(
entity
,
deSource
,
dataRange
,
permissionType
,
systemId
,
ability_list
,
opprivList
);
}
else
{
for
(
int
c
=
0
;
c
<
preDefinedDataRange
.
size
();
c
++){
...
...
@@ -219,6 +332,8 @@ public class PermissionFeignService {
sys_permission
.
setPermissionid
(
permissionId
);
sys_permission
.
setPermissiontype
(
OPPriTag
);
sys_permission
.
setEnable
(
1
);
sys_permission
.
setUpdatedate
(
new
Timestamp
(
new
Date
().
getTime
()));
sys_permission
.
setCreatedate
(
new
Timestamp
(
new
Date
().
getTime
()));
ability_list
.
add
(
sys_permission
);
//存数据操作能力表
...
...
@@ -235,8 +350,23 @@ public class PermissionFeignService {
psDEOppriv
.
setPsdedatarangeid
(
dataRangeId
);
psDEOppriv
.
setPsdedatarangename
(
dataRangeName
);
psDEOppriv
.
setPssourcetype
(
permissionType
);
psDEOppriv
.
setCreatedate
(
new
Timestamp
(
new
Date
().
getTime
()));
psDEOppriv
.
setUpdatedate
(
new
Timestamp
(
new
Date
().
getTime
()));
opprivList
.
add
(
psDEOppriv
);
}
private
JSONObject
success
(
String
msg
){
JSONObject
obj
=
new
JSONObject
();
obj
.
put
(
"code"
,
1
);
obj
.
put
(
"msg"
,
msg
);
return
obj
;
}
private
JSONObject
error
(
String
msg
){
JSONObject
obj
=
new
JSONObject
();
obj
.
put
(
"code"
,
0
);
obj
.
put
(
"msg"
,
msg
);
return
obj
;
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录