Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
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 03429938
authored
Jul 12, 2023
by
chamberone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 解决向后传递参数报错问题
1 parent
0349ba83
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
13 deletions
project-gateway/src/main/java/com/dituhui/pea/gateway/config/AuthFilter.java
project-user/src/main/java/com/dituhui/pea/user/service/UserService.java
project-gateway/src/main/java/com/dituhui/pea/gateway/config/AuthFilter.java
View file @
0342993
...
...
@@ -68,29 +68,23 @@ public class AuthFilter implements GlobalFilter, Ordered {
if
(
StringUtils
.
isNotEmpty
(
authToken
))
{
// 查询token对应的用户
Object
obj
=
redisService
.
get
(
RedisKeyGroup
.
authToken
+
":"
+
authToken
);
log
.
info
(
"{} {}"
,
authToken
,
obj
);
if
(
null
!=
obj
)
{
userDTO
=
(
UserLoginDTO
)
obj
;
}
// Result<?> userResult = userService.getUserInfo(authToken);
// if (ResultEnum.SUCCESS.getCode().equals(userResult.getCode())) {
// userDTO = (UserLoginDTO) userResult.getResult();
// }
}
if
(
userDTO
==
null
)
{
log
.
info
(
"未授权访问{} ip:{}"
,
url
,
getRemoteIP
(
exchange
));
}
else
{
log
.
info
(
"用户:{} id:{} 访问{}"
,
userDTO
.
getAccount
(),
userDTO
.
getId
(),
url
);
// 获取当前的请求对象信息
exchange
.
getRequest
().
getHeaders
().
add
(
"userId"
,
userDTO
.
getId
());
// ServerHttpRequest.Builder builder = exchange.getRequest().mutate();
// // 向header中设置新的key,存储解析好的token对应基本信息
// builder.header("userId", userDTO.getId());
// // 向下游传递
// return chain.filter(exchange.mutate().request(builder.build()).build());
// exchange.getRequest().getHeaders().add("userId", userDTO.getId());
ServerHttpRequest
.
Builder
builder
=
exchange
.
getRequest
().
mutate
();
// 向header中设置新的key,存储解析好的token对应基本信息
builder
.
header
(
"userId"
,
userDTO
.
getId
());
// 向下游传递
Authentication
authentication
=
new
UsernamePasswordAuthenticationToken
(
userDTO
.
getAccount
(),
null
,
null
);
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
return
chain
.
filter
(
exchange
.
mutate
().
request
(
builder
.
build
()).
build
());
}
return
chain
.
filter
(
exchange
);
...
...
project-user/src/main/java/com/dituhui/pea/user/service/UserService.java
View file @
0342993
...
...
@@ -93,7 +93,7 @@ public class UserService {
String
token
=
IdUtil
.
simpleUUID
();
userDTO
.
setToken
(
token
);
long
timestamp
=
System
.
currentTimeMillis
()
+
LIVE_TIME_MILLIS
;
redisService
.
set
(
RedisKeyGroup
.
authToken
+
":"
+
token
,
userDTO
,
timestamp
);
redisService
.
set
(
RedisKeyGroup
.
authToken
+
":"
+
token
,
userDTO
,
timestamp
/
1000
);
return
Result
.
success
(
userDTO
);
}
else
{
return
Result
.
failed
(
"鉴权失败"
);
...
...
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