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 42f3921e
authored
Dec 05, 2023
by
刘鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(网关ak校验): 增加接口实时获取ak信息, 避免出现redis数据丢失导致外部调用鉴权失败
1 parent
33bcfac4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
project-gateway/src/main/java/com/dituhui/pea/gateway/config/AuthFilter.java
project-gateway/src/main/java/com/dituhui/pea/gateway/config/AuthFilter.java
View file @
42f3921
...
...
@@ -12,6 +12,7 @@ import com.google.common.collect.Maps;
import
com.google.common.collect.Sets
;
import
com.google.gson.Gson
;
import
lombok.RequiredArgsConstructor
;
import
lombok.SneakyThrows
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.cloud.gateway.filter.GatewayFilterChain
;
...
...
@@ -25,13 +26,13 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.server.ServerWebExchange
;
import
reactor.core.publisher.Mono
;
import
reactor.core.scheduler.Schedulers
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.concurrent.CompletableFuture
;
@Component
@Slf4j
...
...
@@ -49,6 +50,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
private
final
IUser
iUser
;
@Override
@SneakyThrows
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
String
url
=
exchange
.
getRequest
().
getPath
().
toString
();
// 判断是否属于白名单中
...
...
@@ -122,6 +124,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
}
}
@SneakyThrows
private
Optional
<
Boolean
>
appKey
(
String
ak
)
{
String
value
=
redisService
.
get
(
RedisKeyGroup
.
appKey
+
":"
+
ak
);
...
...
@@ -130,12 +133,13 @@ public class AuthFilter implements GlobalFilter, Ordered {
return
Optional
.
of
(
Boolean
.
TRUE
);
}
Mono
<
Boolean
>
booleanMono
=
Mono
.
fromCallable
(()
->
{
CompletableFuture
<
Boolean
>
supplyAsync
=
CompletableFuture
.
supplyAsync
(()
->
{
String
jsonStr
=
JSONUtil
.
toJsonStr
(
iUser
.
getAppKeyInfo
(
ak
));
return
StringUtils
.
isNotBlank
(
jsonStr
);
})
.
subscribeOn
(
Schedulers
.
boundedElastic
())
;
});
return
booleanMono
.
blockOptional
();
return
Optional
.
ofNullable
(
supplyAsync
.
get
());
}
/**
...
...
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