Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
wangzhen
/
shiro-test
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2bf04c57
authored
Aug 29, 2024
by
wangzhen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor the classes of the RBAC to PermissionService.
1 parent
3ee60786
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
19 deletions
src/main/java/com/myxrk/rbac/aspect/DataGridMaskAspect.java
src/main/java/com/myxrk/rbac/aspect/DataGridMaskAspect.java
View file @
2bf04c5
...
@@ -2,7 +2,6 @@ package com.myxrk.rbac.aspect;
...
@@ -2,7 +2,6 @@ package com.myxrk.rbac.aspect;
import
com.google.common.base.CaseFormat
;
import
com.google.common.base.CaseFormat
;
import
com.myxrk.rbac.annotation.DataGrid
;
import
com.myxrk.rbac.annotation.DataGrid
;
import
com.myxrk.rbac.po.SysUser
;
import
com.myxrk.rbac.result.Result
;
import
com.myxrk.rbac.result.Result
;
import
com.myxrk.rbac.service.PermissionService
;
import
com.myxrk.rbac.service.PermissionService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -39,7 +38,6 @@ public class DataGridMaskAspect {
...
@@ -39,7 +38,6 @@ public class DataGridMaskAspect {
@Around
(
"@annotation(org.springframework.web.bind.annotation.GetMapping)"
)
@Around
(
"@annotation(org.springframework.web.bind.annotation.GetMapping)"
)
public
Object
maskData
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
public
Object
maskData
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
// 执行目标方法
Object
result
=
joinPoint
.
proceed
();
Object
result
=
joinPoint
.
proceed
();
// 仅处理Result类型,来源与ResponseBodyAdvice处理之后的结果
// 仅处理Result类型,来源与ResponseBodyAdvice处理之后的结果
...
@@ -58,48 +56,49 @@ public class DataGridMaskAspect {
...
@@ -58,48 +56,49 @@ public class DataGridMaskAspect {
}
}
// 获取数据表格唯一标识
// 获取数据表格唯一标识
Method
tm
=
((
MethodSignature
)
joinPoint
.
getSignature
()).
getMethod
(
);
DataGrid
dg
=
getDataGridAnnotation
(
joinPoint
);
DataGrid
dg
=
tm
.
getDeclaredAnnotation
(
DataGrid
.
class
);
if
(
dg
==
null
)
{
if
(
dg
==
null
)
{
return
result
;
return
result
;
}
}
String
dgKey
=
dg
.
value
();
// 获取当前用户
SysUser
sysUser
=
permissionService
.
getSysUser
();
// 获取当前激活角色,激活的角色只能有一个
Long
role
=
permissionService
.
getActiveRole
();
// 获取当前激活角色所关联的数据表格列
List
<
String
>
columns
=
permissionService
.
getColumnsByRoleAndDataGridKey
(
dgKey
,
role
);
maskData
(
data
,
columns
);
// 更具角色控制DataGrid列的显示
maskData
(
dg
.
value
(),
data
);
return
result
;
return
result
;
}
}
// 不支持的返回类型, 直接放行
log
.
warn
(
"Unsupported return type {}"
,
result
.
getClass
());
return
result
;
return
result
;
}
}
private
static
DataGrid
getDataGridAnnotation
(
ProceedingJoinPoint
joinPoint
)
{
Method
tm
=
((
MethodSignature
)
joinPoint
.
getSignature
()).
getMethod
();
return
tm
.
getDeclaredAnnotation
(
DataGrid
.
class
);
}
private
static
Class
<?>
getDataEntryType
(
List
<?>
data
)
{
private
static
Class
<?>
getDataEntryType
(
List
<?>
data
)
{
return
data
.
get
(
0
).
getClass
();
return
data
.
get
(
0
).
getClass
();
}
}
private
static
void
maskData
(
List
<?>
data
,
List
<
String
>
columns
)
{
private
void
maskData
(
String
dgKey
,
List
<?>
data
)
{
// 获取当前激活角色,激活的角色只能有一个
Long
role
=
permissionService
.
getActiveRole
();
// 获取当前激活角色所关联的数据表格列
List
<
String
>
columns
=
permissionService
.
getColumnsByRoleAndDataGridKey
(
dgKey
,
role
);
// 获取数据类型
// 获取数据类型
Class
<?>
genericType
=
getDataEntryType
(
data
);
Class
<?>
genericType
=
getDataEntryType
(
data
);
// 获取返回值的属性列表
// 获取返回值的属性列表
Set
<
String
>
header
=
getTableHeader
(
genericType
);
Set
<
String
>
header
=
getTableHeader
(
genericType
);
if
(!
header
.
containsAll
(
columns
))
{
if
(!
header
.
containsAll
(
columns
))
{
log
.
error
(
"backend data columns doesn't contains all data grid columns, please fix!: {}"
,
columns
);
log
.
error
(
"backend data columns doesn't contains all data grid columns, please fix!: {}"
,
columns
);
return
;
return
;
}
}
// 根据角色屏DataGrid数据列
List
<?>
masked
=
data
.
stream
().
map
(
entry
->
{
List
<?>
masked
=
data
.
stream
().
map
(
entry
->
{
List
<
String
>
masks
=
getMasks
(
columns
,
header
);
List
<
String
>
masks
=
getMasks
(
columns
,
header
);
if
(!
masks
.
isEmpty
())
{
if
(!
masks
.
isEmpty
())
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment