Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hphy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
向怀芳
hphy
Commits
48c7badf
Commit
48c7badf
authored
Oct 20, 2022
by
向怀芳
🎱
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. IP白名单02
parent
0cf3fe3d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
9 deletions
+12
-9
PasswordDecoderFilter.java
...ct/cloud/common/gateway/filter/PasswordDecoderFilter.java
+7
-9
RequestGlobalFilter.java
...sict/cloud/common/gateway/filter/RequestGlobalFilter.java
+5
-0
No files found.
cloud-common/cloud-common-gateway/src/main/java/cn/sh/stc/sict/cloud/common/gateway/filter/PasswordDecoderFilter.java
View file @
48c7badf
...
@@ -61,8 +61,6 @@ public class PasswordDecoderFilter extends AbstractGatewayFilterFactory {
...
@@ -61,8 +61,6 @@ public class PasswordDecoderFilter extends AbstractGatewayFilterFactory {
public
GatewayFilter
apply
(
Object
config
)
{
public
GatewayFilter
apply
(
Object
config
)
{
return
(
exchange
,
chain
)
->
{
return
(
exchange
,
chain
)
->
{
ServerHttpRequest
request
=
exchange
.
getRequest
();
ServerHttpRequest
request
=
exchange
.
getRequest
();
// IP白名单
log
.
error
(
"RemoteAddress ===================> {}"
,
request
.
getRemoteAddress
());
// 不是登录请求,直接向下执行
// 不是登录请求,直接向下执行
if
(!
StrUtil
.
containsAnyIgnoreCase
(
request
.
getURI
().
getPath
(),
SecurityConstants
.
OAUTH_TOKEN_URL
))
{
if
(!
StrUtil
.
containsAnyIgnoreCase
(
request
.
getURI
().
getPath
(),
SecurityConstants
.
OAUTH_TOKEN_URL
))
{
...
@@ -70,19 +68,19 @@ public class PasswordDecoderFilter extends AbstractGatewayFilterFactory {
...
@@ -70,19 +68,19 @@ public class PasswordDecoderFilter extends AbstractGatewayFilterFactory {
}
}
URI
uri
=
exchange
.
getRequest
().
getURI
();
URI
uri
=
exchange
.
getRequest
().
getURI
();
log
.
error
(
"uri ==============>: {}"
,
uri
.
toString
());
//
log.error("uri ==============>: {}", uri.toString());
String
queryParam
=
uri
.
getRawQuery
();
String
queryParam
=
uri
.
getRawQuery
();
log
.
error
(
"queryParam==============>: {}"
,
queryParam
);
//
log.error("queryParam==============>: {}", queryParam);
Map
<
String
,
String
>
paramMap
=
HttpUtil
.
decodeParamMap
(
queryParam
,
CharsetUtil
.
UTF_8
);
Map
<
String
,
String
>
paramMap
=
HttpUtil
.
decodeParamMap
(
queryParam
,
CharsetUtil
.
UTF_8
);
log
.
error
(
"paramMap==============>: {}"
,
paramMap
.
toString
());
//
log.error("paramMap==============>: {}", paramMap.toString());
String
password
=
paramMap
.
get
(
PASSWORD
);
String
password
=
paramMap
.
get
(
PASSWORD
);
if
(
StrUtil
.
isNotBlank
(
password
))
{
if
(
StrUtil
.
isNotBlank
(
password
))
{
try
{
try
{
// password = decryptAES(password, encodeKey);
// password = decryptAES(password, encodeKey);
log
.
error
(
"before password: {}"
,
password
);
//
log.error("before password: {}", password);
password
=
CryptUtil
.
AESToString
(
password
,
encodeKey
);
password
=
CryptUtil
.
AESToString
(
password
,
encodeKey
);
log
.
error
(
"after password: {}"
,
password
);
//
log.error("after password: {}", password);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"密码解密失败:password = {}"
,
password
);
log
.
error
(
"密码解密失败:password = {}"
,
password
);
return
Mono
.
error
(
e
);
return
Mono
.
error
(
e
);
...
@@ -93,9 +91,9 @@ public class PasswordDecoderFilter extends AbstractGatewayFilterFactory {
...
@@ -93,9 +91,9 @@ public class PasswordDecoderFilter extends AbstractGatewayFilterFactory {
if
(
StrUtil
.
isNotBlank
(
username
))
{
if
(
StrUtil
.
isNotBlank
(
username
))
{
try
{
try
{
// password = decryptAES(password, encodeKey);
// password = decryptAES(password, encodeKey);
log
.
error
(
"before username: {}"
,
username
);
//
log.error("before username: {}", username);
username
=
CryptUtil
.
AESToString
(
username
,
encodeKey
);
username
=
CryptUtil
.
AESToString
(
username
,
encodeKey
);
log
.
error
(
"after username: {}"
,
username
);
//
log.error("after username: {}", username);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"用户名解密失败:username = {}"
,
username
);
log
.
error
(
"用户名解密失败:username = {}"
,
username
);
return
Mono
.
error
(
e
);
return
Mono
.
error
(
e
);
...
...
cloud-common/cloud-common-gateway/src/main/java/cn/sh/stc/sict/cloud/common/gateway/filter/RequestGlobalFilter.java
View file @
48c7badf
package
cn
.
sh
.
stc
.
sict
.
cloud
.
common
.
gateway
.
filter
;
package
cn
.
sh
.
stc
.
sict
.
cloud
.
common
.
gateway
.
filter
;
import
cn.sh.stc.sict.cloud.common.core.constant.SecurityConstants
;
import
cn.sh.stc.sict.cloud.common.core.constant.SecurityConstants
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.cloud.gateway.filter.GatewayFilterChain
;
import
org.springframework.cloud.gateway.filter.GatewayFilterChain
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.Ordered
;
...
@@ -28,6 +29,7 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.a
...
@@ -28,6 +29,7 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.a
* @Author
* @Author
* @Date
* @Date
*/
*/
@Slf4j
@Component
@Component
public
class
RequestGlobalFilter
implements
GlobalFilter
,
Ordered
{
public
class
RequestGlobalFilter
implements
GlobalFilter
,
Ordered
{
private
static
final
String
HEADER_NAME
=
"X-Forwarded-Prefix"
;
private
static
final
String
HEADER_NAME
=
"X-Forwarded-Prefix"
;
...
@@ -47,6 +49,9 @@ public class RequestGlobalFilter implements GlobalFilter, Ordered {
...
@@ -47,6 +49,9 @@ public class RequestGlobalFilter implements GlobalFilter, Ordered {
.
headers
(
httpHeaders
->
{
httpHeaders
.
remove
(
SecurityConstants
.
FROM
);})
.
headers
(
httpHeaders
->
{
httpHeaders
.
remove
(
SecurityConstants
.
FROM
);})
.
build
();
.
build
();
// IP白名单
log
.
error
(
"RemoteAddress ===================> {}"
,
request
.
getRemoteAddress
());
// 2. 重写StripPrefix
// 2. 重写StripPrefix
addOriginalRequestUrl
(
exchange
,
request
.
getURI
());
addOriginalRequestUrl
(
exchange
,
request
.
getURI
());
String
rawPath
=
request
.
getURI
().
getRawPath
();
String
rawPath
=
request
.
getURI
().
getRawPath
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment