From 95835d19a18f90c4c5a670df18e8f27c18a2e0e2 Mon Sep 17 00:00:00 2001
From: Ray Hao <1490493387@qq.com>
Date: Wed, 28 Feb 2024 18:31:13 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BD=91=E5=85=B3=E6=B7=BB=E5=8A=A0JWT?=
=?UTF-8?q?=E9=BB=91=E5=90=8D=E5=8D=95=E6=8B=A6=E6=88=AA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
youlai-gateway/pom.xml | 5 -----
.../youlai/gateway/filter/TokenValidationGlobalFilter.java | 4 +++-
.../src/main/resources/logback-spring.xml | 0
3 files changed, 3 insertions(+), 6 deletions(-)
rename {youlai-common/common-log => youlai-gateway}/src/main/resources/logback-spring.xml (100%)
diff --git a/youlai-gateway/pom.xml b/youlai-gateway/pom.xml
index fdea242e0..f6dcf92e0 100644
--- a/youlai-gateway/pom.xml
+++ b/youlai-gateway/pom.xml
@@ -86,11 +86,6 @@
common-core
-
- com.youlai
- common-log
-
-
com.youlai
common-redis
diff --git a/youlai-gateway/src/main/java/com/youlai/gateway/filter/TokenValidationGlobalFilter.java b/youlai-gateway/src/main/java/com/youlai/gateway/filter/TokenValidationGlobalFilter.java
index 7e75b3ac4..25fe965cc 100644
--- a/youlai-gateway/src/main/java/com/youlai/gateway/filter/TokenValidationGlobalFilter.java
+++ b/youlai-gateway/src/main/java/com/youlai/gateway/filter/TokenValidationGlobalFilter.java
@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.jwt.JWTPayload;
import com.nimbusds.jose.JWSObject;
+import com.nimbusds.jose.Payload;
import com.youlai.common.constant.RedisConstants;
import com.youlai.common.result.ResultCode;
import com.youlai.gateway.util.WebFluxUtils;
@@ -21,6 +22,7 @@ import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import java.text.ParseException;
+import java.util.Map;
/**
* Token 验证全局过滤器
@@ -52,7 +54,7 @@ public class TokenValidationGlobalFilter implements GlobalFilter, Ordered {
try {
String token = authorization.substring(BEARER_PREFIX.length());
JWSObject jwsObject = JWSObject.parse(token);
- String jti = JSONUtil.parseObj(jwsObject.getPayload()).get(JWTPayload.JWT_ID, String.class);
+ String jti = (String) jwsObject.getPayload().toJSONObject().get(JWTPayload.JWT_ID);
Boolean isBlackToken = redisTemplate.hasKey(RedisConstants.TOKEN_BLACKLIST_PREFIX + jti);
if (Boolean.TRUE.equals(isBlackToken)) {
return WebFluxUtils.writeErrorResponse(response, ResultCode.TOKEN_ACCESS_FORBIDDEN);
diff --git a/youlai-common/common-log/src/main/resources/logback-spring.xml b/youlai-gateway/src/main/resources/logback-spring.xml
similarity index 100%
rename from youlai-common/common-log/src/main/resources/logback-spring.xml
rename to youlai-gateway/src/main/resources/logback-spring.xml