refactor: 移除X-Tenant-Group相关代码

- TenantGatewayFilter简化为仅记录日志
- 移除application.yml和application-docker.yml中的tenant-group-header配置
This commit is contained in:
zhangjf 2026-02-20 11:27:21 +08:00
parent f3b7576bf1
commit a8450d181f
12 changed files with 24 additions and 45 deletions

View File

@ -1,2 +1,2 @@
#Thu Feb 19 19:13:53 CST 2026 #Fri Feb 20 11:21:39 CST 2026
central|https\://repo1.maven.org/maven2|null=1771499633540 central|https\://repo1.maven.org/maven2|null=1771557699084

View File

@ -1,2 +1,2 @@
#Thu Feb 19 19:13:53 CST 2026 #Fri Feb 20 11:21:39 CST 2026
central|https\://repo1.maven.org/maven2|null=1771499633542 central|https\://repo1.maven.org/maven2|null=1771557699091

View File

@ -1,2 +1,2 @@
#Thu Feb 19 19:13:53 CST 2026 #Fri Feb 20 11:21:39 CST 2026
central|https\://repo1.maven.org/maven2|null=1771499633545 central|https\://repo1.maven.org/maven2|null=1771557699097

View File

@ -1,2 +1,2 @@
#Thu Feb 19 19:13:53 CST 2026 #Fri Feb 20 11:21:39 CST 2026
central|https\://repo1.maven.org/maven2|null=1771499633544 central|https\://repo1.maven.org/maven2|null=1771557699096

View File

@ -1,2 +1,2 @@
#Thu Feb 19 19:13:53 CST 2026 #Fri Feb 20 11:21:39 CST 2026
central|https\://repo1.maven.org/maven2|null=1771499633543 central|https\://repo1.maven.org/maven2|null=1771557699093

View File

@ -1,2 +1,2 @@
#Thu Feb 19 19:13:53 CST 2026 #Fri Feb 20 11:21:39 CST 2026
central|https\://repo1.maven.org/maven2|null=1771499633542 central|https\://repo1.maven.org/maven2|null=1771557699090

View File

@ -1,2 +1,2 @@
#Thu Feb 19 19:13:53 CST 2026 #Fri Feb 20 11:21:39 CST 2026
central|https\://repo1.maven.org/maven2|null=1771499633545 central|https\://repo1.maven.org/maven2|null=1771557699098

View File

@ -1,2 +1,2 @@
#Thu Feb 19 19:13:53 CST 2026 #Fri Feb 20 11:21:39 CST 2026
central|https\://repo1.maven.org/maven2|null=1771499633543 central|https\://repo1.maven.org/maven2|null=1771557699092

View File

@ -1,2 +1,2 @@
#Thu Feb 19 19:13:53 CST 2026 #Fri Feb 20 11:21:39 CST 2026
central|https\://repo1.maven.org/maven2|null=1771499633544 central|https\://repo1.maven.org/maven2|null=1771557699094

View File

@ -16,8 +16,8 @@ import java.util.List;
/** /**
* 租户信息全局过滤器 * 租户信息全局过滤器
* *
* <p>从请求头中获取用户信息由TokenAuthFilter解析构建租户组信息</p> * <p>从请求头中获取用户信息由TokenAuthFilter解析</p>
* <p>在TokenAuthFilter之后执行用于多租户路由</p> * <p>在TokenAuthFilter之后执行用于日志记录</p>
*/ */
@Component @Component
public class TenantGatewayFilter implements GlobalFilter, Ordered { public class TenantGatewayFilter implements GlobalFilter, Ordered {
@ -26,7 +26,6 @@ public class TenantGatewayFilter implements GlobalFilter, Ordered {
// Header 名称由TokenAuthFilter设置 // Header 名称由TokenAuthFilter设置
public static final String HEADER_TENANT_ID = "X-Tenant-Id"; public static final String HEADER_TENANT_ID = "X-Tenant-Id";
public static final String HEADER_TENANT_GROUP = "X-Tenant-Group";
public static final String HEADER_USER_ID = "X-User-Id"; public static final String HEADER_USER_ID = "X-User-Id";
public static final String HEADER_USERNAME = "X-Username"; public static final String HEADER_USERNAME = "X-Username";
@ -51,18 +50,10 @@ public class TenantGatewayFilter implements GlobalFilter, Ordered {
String userId = request.getHeaders().getFirst(HEADER_USER_ID); String userId = request.getHeaders().getFirst(HEADER_USER_ID);
String username = request.getHeaders().getFirst(HEADER_USERNAME); String username = request.getHeaders().getFirst(HEADER_USERNAME);
// 构建租户组信息 logger.debug("[TenantGateway] 租户ID: {}, 用户ID: {}, 用户名: {}, 路径: {}",
String tenantGroup = buildTenantGroup(tenantId); tenantId, userId, username, path);
// 将租户组信息写入请求头 return chain.filter(exchange);
ServerHttpRequest mutatedRequest = request.mutate()
.header(HEADER_TENANT_GROUP, tenantGroup)
.build();
logger.debug("[TenantGateway] 租户ID: {}, 租户组: {}, 用户: {}, 路径: {}",
tenantId, tenantGroup, username, path);
return chain.filter(exchange.mutate().request(mutatedRequest).build());
} }
/** /**
@ -72,16 +63,6 @@ public class TenantGatewayFilter implements GlobalFilter, Ordered {
return WHITE_LIST.stream().anyMatch(path::startsWith); return WHITE_LIST.stream().anyMatch(path::startsWith);
} }
/**
* 构建租户组名称
*/
private String buildTenantGroup(String tenantId) {
if (tenantId == null || tenantId.isEmpty()) {
return "DEFAULT";
}
return "TENANT_" + tenantId.toUpperCase();
}
@Override @Override
public int getOrder() { public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE + 2; // 在TokenAuthFilter之后执行 return Ordered.HIGHEST_PRECEDENCE + 2; // 在TokenAuthFilter之后执行

View File

@ -73,7 +73,6 @@ tenant:
routing: routing:
enabled: true enabled: true
tenant-header: X-Tenant-Id tenant-header: X-Tenant-Id
tenant-group-header: X-Tenant-Group
default-tenant-id: "1" default-tenant-id: "1"
shared-services: shared-services:
- fund-gateway - fund-gateway

View File

@ -76,12 +76,11 @@ logging:
pattern: pattern:
console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
# 多租户路由配置(服务实例只需声明自己的租户组) # 多租户路由配置
tenant: tenant:
routing: routing:
enabled: true enabled: true
tenant-header: X-Tenant-Id tenant-header: X-Tenant-Id
tenant-group-header: X-Tenant-Group
default-tenant-id: "1" default-tenant-id: "1"
# 共享服务列表 # 共享服务列表
shared-services: shared-services: