|
@@ -7,39 +7,40 @@ import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Configuration
|
|
@Configuration
|
|
|
public class SaTokenConfig implements WebMvcConfigurer {
|
|
public class SaTokenConfig implements WebMvcConfigurer {
|
|
|
|
|
|
|
|
|
|
+ private static final List<String> EXCLUDE_PATHS = Arrays.asList(
|
|
|
|
|
+ "/login/**",
|
|
|
|
|
+ "/health/**",
|
|
|
|
|
+ "/static/**",
|
|
|
|
|
+ "/favicon.ico",
|
|
|
|
|
+ "/logo.svg",
|
|
|
|
|
+ "/platform-config.json",
|
|
|
|
|
+ "/index.html",
|
|
|
|
|
+ "/audio/**",
|
|
|
|
|
+ "/html/**",
|
|
|
|
|
+ "/wasm/**",
|
|
|
|
|
+ "/",
|
|
|
|
|
+ "/error"
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
|
- // 注册Sa-Token拦截器,拦截所有路径
|
|
|
|
|
registry.addInterceptor(new SaInterceptor(handle -> {
|
|
registry.addInterceptor(new SaInterceptor(handle -> {
|
|
|
- // 记录token信息(用于调试)
|
|
|
|
|
String tokenValue = StpUtil.getTokenValue();
|
|
String tokenValue = StpUtil.getTokenValue();
|
|
|
if (tokenValue != null && !tokenValue.isEmpty()) {
|
|
if (tokenValue != null && !tokenValue.isEmpty()) {
|
|
|
log.debug("当前请求token: {}, 是否登录: {}", tokenValue, StpUtil.isLogin());
|
|
log.debug("当前请求token: {}, 是否登录: {}", tokenValue, StpUtil.isLogin());
|
|
|
} else {
|
|
} else {
|
|
|
log.debug("当前请求未携带token");
|
|
log.debug("当前请求未携带token");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 登录认证:除了指定的接口,其他都需要登录
|
|
|
|
|
StpUtil.checkLogin();
|
|
StpUtil.checkLogin();
|
|
|
}))
|
|
}))
|
|
|
.addPathPatterns("/**")
|
|
.addPathPatterns("/**")
|
|
|
- .excludePathPatterns(
|
|
|
|
|
- "/login/**", // 登录接口
|
|
|
|
|
- "/health/**", // 健康检查接口
|
|
|
|
|
- "/static/**", // 静态资源
|
|
|
|
|
- "/favicon.ico", // 网站图标
|
|
|
|
|
- "/logo.svg", // logo
|
|
|
|
|
- "/platform-config.json", // 平台配置
|
|
|
|
|
- "/index.html", // 首页
|
|
|
|
|
- "/*.js", // JS文件
|
|
|
|
|
- "/*.css", // CSS文件
|
|
|
|
|
- "/audio/**", // 音频资源
|
|
|
|
|
- "/html/**", // HTML资源
|
|
|
|
|
- "/wasm/**" // WASM资源
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ .excludePathPatterns(EXCLUDE_PATHS);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|