Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-gateway-server
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 9fd172f9
authored
Jun 29, 2023
by
刘宇峰
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
加入swagger放通拦截
1 parent
4afb0539
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
1 deletions
src/main/java/com/glsx/plat/gateway/filter/GlobalAuthGlobalFilter.java
src/main/java/com/glsx/plat/gateway/filter/GlobalAuthGlobalFilter.java
View file @
9fd172f
...
@@ -24,6 +24,7 @@ import org.springframework.http.MediaType;
...
@@ -24,6 +24,7 @@ import org.springframework.http.MediaType;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
import
org.springframework.http.server.reactive.ServerHttpResponse
;
import
org.springframework.http.server.reactive.ServerHttpResponse
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.AntPathMatcher
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.ServerWebExchange
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
reactor.core.publisher.Mono
;
...
@@ -32,6 +33,7 @@ import java.nio.charset.StandardCharsets;
...
@@ -32,6 +33,7 @@ import java.nio.charset.StandardCharsets;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
/**
/**
* @author payu
* @author payu
...
@@ -64,7 +66,7 @@ public class GlobalAuthGlobalFilter implements GlobalFilter, Ordered {
...
@@ -64,7 +66,7 @@ public class GlobalAuthGlobalFilter implements GlobalFilter, Ordered {
String
url
=
request
.
getURI
().
getPath
();
String
url
=
request
.
getURI
().
getPath
();
//跳过不需要验证的路径
//跳过不需要验证的路径
if
(
Arrays
.
asList
(
skipAuthUrls
).
contains
(
url
))
{
if
(
isMatchedStr
(
skipAuthUrls
,
url
))
{
return
chain
.
filter
(
exchange
);
return
chain
.
filter
(
exchange
);
}
}
...
@@ -157,4 +159,26 @@ public class GlobalAuthGlobalFilter implements GlobalFilter, Ordered {
...
@@ -157,4 +159,26 @@ public class GlobalAuthGlobalFilter implements GlobalFilter, Ordered {
//return stringRedisTemplate.hasKey(String.format(properties.getBlacklistKey(), token));
//return stringRedisTemplate.hasKey(String.format(properties.getBlacklistKey(), token));
}
}
/**
* 判断当前访问的url是否开头URI是在配置的忽略url列表中
*
* @param url
* @return
*/
public
static
boolean
isMatchedStr
(
String
[]
skipAuthUrls
,
String
url
)
{
if
(
StringUtils
.
isEmpty
(
url
))
{
return
false
;
}
if
(
Objects
.
isNull
(
skipAuthUrls
))
{
return
false
;
}
AntPathMatcher
matcher
=
new
AntPathMatcher
();
for
(
String
skipAuthUrl
:
skipAuthUrls
)
{
if
(
matcher
.
match
(
skipAuthUrl
,
url
))
{
return
true
;
}
}
return
false
;
}
}
}
\ No newline at end of file
\ No newline at end of file
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