Files
happy-life-star/backend-single/src/main/java/com/emotion/config/WebMvcConfig.java
T
2026-05-17 10:14:08 +08:00

57 lines
2.3 KiB
Java

package com.emotion.config;
import com.emotion.interceptor.AdminAuthInterceptor;
import com.emotion.interceptor.JwtAuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Web MVC配置
*
* @author huazhongmin
* @date 2025-07-23
*/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Autowired
private JwtAuthInterceptor jwtAuthInterceptor;
@Autowired
private AdminAuthInterceptor adminAuthInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 管理员拦截器 - 优先级最高,只拦截 /admin/** 路径
registry.addInterceptor(adminAuthInterceptor)
.addPathPatterns("/admin/**")
.excludePathPatterns(
"/admin/auth/login", // 管理员登录接口
"/admin/auth/refreshToken" // 管理员刷新token接口
)
.order(1); // 优先级1,最先执行
// 普通用户拦截器 - 拦截除管理员路径外的所有请求
registry.addInterceptor(jwtAuthInterceptor)
.addPathPatterns("/**")
.excludePathPatterns(
"/auth/login", // 登录接口
"/auth/register", // 注册接口
"/auth/captcha", // 图形验证码接口
"/auth/sms-code", // 短信验证码接口(免登录)
"/auth/refresh-token", // 刷新token接口
"/auth/resetPassword", // 重置密码接口(免登录)
"/analytics/events/batch", // Analytics event batch endpoint
"/health", // 健康检查接口
"/ws/**", // WebSocket接口
"/swagger-ui/**", // Swagger UI
"/v3/api-docs/**", // API文档
"/actuator/**", // 监控端点
"/admin/**" // 排除管理员路径,由管理员拦截器处理
)
.order(2); // 优先级2
}
}