refactor(config):重构配置文件并优化认证异常处理

- 移除各模块中重复的 spring.config.import 配置
- 新增 bootstrap.yml 文件用于 wol-module-codegen 模块配置加载
- 在网关模块新增 codegen 路由规则
- 将通用依赖提升至父级 pom 统一管理
- 为 SaToken 认证失败添加详细日志记录- 优化认证异常处理逻辑,区分登录异常与其他认证异常
- 移除系统基础模块和代码生成模块中的冗余依赖声明
This commit is contained in:
cuijiawang 2025-10-27 12:56:08 +08:00
parent 08accdfdd4
commit ee41e544f5
10 changed files with 48 additions and 28 deletions

View File

@ -1,11 +1,13 @@
package com.agileboot.common.satoken.config;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.filter.SaServletFilter;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.agileboot.common.core.constant.HttpStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
@ -17,6 +19,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
*
* @author Lion Li
*/
@Slf4j
@AutoConfiguration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class SaTokenMvcConfiguration implements WebMvcConfigurer {
@ -41,7 +44,13 @@ public class SaTokenMvcConfiguration implements WebMvcConfigurer {
.setAuth(obj -> {
SaRouter.match("/**", "/auth/login", StpUtil::checkLogin);
})
.setError(e -> SaResult.error("认证失败,无法访问系统资源").setCode(HttpStatus.UNAUTHORIZED));
.setError(e -> {
if (e instanceof NotLoginException) {
return SaResult.error(e.getMessage()).setCode(HttpStatus.UNAUTHORIZED);
}
log.error("认证失败'{}',无法访问系统资源", e.getMessage());
return SaResult.error("认证失败,无法访问系统资源").setCode(HttpStatus.UNAUTHORIZED);
});
}
}

View File

@ -5,7 +5,5 @@ server:
spring:
application:
name: @application.name@
config:
import: classpath:base.yml,classpath:nacos.yml
profiles:
active: dev

View File

@ -8,6 +8,7 @@ import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.agileboot.common.core.constant.HttpStatus;
import com.agileboot.common.satoken.utils.LoginHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -18,6 +19,7 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
*
* @author Lion Li
*/
@Slf4j
@Configuration
public class SaTokenConfig {
@ -56,6 +58,7 @@ public class SaTokenConfig {
if (e instanceof NotLoginException) {
return SaResult.error(e.getMessage()).setCode(HttpStatus.UNAUTHORIZED);
}
log.error("认证失败'{}',无法访问系统资源", e.getMessage());
return SaResult.error("认证失败,无法访问系统资源").setCode(HttpStatus.UNAUTHORIZED);
});
}

View File

@ -9,3 +9,7 @@ spring:
uri: lb://wol-auth
predicates:
- Path=/auth/**
- id: wol-module-codegen
uri: lb://wol-module-codegen
predicates:
- Path=/codegen/**

View File

@ -7,8 +7,6 @@ server:
spring:
application:
name: @application.name@
config:
import: classpath:base.yml,classpath:nacos.yml
profiles:
active: dev
main:

View File

@ -12,18 +12,6 @@
<artifactId>agileboot-system-base</artifactId>
<dependencies>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-web</artifactId>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-mybatis</artifactId>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-domain</artifactId>
</dependency>
<!-- 获取系统信息 -->
<dependency>
<groupId>com.github.oshi</groupId>

View File

@ -15,5 +15,31 @@
<module>wol-module-ai</module>
</modules>
<dependencies>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-nacos</artifactId>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-satoken</artifactId>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-web</artifactId>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-mybatis</artifactId>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-redis</artifactId>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-domain</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -17,15 +17,6 @@
</properties>
<dependencies>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-web</artifactId>
</dependency>
<dependency>
<groupId>com.agileboot</groupId>
<artifactId>wol-common-mybatis</artifactId>
</dependency>
<!-- Freemarker模板引擎 -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -3,5 +3,3 @@ server:
spring:
application:
name: @application.name@
config:
import: classpath:base.yml

View File

@ -0,0 +1,5 @@
spring:
application:
name: @application.name@
config:
import: classpath:base.yml,classpath:nacos.yml