Commit 42f3921e by 刘鑫

feat(网关ak校验): 增加接口实时获取ak信息, 避免出现redis数据丢失导致外部调用鉴权失败

1 parent 33bcfac4
......@@ -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());
}
/**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!