gateway tomcat去除

This commit is contained in:
2025-12-22 17:03:37 +08:00
parent e09817015e
commit b023bec261
55 changed files with 1926 additions and 260 deletions

View File

@@ -100,14 +100,13 @@ public class GatewayAuthConfig {
List<GrantedAuthority> authorities = new ArrayList<>();
try {
String authHeader = request.getHeader("Authorization");
logger.info("Authorization header: {}", authHeader != null ? "Bearer ***" : "null");
String token = extractToken(request);
logger.debug("提取到Token: {}", token != null ? "***" : "null");
if (StringUtils.hasText(authHeader) && authHeader.startsWith(BEARER_PREFIX)) {
String token = authHeader.substring(BEARER_PREFIX.length());
if (StringUtils.hasText(token)) {
String cacheKey = LOGIN_TOKEN_PREFIX + token;
LoginDomain login = redisService.get(cacheKey, LoginDomain.class);
logger.info("Redis key: {}, login: {}", cacheKey, login != null ? "loaded" : "null");
logger.debug("Redis key: {}, login: {}", cacheKey, login != null ? "loaded" : "null");
if (login != null) {
if (login.getUserPermissions() != null) {
@@ -118,7 +117,7 @@ public class GatewayAuthConfig {
}
}
}
logger.info("加载用户权限: {} 个", authorities.size());
logger.debug("加载用户权限: {} 个", authorities.size());
}
}
} catch (Exception e) {
@@ -127,5 +126,25 @@ public class GatewayAuthConfig {
return authorities;
}
/**
* 从请求头或URL参数提取Token
*/
private String extractToken(HttpServletRequest request) {
// 1. 优先从请求头获取
String authHeader = request.getHeader("Authorization");
if (StringUtils.hasText(authHeader) && authHeader.startsWith(BEARER_PREFIX)) {
return authHeader.substring(BEARER_PREFIX.length()).trim();
}
// 2. 从URL参数获取用于WebSocket连接
String tokenParam = request.getParameter("token");
if (StringUtils.hasText(tokenParam)) {
logger.debug("从URL参数获取Token");
return tokenParam.trim();
}
return null;
}
}
}

View File

@@ -127,7 +127,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
// 从Redis加载 LoginDomain并将权限装配到 Spring Security 上下文
if (redisService != null) {
Object obj = redisService.get(REDIS_LOGIN_PREFIX + userId);
Object obj = redisService.get(REDIS_LOGIN_PREFIX + token);
if (obj instanceof LoginDomain loginDomain) {
// 组装权限码 authorities已存在
List<SimpleGrantedAuthority> permAuthorities = null;

View File

@@ -35,6 +35,14 @@
<artifactId>common-utils</artifactId>
<version>${urban-lifeline.version}</version>
</dependency>
<!-- Swagger/OpenAPI 注解 (用于 @Schema 等) -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations-jakarta</artifactId>
<version>2.2.36</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -23,4 +23,10 @@ public class TbSysUserRoleDTO extends BaseDTO {
@Schema(description = "角色ID")
private String roleId;
@Schema(description = "部门ID")
private String deptId;
@Schema(description = "部门全路径")
private String deptPath;
}

View File

@@ -19,6 +19,25 @@
</properties>
<dependencies>
<!-- Jakarta Servlet API (用于 ServletUtils) -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Spring Web (用于 FastJsonConfiguration) -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<scope>provided</scope>
</dependency>
<!-- Apache POI for Excel -->
<dependency>
<groupId>org.apache.poi</groupId>

View File

@@ -2,7 +2,7 @@ package org.xyzh.common.utils.config;
import com.alibaba.fastjson2.support.config.FastJsonConfig;
import com.alibaba.fastjson2.support.spring6.http.converter.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
@@ -20,6 +20,7 @@ import java.util.List;
* @since 2025-11-28
*/
@Configuration
@ConditionalOnClass(WebMvcConfigurer.class)
public class FastJsonConfiguration implements WebMvcConfigurer {
/**

View File

@@ -79,4 +79,24 @@
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Jakarta Servlet API (用于 ServletUtils) -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Spring Web (用于 FastJsonConfiguration) -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>