Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-auth-client
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit fb0c68f6
authored
Mar 17, 2022
by
levphon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
共享数据拦截器
1 parent
bd77431b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
21 deletions
src/main/java/cn/com/glsx/auth/api/AuthFeignClient.java
src/main/java/cn/com/glsx/auth/interceptor/DataOnlySharedInterceptor.java
src/main/java/cn/com/glsx/auth/api/AuthFeignClient.java
View file @
fb0c68f
...
...
@@ -6,6 +6,7 @@ import com.glsx.plat.core.web.R;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
java.util.List
;
import
java.util.Set
;
...
...
@@ -33,6 +34,14 @@ public interface AuthFeignClient {
R
<
SyntheticUser
>
getAuthUser
();
/**
* 获取userId用户对应资源等权限
*
* @return
*/
@GetMapping
(
value
=
"/getAuthUserById"
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
R
<
SyntheticUser
>
getAuthUserById
(
@RequestParam
(
"userId"
)
Long
userId
);
/**
* 获取当前登录用户角色数据权限内的部门id
*
* @return
...
...
src/main/java/cn/com/glsx/auth/interceptor/DataOnlySharedInterceptor.java
View file @
fb0c68f
...
...
@@ -94,14 +94,12 @@ public class DataOnlySharedInterceptor implements Interceptor {
}
//拼装sql
String
originSql
=
OriginSqlHolder
.
getSql
();
//获取到当前需要被执行的原始SQL
String
permitSql
=
boundSql
.
getSql
();
//获取到当前需要被执行的权限SQL
String
originSql
=
boundSql
.
getSql
();
//获取到当前需要被执行的SQL
String
relativePertSql
=
assembleLinkOriginSql
(
permitSql
);
//相对数据权限过滤组装
String
linkPermitSql
=
assembleLinkPermitSql
(
originSql
,
dataAuth
,
ShieldContextHolder
.
getUserId
());
//绝对数据权限过滤组装
if
(
dataAuth
.
showSql
())
{
log
.
info
(
"\n
relativePertSql:{}\nlinkPermitSql:{}"
,
relativePert
Sql
,
linkPermitSql
);
log
.
info
(
"\n
originSql:{}\nlinkPermitSql:{}"
,
origin
Sql
,
linkPermitSql
);
}
//复制一份参数
...
...
@@ -126,23 +124,6 @@ public class DataOnlySharedInterceptor implements Interceptor {
return
invocation
.
proceed
();
}
private
String
assembleLinkOriginSql
(
String
sql
)
throws
JSQLParserException
{
Select
select
=
(
Select
)
parserManager
.
parse
(
new
StringReader
(
sql
));
SelectBody
selectBody
=
select
.
getSelectBody
();
PlainSelect
plain
=
(
PlainSelect
)
selectBody
;
plain
.
setOrderByElements
(
null
);
plain
.
setLimit
(
null
);
String
plainStr
=
plain
.
toString
();
return
plainStr
;
}
private
String
assembleLinkPermitSql
(
String
sql
,
DataOnlyShared
dataAuth
,
Long
userId
)
throws
JSQLParserException
{
Select
select
=
(
Select
)
parserManager
.
parse
(
new
StringReader
(
sql
));
...
...
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