增加后台管理模块
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -9,7 +10,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
/**
|
||||
* Web MVC配置
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @author huazhongmin
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@Configuration
|
||||
@@ -18,11 +19,23 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
@Autowired
|
||||
private JwtAuthInterceptor jwtAuthInterceptor;
|
||||
|
||||
@Autowired
|
||||
private AdminAuthInterceptor adminAuthInterceptor;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 注意:已配置 server.servlet.context-path=/api,拦截器路径匹配不需要再带 /api 前缀
|
||||
// 管理员拦截器 - 优先级最高,只拦截 /admin/** 路径
|
||||
registry.addInterceptor(adminAuthInterceptor)
|
||||
.addPathPatterns("/admin/**")
|
||||
.excludePathPatterns(
|
||||
"/admin/auth/login", // 管理员登录接口
|
||||
"/admin/auth/refreshToken" // 管理员刷新token接口
|
||||
)
|
||||
.order(1); // 优先级1,最先执行
|
||||
|
||||
// 普通用户拦截器 - 拦截除管理员路径外的所有请求
|
||||
registry.addInterceptor(jwtAuthInterceptor)
|
||||
.addPathPatterns("/**") // 拦截应用内的所有请求(已去掉 /api 前缀)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns(
|
||||
"/auth/login", // 登录接口
|
||||
"/auth/register", // 注册接口
|
||||
@@ -34,7 +47,9 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
"/ws/**", // WebSocket接口
|
||||
"/swagger-ui/**", // Swagger UI
|
||||
"/v3/api-docs/**", // API文档
|
||||
"/actuator/**" // 监控端点
|
||||
);
|
||||
"/actuator/**", // 监控端点
|
||||
"/admin/**" // 排除管理员路径,由管理员拦截器处理
|
||||
)
|
||||
.order(2); // 优先级2
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user