feat(gateway): 修改文件上传接口返回结构并添加认证路径白名单
- 将 POST /system/file/upload 接口返回结构从字符串改为 { id: string, url: string } 对象
- 添加 id 字段作为 infra_file.id 的字符串形式,解决前端精度丢失问题
- 新增 SKIP_AUTH_PATHS 白名单集合,包含登录、登出、刷新令牌等免校验路径
- 在网关过滤器中添加白名单检查逻辑,跳过指定路径的 access token 校验
- 解决过期 token 拦截导致刷新令牌接口无法正常执行的问题
This commit is contained in:
@@ -25,6 +25,7 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.njcn.rdms.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache;
|
||||
@@ -37,6 +38,18 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered {
|
||||
|
||||
private static final LoginUser LOGIN_USER_EMPTY = new LoginUser();
|
||||
|
||||
/**
|
||||
* 跳过 access token 校验的路径白名单。
|
||||
* 这些接口在 system 端标注 @PermitAll,本就不需要登录态;若前端调用时带过期 access,
|
||||
* 网关不应在此处拦截 1002023000,否则 /refresh-token 永远走不到 system 的 1002023001 / 业务逻辑。
|
||||
*/
|
||||
private static final Set<String> SKIP_AUTH_PATHS = Set.of(
|
||||
"/admin-api/system/auth/login",
|
||||
"/admin-api/system/auth/logout",
|
||||
"/admin-api/system/auth/refresh-token",
|
||||
"/admin-api/system/auth/register"
|
||||
);
|
||||
|
||||
private final WebClient webClient;
|
||||
|
||||
private final LoadingCache<String, LoginUser> loginUserCache = buildAsyncReloadingCache(Duration.ofMinutes(1),
|
||||
@@ -58,6 +71,11 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered {
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
exchange = SecurityFrameworkUtils.removeLoginUser(exchange);
|
||||
|
||||
// 白名单路径直接放行,不做 token 校验
|
||||
if (SKIP_AUTH_PATHS.contains(exchange.getRequest().getPath().value())) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
String token = SecurityFrameworkUtils.obtainAuthorization(exchange);
|
||||
if (StrUtil.isEmpty(token)) {
|
||||
return chain.filter(exchange);
|
||||
|
||||
Reference in New Issue
Block a user