mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
i18输出测试
This commit is contained in:
+14
-3
@@ -2,6 +2,7 @@ package com.cf.imes.gateway.filter.security;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
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.ServiceException;
|
||||
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.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -24,6 +26,7 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -80,6 +83,14 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered {
|
||||
// 移除 login-user 的请求头,避免伪造模拟
|
||||
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
|
||||
String token = SecurityFrameworkUtils.obtainAuthorization(exchange);
|
||||
if (CharSequenceUtil.isEmpty(token)) {
|
||||
@@ -120,9 +131,7 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered {
|
||||
ServerWebExchange newExchange = exchange.mutate()
|
||||
.request(builder -> SecurityFrameworkUtils.setLoginUserHeader(builder, user))
|
||||
.build();
|
||||
System.out.println("========== FINAL EXCHANGE ==========");
|
||||
System.out.println("Accept-Language FINAL = "
|
||||
+ newExchange.getRequest().getHeaders().getFirst("Accept-Language"));
|
||||
|
||||
return chain.filter(newExchange);
|
||||
});
|
||||
}
|
||||
@@ -131,6 +140,8 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered {
|
||||
// 用token从checktoken api中获取当前用户
|
||||
Long organId = WebFrameworkUtils.getOrganId(exchange);
|
||||
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);
|
||||
if (remoteUser != null) {
|
||||
return Mono.just(remoteUser);
|
||||
|
||||
Reference in New Issue
Block a user