mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-22 12:48:59 +08:00
feat: 网关添加JWT黑名单拦截
This commit is contained in:
parent
e584768467
commit
95835d19a1
@ -86,11 +86,6 @@
|
||||
<artifactId>common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.youlai</groupId>
|
||||
<artifactId>common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.youlai</groupId>
|
||||
<artifactId>common-redis</artifactId>
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user