refactor(config):重构配置文件并优化认证异常处理
- 移除各模块中重复的 spring.config.import 配置 - 新增 bootstrap.yml 文件用于 wol-module-codegen 模块配置加载 - 在网关模块新增 codegen 路由规则 - 将通用依赖提升至父级 pom 统一管理 - 为 SaToken 认证失败添加详细日志记录- 优化认证异常处理逻辑,区分登录异常与其他认证异常 - 移除系统基础模块和代码生成模块中的冗余依赖声明
This commit is contained in:
parent
08accdfdd4
commit
ee41e544f5
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,5 @@ server:
|
||||
spring:
|
||||
application:
|
||||
name: @application.name@
|
||||
config:
|
||||
import: classpath:base.yml,classpath:nacos.yml
|
||||
profiles:
|
||||
active: dev
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
@ -9,3 +9,7 @@ spring:
|
||||
uri: lb://wol-auth
|
||||
predicates:
|
||||
- Path=/auth/**
|
||||
- id: wol-module-codegen
|
||||
uri: lb://wol-module-codegen
|
||||
predicates:
|
||||
- Path=/codegen/**
|
||||
|
||||
@ -7,8 +7,6 @@ server:
|
||||
spring:
|
||||
application:
|
||||
name: @application.name@
|
||||
config:
|
||||
import: classpath:base.yml,classpath:nacos.yml
|
||||
profiles:
|
||||
active: dev
|
||||
main:
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -3,5 +3,3 @@ server:
|
||||
spring:
|
||||
application:
|
||||
name: @application.name@
|
||||
config:
|
||||
import: classpath:base.yml
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
spring:
|
||||
application:
|
||||
name: @application.name@
|
||||
config:
|
||||
import: classpath:base.yml,classpath:nacos.yml
|
||||
Loading…
x
Reference in New Issue
Block a user