diff --git a/rdms-gateway/src/main/java/com/njcn/rdms/gateway/filter/security/TokenAuthenticationFilter.java b/rdms-gateway/src/main/java/com/njcn/rdms/gateway/filter/security/TokenAuthenticationFilter.java index 00eed22..d5d7780 100644 --- a/rdms-gateway/src/main/java/com/njcn/rdms/gateway/filter/security/TokenAuthenticationFilter.java +++ b/rdms-gateway/src/main/java/com/njcn/rdms/gateway/filter/security/TokenAuthenticationFilter.java @@ -14,6 +14,7 @@ import com.njcn.rdms.framework.common.util.json.JsonUtils; import com.njcn.rdms.gateway.util.SecurityFrameworkUtils; import com.njcn.rdms.gateway.util.WebFrameworkUtils; import com.njcn.rdms.module.system.enums.ErrorCodeConstants; +import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.client.loadbalancer.reactive.ReactorLoadBalancerExchangeFilterFunction; import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GlobalFilter; @@ -30,6 +31,7 @@ import java.util.function.Function; import static com.njcn.rdms.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; +@Slf4j @Component public class TokenAuthenticationFilter implements GlobalFilter, Ordered { @@ -57,8 +59,16 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered { @Override public LoginUser load(String token) { - String body = checkAccessToken(token).block(); - return buildUser(body, token); + // 仅异步 refresh 走这里(同步链路用 getIfPresent + 直接 checkAccessToken,不触发 load) + // 远端 token 已过期/校验失败时吞掉 ServiceException: + // 若抛出,会被 Guava 包成 ExecutionException 并由刷新线程池作为 UncaughtException 打到日志,看起来像故障。 + try { + String body = checkAccessToken(token).block(); + return buildUser(body, token); + } catch (ServiceException ex) { + log.info("[loginUserCache] 异步刷新忽略 token 校验失败:code={}, msg={}", ex.getCode(), ex.getMessage()); + return LOGIN_USER_EMPTY; + } } });