i18输出测试

This commit is contained in:
gaoqr
2026-05-13 11:18:04 +08:00
parent e939342015
commit db2e31680c
@@ -2,6 +2,7 @@ package com.cf.imes.gateway.filter.security;
import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.cf.imes.framework.common.exception.ErrorCode; import com.cf.imes.framework.common.exception.ErrorCode;
import com.cf.imes.framework.common.exception.ServiceException; import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.CommonResult; import com.cf.imes.framework.common.pojo.CommonResult;
@@ -16,6 +17,7 @@ import jakarta.annotation.Resource;
import org.springframework.cloud.client.loadbalancer.reactive.ReactorLoadBalancerExchangeFilterFunction; import org.springframework.cloud.client.loadbalancer.reactive.ReactorLoadBalancerExchangeFilterFunction;
import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -24,6 +26,7 @@ import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.function.Function; import java.util.function.Function;
@@ -80,6 +83,14 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered {
// 移除 login-user 的请求头,避免伪造模拟 // 移除 login-user 的请求头,避免伪造模拟
SecurityFrameworkUtils.removeLoginUser(exchange); SecurityFrameworkUtils.removeLoginUser(exchange);
String Language = exchange.getRequest()
.getHeaders()
.getFirst("Accept-Language");
if (StrUtil.isEmpty(Language)) {
Language = Locale.CHINA.getLanguage();
}
LocaleContextHolder.setLocale(Locale.forLanguageTag(Language));
// 情况一,如果没有 Token 令牌,则直接继续 filter // 情况一,如果没有 Token 令牌,则直接继续 filter
String token = SecurityFrameworkUtils.obtainAuthorization(exchange); String token = SecurityFrameworkUtils.obtainAuthorization(exchange);
if (CharSequenceUtil.isEmpty(token)) { if (CharSequenceUtil.isEmpty(token)) {
@@ -120,9 +131,7 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered {
ServerWebExchange newExchange = exchange.mutate() ServerWebExchange newExchange = exchange.mutate()
.request(builder -> SecurityFrameworkUtils.setLoginUserHeader(builder, user)) .request(builder -> SecurityFrameworkUtils.setLoginUserHeader(builder, user))
.build(); .build();
System.out.println("========== FINAL EXCHANGE ==========");
System.out.println("Accept-Language FINAL = "
+ newExchange.getRequest().getHeaders().getFirst("Accept-Language"));
return chain.filter(newExchange); return chain.filter(newExchange);
}); });
} }
@@ -131,6 +140,8 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered {
// 用token从checktoken api中获取当前用户 // 用token从checktoken api中获取当前用户
Long organId = WebFrameworkUtils.getOrganId(exchange); Long organId = WebFrameworkUtils.getOrganId(exchange);
return checkAccessToken(organId, token).flatMap((Function<String, Mono<LoginUser>>) body -> { return checkAccessToken(organId, token).flatMap((Function<String, Mono<LoginUser>>) body -> {
System.out.println("Accept-Language CHECKTOKEN = "
+ exchange.getRequest().getHeaders().getFirst("Accept-Language"));
LoginUser remoteUser = buildUser(body); LoginUser remoteUser = buildUser(body);
if (remoteUser != null) { if (remoteUser != null) {
return Mono.just(remoteUser); return Mono.just(remoteUser);