修复#6100、@IgnoreAuth扫描加速

This commit is contained in:
EightMonth
2024-04-25 11:52:41 +08:00
parent f1496b5084
commit faebdee755
7 changed files with 176 additions and 81 deletions

View File

@@ -1,13 +1,16 @@
package org.jeecg.handler.swagger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger.web.*;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
/**
* swagger聚合接口三个接口都是 doc.html需要访问的接口
@@ -19,6 +22,11 @@ import java.util.List;
public class SwaggerResourceController {
private MySwaggerResourceProvider swaggerResourceProvider;
@Autowired
private ApplicationContext applicationContext;
// 生产环境profile配置模型
private static final String PRODUCTION_PROFILE_NAME = "prod*";
@Autowired
public SwaggerResourceController(MySwaggerResourceProvider swaggerResourceProvider) {
this.swaggerResourceProvider = swaggerResourceProvider;
@@ -36,6 +44,22 @@ public class SwaggerResourceController {
@RequestMapping
public ResponseEntity<List<SwaggerResource>> swaggerResources() {
// 如果激活的profile带有生产环境的profile则屏蔽swagger资源
if (isProd()) {
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK);
}
return new ResponseEntity<>(swaggerResourceProvider.get(), HttpStatus.OK);
}
private boolean isProd() {
String[] profiles = applicationContext.getEnvironment().getActiveProfiles();
Pattern pattern = Pattern.compile(PRODUCTION_PROFILE_NAME);
for (String profile : profiles) {
if (pattern.matcher(profile).find()) {
return true;
}
}
return false;
}
}

View File

@@ -16,6 +16,7 @@ import org.springframework.core.env.Environment;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
@@ -35,6 +36,7 @@ public class JeecgSystemCloudApplication extends SpringBootServletInitializer im
private RedisTemplate<String, Object> redisTemplate;
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(JeecgSystemCloudApplication.class);
}