From 098dd26f258157864d6f6690af2ee5622072f74f Mon Sep 17 00:00:00 2001 From: Parker Date: Mon, 24 Apr 2023 18:52:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8D=87=E7=BA=A7springboot=20=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=B8=BA=202.7.10,=20=E4=BF=AE=E5=A4=8D=20CVE-2023-20?= =?UTF-8?q?860?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- opsli-api/pom.xml | 4 +- opsli-base-support/opsli-core/pom.xml | 5 +- .../autoconfigure/conf/SwaggerConfig.java | 45 ++++++ .../MySQLDatabaseTableServiceImpl.java | 2 + .../logs/service/impl/GenLogsServiceImpl.java | 2 + .../service/impl/GenTableServiceImpl.java | 3 + .../opsli-plugins-pagehelper/pom.xml | 51 +++++++ .../PageHelperAutoConfiguration.java | 69 +++++++++ .../pagehelper/PageHelperProperties.java | 135 ++++++++++++++++++ ...itional-spring-configuration-metadata.json | 88 ++++++++++++ .../main/resources/META-INF/spring.factories | 3 + opsli-plugins/pom.xml | 1 + .../src/main/resources/application.yaml | 10 +- pom.xml | 21 +-- 14 files changed, 422 insertions(+), 17 deletions(-) create mode 100644 opsli-plugins/opsli-plugins-pagehelper/pom.xml create mode 100644 opsli-plugins/opsli-plugins-pagehelper/src/main/java/org/opsli/plugins/pagehelper/PageHelperAutoConfiguration.java create mode 100644 opsli-plugins/opsli-plugins-pagehelper/src/main/java/org/opsli/plugins/pagehelper/PageHelperProperties.java create mode 100644 opsli-plugins/opsli-plugins-pagehelper/src/main/resources/META-INF/additional-spring-configuration-metadata.json create mode 100644 opsli-plugins/opsli-plugins-pagehelper/src/main/resources/META-INF/spring.factories diff --git a/opsli-api/pom.xml b/opsli-api/pom.xml index 208948f..c51251f 100644 --- a/opsli-api/pom.xml +++ b/opsli-api/pom.xml @@ -43,9 +43,9 @@ com.github.xiaoymin knife4j-spring-boot-starter - 2.0.5 + ${knife4j.version} - \ No newline at end of file + diff --git a/opsli-base-support/opsli-core/pom.xml b/opsli-base-support/opsli-core/pom.xml index 6b489e3..2771ce9 100644 --- a/opsli-base-support/opsli-core/pom.xml +++ b/opsli-base-support/opsli-core/pom.xml @@ -120,8 +120,9 @@ - com.github.pagehelper - pagehelper-spring-boot-starter + org.opsliframework.boot + opsli-plugins-pagehelper + ${pagehelper.version} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/autoconfigure/conf/SwaggerConfig.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/autoconfigure/conf/SwaggerConfig.java index f7a293c..15d40cb 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/autoconfigure/conf/SwaggerConfig.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/autoconfigure/conf/SwaggerConfig.java @@ -21,10 +21,14 @@ import com.google.common.collect.Lists; import io.swagger.annotations.ApiOperation; import org.opsli.core.autoconfigure.properties.GlobalProperties; import org.opsli.core.utils.UserTokenUtil; +import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.util.ReflectionUtils; +import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ParameterBuilder; @@ -35,10 +39,14 @@ import springfox.documentation.service.*; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider; +import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider; import springfox.documentation.swagger2.annotations.EnableSwagger2; import javax.annotation.Resource; +import java.lang.reflect.Field; import java.util.List; +import java.util.stream.Collectors; /** * Swagger 配置类 @@ -151,4 +159,41 @@ public class SwaggerConfig { return new ApiKey(UserTokenUtil.TOKEN_NAME, UserTokenUtil.TOKEN_NAME, "header"); } + /** + * 解决springboot2.6 和springfox不兼容问题 + * @return + */ + @Bean + public static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() { + return new BeanPostProcessor() { + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) { + customizeSpringfoxHandlerMappings(getHandlerMappings(bean)); + } + return bean; + } + + private void customizeSpringfoxHandlerMappings(List mappings) { + List copy = mappings.stream() + .filter(mapping -> mapping.getPatternParser() == null) + .collect(Collectors.toList()); + mappings.clear(); + mappings.addAll(copy); + } + + @SuppressWarnings("unchecked") + private List getHandlerMappings(Object bean) { + try { + Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings"); + field.setAccessible(true); + return (List) field.get(bean); + } catch (IllegalArgumentException | IllegalAccessException e) { + throw new IllegalStateException(e); + } + } + }; + } + } diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/importable/service/MySQLDatabaseTableServiceImpl.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/importable/service/MySQLDatabaseTableServiceImpl.java index 9035a74..02e5745 100644 --- a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/importable/service/MySQLDatabaseTableServiceImpl.java +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/importable/service/MySQLDatabaseTableServiceImpl.java @@ -24,6 +24,7 @@ import org.opsli.modulars.generator.importable.entity.DatabaseTable; import org.opsli.modulars.generator.importable.mapper.MySQLDatabaseTableMapper; import org.opsli.modulars.generator.table.service.IGenTableService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import java.util.List; @@ -50,6 +51,7 @@ public class MySQLDatabaseTableServiceImpl implements DatabaseTableService { @Autowired(required = false) private MySQLDatabaseTableMapper mapper; + @Lazy @Autowired private IGenTableService iGenTableService; diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/logs/service/impl/GenLogsServiceImpl.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/logs/service/impl/GenLogsServiceImpl.java index 3f02b35..c8a3b3b 100644 --- a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/logs/service/impl/GenLogsServiceImpl.java +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/logs/service/impl/GenLogsServiceImpl.java @@ -40,6 +40,7 @@ import org.opsli.modulars.generator.table.service.IGenTableService; import org.opsli.modulars.generator.table.wrapper.GenTableAndColumnModel; import org.opsli.modulars.generator.table.wrapper.GenTableModel; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -53,6 +54,7 @@ import java.util.List; * @author parker * @date 2020-09-16 17:34 */ +@Lazy(false) @Service public class GenLogsServiceImpl extends CrudServiceImpl implements IGenLogsService { diff --git a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/table/service/impl/GenTableServiceImpl.java b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/table/service/impl/GenTableServiceImpl.java index 040bb89..91a5a4e 100644 --- a/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/table/service/impl/GenTableServiceImpl.java +++ b/opsli-modulars/opsli-modulars-generator/src/main/java/org/opsli/modulars/generator/table/service/impl/GenTableServiceImpl.java @@ -37,6 +37,7 @@ import org.opsli.modulars.generator.table.service.IGenTableService; import org.opsli.modulars.generator.table.wrapper.GenTableAndColumnModel; import org.opsli.modulars.generator.table.wrapper.GenTableModel; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -57,9 +58,11 @@ public class GenTableServiceImpl extends CrudServiceImpl + + + opsli-plugins + org.opsliframework.boot + 1.0.0 + + 4.0.0 + + 1.4.6 + opsli-plugins-pagehelper + + + 5.3.2 + 2.2.2 + + + + + org.mybatis + mybatis + compile + + + + com.github.pagehelper + pagehelper + ${pagehelper.version} + + + org.mybatis.spring.boot + mybatis-spring-boot-autoconfigure + ${mybatis-spring-boot.version} + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + ${mybatis-spring-boot.version} + + + + + org.springframework.boot + spring-boot-autoconfigure + + + + + diff --git a/opsli-plugins/opsli-plugins-pagehelper/src/main/java/org/opsli/plugins/pagehelper/PageHelperAutoConfiguration.java b/opsli-plugins/opsli-plugins-pagehelper/src/main/java/org/opsli/plugins/pagehelper/PageHelperAutoConfiguration.java new file mode 100644 index 0000000..10eef9d --- /dev/null +++ b/opsli-plugins/opsli-plugins-pagehelper/src/main/java/org/opsli/plugins/pagehelper/PageHelperAutoConfiguration.java @@ -0,0 +1,69 @@ +package org.opsli.plugins.pagehelper; + +import com.github.pagehelper.PageInterceptor; +import org.apache.ibatis.plugin.Interceptor; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; + +import java.util.List; + +/** + * 自定注入分页插件 + * + * @author liuzh + */ +@Configuration +@ConditionalOnBean(SqlSessionFactory.class) +@EnableConfigurationProperties(PageHelperProperties.class) +@AutoConfigureAfter(MybatisAutoConfiguration.class) +@Lazy(false) +public class PageHelperAutoConfiguration implements InitializingBean { + + private final List sqlSessionFactoryList; + + private final PageHelperProperties properties; + + public PageHelperAutoConfiguration(List sqlSessionFactoryList, PageHelperProperties properties) { + this.sqlSessionFactoryList = sqlSessionFactoryList; + this.properties = properties; + } + + @Override + public void afterPropertiesSet() { + // 关闭 Banner + String bannerFlag = Boolean.TRUE.equals(this.properties.getBanner())?"true":"false"; + System.setProperty("pagehelper.banner", bannerFlag); + + PageInterceptor interceptor = new PageInterceptor(); + interceptor.setProperties(this.properties); + for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) { + org.apache.ibatis.session.Configuration configuration = sqlSessionFactory.getConfiguration(); + if (!containsInterceptor(configuration, interceptor)) { + configuration.addInterceptor(interceptor); + } + } + } + + /** + * 是否已经存在相同的拦截器 + * + * @param configuration + * @param interceptor + * @return + */ + private boolean containsInterceptor(org.apache.ibatis.session.Configuration configuration, Interceptor interceptor) { + try { + // getInterceptors since 3.2.2 + return configuration.getInterceptors().contains(interceptor); + } catch (Exception e) { + return false; + } + } + +} diff --git a/opsli-plugins/opsli-plugins-pagehelper/src/main/java/org/opsli/plugins/pagehelper/PageHelperProperties.java b/opsli-plugins/opsli-plugins-pagehelper/src/main/java/org/opsli/plugins/pagehelper/PageHelperProperties.java new file mode 100644 index 0000000..fbe56e8 --- /dev/null +++ b/opsli-plugins/opsli-plugins-pagehelper/src/main/java/org/opsli/plugins/pagehelper/PageHelperProperties.java @@ -0,0 +1,135 @@ +package org.opsli.plugins.pagehelper; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.util.Properties; + +/** + * Configuration properties for PageHelper. + * + * @author liuzh + */ +@ConfigurationProperties(prefix = PageHelperProperties.PAGEHELPER_PREFIX) +public class PageHelperProperties extends Properties { + + public static final String PAGEHELPER_PREFIX = "pagehelper"; + + public Boolean getOffsetAsPageNum() { + return Boolean.valueOf(getProperty("offsetAsPageNum")); + } + + public void setOffsetAsPageNum(Boolean offsetAsPageNum) { + setProperty("offsetAsPageNum", offsetAsPageNum.toString()); + } + + public Boolean getRowBoundsWithCount() { + return Boolean.valueOf(getProperty("rowBoundsWithCount")); + } + + public void setRowBoundsWithCount(Boolean rowBoundsWithCount) { + setProperty("rowBoundsWithCount", rowBoundsWithCount.toString()); + } + + public Boolean getPageSizeZero() { + return Boolean.valueOf(getProperty("pageSizeZero")); + } + + public void setPageSizeZero(Boolean pageSizeZero) { + setProperty("pageSizeZero", pageSizeZero.toString()); + } + + public Boolean getReasonable() { + return Boolean.valueOf(getProperty("reasonable")); + } + + public void setReasonable(Boolean reasonable) { + setProperty("reasonable", reasonable.toString()); + } + + public Boolean getSupportMethodsArguments() { + return Boolean.valueOf(getProperty("supportMethodsArguments")); + } + + public void setSupportMethodsArguments(Boolean supportMethodsArguments) { + setProperty("supportMethodsArguments", supportMethodsArguments.toString()); + } + + public String getDialect() { + return getProperty("dialect"); + } + + public void setDialect(String dialect) { + setProperty("dialect", dialect); + } + + public String getHelperDialect() { + return getProperty("helperDialect"); + } + + public void setHelperDialect(String helperDialect) { + setProperty("helperDialect", helperDialect); + } + + public Boolean getAutoRuntimeDialect() { + return Boolean.valueOf(getProperty("autoRuntimeDialect")); + } + + public void setAutoRuntimeDialect(Boolean autoRuntimeDialect) { + setProperty("autoRuntimeDialect", autoRuntimeDialect.toString()); + } + + public Boolean getAutoDialect() { + return Boolean.valueOf(getProperty("autoDialect")); + } + + public void setAutoDialect(Boolean autoDialect) { + setProperty("autoDialect", autoDialect.toString()); + } + + public Boolean getCloseConn() { + return Boolean.valueOf(getProperty("closeConn")); + } + + public void setCloseConn(Boolean closeConn) { + setProperty("closeConn", closeConn.toString()); + } + + public String getParams() { + return getProperty("params"); + } + + public void setParams(String params) { + setProperty("params", params); + } + + public Boolean getDefaultCount() { + return Boolean.valueOf(getProperty("defaultCount")); + } + + public void setDefaultCount(Boolean defaultCount) { + setProperty("defaultCount", defaultCount.toString()); + } + + public String getDialectAlias() { + return getProperty("dialectAlias"); + } + + public void setDialectAlias(String dialectAlias) { + setProperty("dialectAlias", dialectAlias); + } + + public String getAutoDialectClass() { + return getProperty("autoDialectClass"); + } + + public void setAutoDialectClass(String autoDialectClass) { + setProperty("autoDialectClass", autoDialectClass); + } + + public Boolean getBanner() { + return Boolean.valueOf(getProperty("banner")); + } + public void setBanner(Boolean banner) { + setProperty("banner", banner.toString()); + } +} diff --git a/opsli-plugins/opsli-plugins-pagehelper/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/opsli-plugins/opsli-plugins-pagehelper/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 0000000..052b409 --- /dev/null +++ b/opsli-plugins/opsli-plugins-pagehelper/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,88 @@ +{ + "groups": [ + { + "name": "pagehelper", + "type": "org.opsli.plugins.pagehelper.PageHelperProperties", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + } + ], + "properties": [ + { + "name": "pagehelper.banner", + "type": "java.lang.Boolean", + "defaultValue": false, + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.auto-dialect", + "type": "java.lang.Boolean", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.auto-dialect-class", + "type": "java.lang.String", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.auto-runtime-dialect", + "type": "java.lang.Boolean", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.close-conn", + "type": "java.lang.Boolean", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.default-count", + "type": "java.lang.Boolean", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.dialect", + "type": "java.lang.String", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.dialect-alias", + "type": "java.lang.String", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.helper-dialect", + "type": "java.lang.String", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.offset-as-page-num", + "type": "java.lang.Boolean", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.page-size-zero", + "type": "java.lang.Boolean", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.params", + "type": "java.lang.String", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.reasonable", + "type": "java.lang.Boolean", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.row-bounds-with-count", + "type": "java.lang.Boolean", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + }, + { + "name": "pagehelper.support-methods-arguments", + "type": "java.lang.Boolean", + "sourceType": "org.opsli.plugins.pagehelper.PageHelperProperties" + } + ], + "hints": [] +} diff --git a/opsli-plugins/opsli-plugins-pagehelper/src/main/resources/META-INF/spring.factories b/opsli-plugins/opsli-plugins-pagehelper/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..330be8e --- /dev/null +++ b/opsli-plugins/opsli-plugins-pagehelper/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Auto Configure +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.opsli.plugins.pagehelper.PageHelperAutoConfiguration diff --git a/opsli-plugins/pom.xml b/opsli-plugins/pom.xml index 9228056..d898af7 100644 --- a/opsli-plugins/pom.xml +++ b/opsli-plugins/pom.xml @@ -25,6 +25,7 @@ opsli-plugins-email opsli-plugins-sms opsli-plugins-security + opsli-plugins-pagehelper diff --git a/opsli-starter/src/main/resources/application.yaml b/opsli-starter/src/main/resources/application.yaml index 098d489..283a11e 100644 --- a/opsli-starter/src/main/resources/application.yaml +++ b/opsli-starter/src/main/resources/application.yaml @@ -36,8 +36,6 @@ spring: max-file-size: 10MB max-request-size: 10MB #静态资源 - resources: - static-locations: classpath:/META-INF/resources/,classpath:/resources/, classpath:/static/, classpath:/public/,file:${opsli.web.upload-path} #json 时间戳统一转换 jackson: date-format: yyyy-MM-dd HH:mm:ss @@ -52,7 +50,13 @@ spring: # #main: # allow-bean-definition-overriding: true - + web: + resources: + static-locations: classpath:/META-INF/resources/,classpath:/resources/, classpath:/static/, classpath:/public/,file:${opsli.web.upload-path} + mvc: + #Spring Boot 2.6+后映射匹配的默认策略已从AntPathMatcher更改为PathPatternParser,需要手动指定为ant-path-matcher + pathmatch: + matching-strategy: ant_path_matcher # 缓存配置项 cache: # 前缀 diff --git a/pom.xml b/pom.xml index 7f207d9..d09f375 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ org.springframework.boot spring-boot-starter-parent - 2.5.6 + 2.7.10 @@ -59,12 +59,15 @@ UTF-8 UTF-8 1.8 - 2.5.6 + + 2.7.10 true 1.2.83 + 3.5.9 3.5.2 - 1.3.0 + 1.4.6 + 3.0.3 3.10.3 5.6.1 @@ -169,19 +172,17 @@ + + org.mybatis + mybatis + ${mybatis.version} + com.baomidou mybatis-plus-boot-starter ${mybatis-plus.version} - - - com.github.pagehelper - pagehelper-spring-boot-starter - ${pagehelper.version} - - com.alibaba