diff --git a/nl-plugin-tool/pom.xml b/nl-plugin-tool/pom.xml index 1929adf..e1be04b 100644 --- a/nl-plugin-tool/pom.xml +++ b/nl-plugin-tool/pom.xml @@ -17,6 +17,11 @@ org.nl.tool.api nl-plugin-tool-api + + + org.nl + nl-plugin-auth-api + \ No newline at end of file diff --git a/nl-plugin-tool/src/main/java/org/nl/tool/mock/core/config/MockConfigProperties.java b/nl-plugin-tool/src/main/java/org/nl/tool/mock/core/config/MockConfigProperties.java index 3a9971f..82c95b0 100644 --- a/nl-plugin-tool/src/main/java/org/nl/tool/mock/core/config/MockConfigProperties.java +++ b/nl-plugin-tool/src/main/java/org/nl/tool/mock/core/config/MockConfigProperties.java @@ -4,6 +4,9 @@ import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +import java.util.ArrayList; +import java.util.List; + /** * Mock配置属性类 * 使用@ConfigurationProperties从application.yml中绑定mock配置 @@ -13,6 +16,9 @@ import org.springframework.stereotype.Component; * enabled: true * cache-expiration-seconds: 300 * log-mock-usage: true + * whitelist: + * - /api/login + * - /api/mes/** * @author: lyd * @date: 2026/1/28 */ diff --git a/nl-plugin-tool/src/main/java/org/nl/tool/mock/modular/mockconfig/controller/MockConfigController.java b/nl-plugin-tool/src/main/java/org/nl/tool/mock/modular/mockconfig/controller/MockConfigController.java index 2c371fb..c17fe3e 100644 --- a/nl-plugin-tool/src/main/java/org/nl/tool/mock/modular/mockconfig/controller/MockConfigController.java +++ b/nl-plugin-tool/src/main/java/org/nl/tool/mock/modular/mockconfig/controller/MockConfigController.java @@ -13,6 +13,7 @@ package org.nl.tool.mock.modular.mockconfig.controller; import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.dev33.satoken.annotation.SaIgnore; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; @@ -120,4 +121,9 @@ public class MockConfigController { public CommonResult detail(@Valid MockConfigIdParam mockConfigIdParam) { return CommonResult.data(mockConfigService.detail(mockConfigIdParam)); } + + @GetMapping("/test") + public String test() { + return "WELCOME"; + } } diff --git a/nl-web-app/src/main/java/org/nl/core/config/GlobalConfigure.java b/nl-web-app/src/main/java/org/nl/core/config/GlobalConfigure.java index d195108..20bbf1c 100644 --- a/nl-web-app/src/main/java/org/nl/core/config/GlobalConfigure.java +++ b/nl-web-app/src/main/java/org/nl/core/config/GlobalConfigure.java @@ -48,6 +48,7 @@ import org.aspectj.lang.reflect.MethodSignature; import org.mybatis.spring.annotation.MapperScan; import org.nl.core.handler.GlobalExceptionUtil; import org.nl.sys.core.enums.SysBuildInEnum; +import org.nl.tool.mock.core.config.MockConfigProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -59,6 +60,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.jdbc.support.JdbcUtils; import org.springframework.stereotype.Component; import org.springframework.util.ResourceUtils; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.nl.auth.core.util.StpClientUtil; @@ -98,15 +100,45 @@ public class GlobalConfigure implements WebMvcConfigurer { @Autowired private SaTokenConfig saTokenConfig; + @Autowired + private MockInterceptor mockInterceptor; private static final String COMMON_REPEAT_SUBMIT_CACHE_KEY = "common-repeatSubmit:"; + public static final String[] NO_CHECK_MOCK = { + "/", + "/test", + "/auth/session/**", + "/auth/third/page", + "/client/user/**", + "/sys/**", + "/dev/**", + "/gen/basic/**", + "/gen/config/**", + "/mobile/menu/**", + "/mobile/module/**", + "/api/agv/status", + "/api/device/**", + "/api/agv/map/**", + "/api/localStorage/**", + "/api/baseData/point/status", + "/api/language/**", + "/favicon.ico", + "/doc.html", + "/webjars/**", + "/v3/api-docs/**", + "/druid/**", + "/mobile/**", + "/auth/**" + }; + /** * 无需登录的接口地址集合 */ public static final String[] NO_LOGIN_PATH_ARR = { /* 主入口 */ "/", + "/test", /*AGV*/ "/api/agv/status", "/api/device/**", @@ -673,4 +705,21 @@ public class GlobalConfigure implements WebMvcConfigurer { public void registerListenerList(List dataChangeListenerList) { CommonDataChangeEventCenter.registerListenerList(dataChangeListenerList); } + + /** + * 注册拦截器 + * 配置拦截路径和排除路径 + * + * @param registry 拦截器注册器 + */ + @Override + public void addInterceptors(InterceptorRegistry registry) { +// log.info("Registering MockInterceptor"); + + registry.addInterceptor(mockInterceptor) + .addPathPatterns("/**") // 拦截所有路径 + .excludePathPatterns(CollectionUtil.newArrayList(NO_CHECK_MOCK)); + +// log.info("MockInterceptor registered successfully"); + } } diff --git a/nl-web-app/src/main/java/org/nl/core/config/MockInterceptor.java b/nl-web-app/src/main/java/org/nl/core/config/MockInterceptor.java index 01ee46a..e203b0c 100644 --- a/nl-web-app/src/main/java/org/nl/core/config/MockInterceptor.java +++ b/nl-web-app/src/main/java/org/nl/core/config/MockInterceptor.java @@ -8,8 +8,12 @@ import org.nl.tool.mock.core.handle.MockService; import org.nl.tool.mock.modular.mockconfig.entity.MockConfig; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; +import org.springframework.util.AntPathMatcher; +import org.springframework.util.PathMatcher; +import org.springframework.util.StringUtils; import org.springframework.web.servlet.HandlerInterceptor; +import java.util.List; import java.util.Optional; /** @@ -30,6 +34,7 @@ public class MockInterceptor implements HandlerInterceptor { private final MockService mockService; private final MockConfigProperties properties; + private final PathMatcher pathMatcher = new AntPathMatcher(); /** * 构造函数,注入依赖 @@ -55,13 +60,12 @@ public class MockInterceptor implements HandlerInterceptor { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + log.info("check config..."); // 检查全局Mock开关 if (!properties.isEnabled()) { log.debug("Mock functionality is globally disabled, continuing to controller"); return true; // Mock功能禁用,继续执行Controller } - - // todo: 检测白名单 // 提取请求路径和方法 String path = request.getRequestURI();