Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
谢明辉
/
fanxing3
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 9392020c
authored
Dec 08, 2021
by
xmh
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
<fix> 修复用户名传输时中文乱码
1 parent
57b9e902
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
5 deletions
fanxing-gateway/src/main/java/com/viontech/fanxing/forward/AuthorizationFilter.java
fanxing-ops/src/main/java/com/viontech/fanxing/ops/service/impl/LogServiceImpl.java
fanxing-query/src/main/java/com/viontech/fanxing/query/service/main/OpsClientService.java
fanxing-task/src/main/java/com/viontech/fanxing/task/service/OpsClientService.java
fanxing-gateway/src/main/java/com/viontech/fanxing/forward/AuthorizationFilter.java
View file @
9392020
...
@@ -20,6 +20,8 @@ import org.springframework.web.server.ServerWebExchange;
...
@@ -20,6 +20,8 @@ import org.springframework.web.server.ServerWebExchange;
import
reactor.core.publisher.Mono
;
import
reactor.core.publisher.Mono
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -63,10 +65,16 @@ public class AuthorizationFilter implements GlobalFilter {
...
@@ -63,10 +65,16 @@ public class AuthorizationFilter implements GlobalFilter {
return
unAuthorized
(
exchange
.
getResponse
(),
checkResult
.
right
);
return
unAuthorized
(
exchange
.
getResponse
(),
checkResult
.
right
);
}
}
// 添加 username 到 header 中, 供之后的服务使用
// 添加 username 到 header 中, 供之后的服务使用
ServerHttpRequest
req
=
request
.
mutate
().
headers
(
headers
->
headers
.
add
(
"username"
,
checkResult
.
right
)).
build
();
ServerHttpRequest
req
=
request
.
mutate
().
headers
(
headers
->
{
try
{
headers
.
add
(
"username"
,
URLEncoder
.
encode
(
checkResult
.
right
,
"utf8"
));
}
catch
(
UnsupportedEncodingException
e
)
{
log
.
error
(
""
,
e
);
}
}).
build
();
exchange
.
mutate
().
request
(
req
).
build
();
exchange
.
mutate
().
request
(
req
).
build
();
log
.
info
(
"token 校验成功:
{}"
,
token
);
log
.
info
(
"token 校验成功:
[{}][{}]"
,
checkResult
.
right
,
token
);
}
}
return
chain
.
filter
(
exchange
);
return
chain
.
filter
(
exchange
);
}
}
...
...
fanxing-ops/src/main/java/com/viontech/fanxing/ops/service/impl/LogServiceImpl.java
View file @
9392020
...
@@ -13,6 +13,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
...
@@ -13,6 +13,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.net.URLDecoder
;
import
java.util.Date
;
import
java.util.Date
;
@Service
@Service
...
@@ -33,7 +34,7 @@ public class LogServiceImpl extends BaseServiceImpl<Log> implements LogService {
...
@@ -33,7 +34,7 @@ public class LogServiceImpl extends BaseServiceImpl<Log> implements LogService {
String
username
=
null
;
String
username
=
null
;
if
(
requestAttributes
!=
null
)
{
if
(
requestAttributes
!=
null
)
{
HttpServletRequest
request
=
((
ServletRequestAttributes
)
requestAttributes
).
getRequest
();
HttpServletRequest
request
=
((
ServletRequestAttributes
)
requestAttributes
).
getRequest
();
username
=
request
.
getHeader
(
"username
"
);
username
=
URLDecoder
.
decode
(
request
.
getHeader
(
"username"
),
"utf8
"
);
}
}
Log
log
=
new
Log
();
Log
log
=
new
Log
();
log
.
setUsername
(
username
);
log
.
setUsername
(
username
);
...
...
fanxing-query/src/main/java/com/viontech/fanxing/query/service/main/OpsClientService.java
View file @
9392020
...
@@ -15,6 +15,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
...
@@ -15,6 +15,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.net.URLDecoder
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
@@ -80,7 +81,7 @@ public class OpsClientService {
...
@@ -80,7 +81,7 @@ public class OpsClientService {
String
username
=
null
;
String
username
=
null
;
if
(
requestAttributes
!=
null
)
{
if
(
requestAttributes
!=
null
)
{
HttpServletRequest
request
=
((
ServletRequestAttributes
)
requestAttributes
).
getRequest
();
HttpServletRequest
request
=
((
ServletRequestAttributes
)
requestAttributes
).
getRequest
();
username
=
request
.
getHeader
(
"username
"
);
username
=
URLDecoder
.
decode
(
request
.
getHeader
(
"username"
),
"utf8
"
);
}
}
LogVo
logVo
=
new
LogVo
();
LogVo
logVo
=
new
LogVo
();
logVo
.
setUsername
(
username
);
logVo
.
setUsername
(
username
);
...
...
fanxing-task/src/main/java/com/viontech/fanxing/task/service/OpsClientService.java
View file @
9392020
...
@@ -17,6 +17,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
...
@@ -17,6 +17,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.net.URLDecoder
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -79,7 +80,7 @@ public class OpsClientService {
...
@@ -79,7 +80,7 @@ public class OpsClientService {
String
username
=
null
;
String
username
=
null
;
if
(
requestAttributes
!=
null
)
{
if
(
requestAttributes
!=
null
)
{
HttpServletRequest
request
=
((
ServletRequestAttributes
)
requestAttributes
).
getRequest
();
HttpServletRequest
request
=
((
ServletRequestAttributes
)
requestAttributes
).
getRequest
();
username
=
request
.
getHeader
(
"username
"
);
username
=
URLDecoder
.
decode
(
request
.
getHeader
(
"username"
),
"utf8
"
);
}
}
LogVo
logVo
=
new
LogVo
();
LogVo
logVo
=
new
LogVo
();
logVo
.
setUsername
(
username
);
logVo
.
setUsername
(
username
);
...
...
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