From 1700db64c52a285eab45080560cc047f36549b29 Mon Sep 17 00:00:00 2001 From: smallchill Date: Tue, 19 Jul 2022 12:24:42 +0800 Subject: [PATCH] =?UTF-8?q?:tada:=203.4.1.RELEASE=20=E9=87=8D=E6=9E=84swag?= =?UTF-8?q?ger=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blade-core-boot/pom.xml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- blade-core-cloud/pom.xml | 2 +- blade-core-datascope/pom.xml | 2 +- blade-core-develop/pom.xml | 2 +- .../main/resources/templates/entity.java.vm | 6 +- .../main/resources/templates/entityVO.java.vm | 4 +- blade-core-launch/pom.xml | 2 +- .../core/launch/constant/AppConstant.java | 2 +- blade-core-loadbalancer/pom.xml | 2 +- blade-core-log/pom.xml | 2 +- blade-core-mybatis/pom.xml | 2 +- blade-core-oss/pom.xml | 2 +- blade-core-report/pom.xml | 2 +- blade-core-secure/pom.xml | 2 +- blade-core-social/pom.xml | 2 +- blade-core-swagger/pom.xml | 2 +- .../swagger/SwaggerAutoConfiguration.java | 74 ++++++++++--------- .../core/swagger/SwaggerProperties.java | 35 ++++++++- .../springblade/core/swagger/SwaggerUtil.java | 17 ++++- .../core/swagger/SwaggerWebConfiguration.java | 39 ++++++++++ blade-core-test/pom.xml | 2 +- blade-core-tool/pom.xml | 2 +- blade-core-transaction/pom.xml | 2 +- pom.xml | 6 +- 25 files changed, 153 insertions(+), 64 deletions(-) create mode 100644 blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerWebConfiguration.java diff --git a/blade-core-boot/pom.xml b/blade-core-boot/pom.xml index 35482fe..061af72 100644 --- a/blade-core-boot/pom.xml +++ b/blade-core-boot/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-tool - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-boot/src/main/resources/bootstrap.yml b/blade-core-boot/src/main/resources/bootstrap.yml index f92e08d..57d74a0 100644 --- a/blade-core-boot/src/main/resources/bootstrap.yml +++ b/blade-core-boot/src/main/resources/bootstrap.yml @@ -101,7 +101,7 @@ mybatis-plus: swagger: title: SpringBlade 接口文档系统 description: SpringBlade 接口文档系统 - version: 3.4.0 + version: 3.4.1 license: Powered By SpringBlade licenseUrl: https://bladex.vip terms-of-service-url: https://bladex.vip diff --git a/blade-core-cloud/pom.xml b/blade-core-cloud/pom.xml index df03569..91cc7e2 100644 --- a/blade-core-cloud/pom.xml +++ b/blade-core-cloud/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-datascope/pom.xml b/blade-core-datascope/pom.xml index 774e7eb..8d0e52f 100644 --- a/blade-core-datascope/pom.xml +++ b/blade-core-datascope/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-develop/pom.xml b/blade-core-develop/pom.xml index 3ce2235..47c59ab 100644 --- a/blade-core-develop/pom.xml +++ b/blade-core-develop/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-develop/src/main/resources/templates/entity.java.vm b/blade-core-develop/src/main/resources/templates/entity.java.vm index d4992e7..08afc0b 100644 --- a/blade-core-develop/src/main/resources/templates/entity.java.vm +++ b/blade-core-develop/src/main/resources/templates/entity.java.vm @@ -22,7 +22,7 @@ import $!{pkg}; import lombok.Data; import lombok.EqualsAndHashCode; #end -#if($!{swagger2}) +#if($!{swagger}) import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; #end @@ -42,7 +42,7 @@ import io.swagger.annotations.ApiModelProperty; #if($!{superEntityClass}) @EqualsAndHashCode(callSuper = true) #end -#if($!{swagger2}) +#if($!{swagger}) @ApiModel(value = "$!{entity}对象", description = #if ("$!{table.comment}"=="")"$!{entity}对象"#else"$!{table.comment}"#end) #end #if($!{superEntityClass}) @@ -66,7 +66,7 @@ public class $!{entity} implements Serializable { /** * $!{field.comment} */ - #if($!{swagger2}) + #if($!{swagger}) @ApiModelProperty(value = "$!{field.comment}") #end #end diff --git a/blade-core-develop/src/main/resources/templates/entityVO.java.vm b/blade-core-develop/src/main/resources/templates/entityVO.java.vm index cc88136..ac0f812 100644 --- a/blade-core-develop/src/main/resources/templates/entityVO.java.vm +++ b/blade-core-develop/src/main/resources/templates/entityVO.java.vm @@ -21,7 +21,7 @@ import $!{package.Entity}.$!{entity}; import lombok.Data; import lombok.EqualsAndHashCode; #end -#if($!{swagger2}) +#if($!{swagger}) import io.swagger.annotations.ApiModel; #end @@ -35,7 +35,7 @@ import io.swagger.annotations.ApiModel; @Data @EqualsAndHashCode(callSuper = true) #end -#if($!{swagger2}) +#if($!{swagger}) @ApiModel(value = "$!{entity}VO对象", description = #if ("$!{table.comment}"=="")"$!{entity}VO对象"#else"$!{table.comment}"#end) #end public class $!{entity}VO extends $!{entity} { diff --git a/blade-core-launch/pom.xml b/blade-core-launch/pom.xml index 39f3fbf..527a0fc 100644 --- a/blade-core-launch/pom.xml +++ b/blade-core-launch/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java index 1ba6339..cd09d6c 100644 --- a/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java +++ b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java @@ -25,7 +25,7 @@ public interface AppConstant { /** * 应用版本 */ - String APPLICATION_VERSION = "3.4.0"; + String APPLICATION_VERSION = "3.4.1"; /** * 基础包 diff --git a/blade-core-loadbalancer/pom.xml b/blade-core-loadbalancer/pom.xml index 5f3bae7..49b11cb 100644 --- a/blade-core-loadbalancer/pom.xml +++ b/blade-core-loadbalancer/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-log/pom.xml b/blade-core-log/pom.xml index 17e42a7..fb1bb8a 100644 --- a/blade-core-log/pom.xml +++ b/blade-core-log/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-mybatis/pom.xml b/blade-core-mybatis/pom.xml index b792d16..8caac07 100644 --- a/blade-core-mybatis/pom.xml +++ b/blade-core-mybatis/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-oss/pom.xml b/blade-core-oss/pom.xml index 0fa60c1..1020e2f 100644 --- a/blade-core-oss/pom.xml +++ b/blade-core-oss/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-report/pom.xml b/blade-core-report/pom.xml index a54e55c..029877b 100644 --- a/blade-core-report/pom.xml +++ b/blade-core-report/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-secure/pom.xml b/blade-core-secure/pom.xml index eabf8b8..016a26e 100644 --- a/blade-core-secure/pom.xml +++ b/blade-core-secure/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-social/pom.xml b/blade-core-social/pom.xml index bc9640c..2072104 100644 --- a/blade-core-social/pom.xml +++ b/blade-core-social/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-swagger/pom.xml b/blade-core-swagger/pom.xml index 34efeb6..7f50c3d 100644 --- a/blade-core-swagger/pom.xml +++ b/blade-core-swagger/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerAutoConfiguration.java b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerAutoConfiguration.java index 0d8c13c..9ea3871 100644 --- a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerAutoConfiguration.java +++ b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerAutoConfiguration.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018-2028, lengleng (wangiegie@gmail.com). + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). *

* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import lombok.AllArgsConstructor; import org.springblade.core.launch.props.BladeProperties; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; @@ -44,11 +43,10 @@ import java.util.List; * * @author Chill */ -@AutoConfiguration @EnableSwagger -@EnableConfigurationProperties(SwaggerProperties.class) -@Import(BeanValidatorPluginsConfiguration.class) +@AutoConfiguration @AllArgsConstructor +@Import(BeanValidatorPluginsConfiguration.class) public class SwaggerAutoConfiguration { private static final String DEFAULT_BASE_PATH = "/**"; @@ -71,13 +69,11 @@ public class SwaggerAutoConfiguration { } @Bean + @ConditionalOnMissingBean public Docket api(SwaggerProperties swaggerProperties) { - // base-path处理 if (swaggerProperties.getBasePath().size() == 0) { swaggerProperties.getBasePath().add(DEFAULT_BASE_PATH); } - - // exclude-path处理 if (swaggerProperties.getExcludePath().size() == 0) { swaggerProperties.getExcludePath().addAll(DEFAULT_EXCLUDE_PATH); } @@ -85,54 +81,60 @@ public class SwaggerAutoConfiguration { .host(swaggerProperties.getHost()) .apiInfo(apiInfo(swaggerProperties)).select() .apis(SwaggerUtil.basePackages(swaggerProperties.getBasePackages())); - swaggerProperties.getBasePath().forEach(p -> apis.paths(PathSelectors.ant(p))); swaggerProperties.getExcludePath().forEach(p -> apis.paths(PathSelectors.ant(p).negate())); - - return apis.build() - .securitySchemes(Collections.singletonList(securitySchema(swaggerProperties))) - .securityContexts(Collections.singletonList(securityContext(swaggerProperties))) - .securityContexts(Lists.newArrayList(securityContext(swaggerProperties))) - .securitySchemes(Collections.singletonList(securitySchema(swaggerProperties))) + return apis.build().securityContexts(securityContexts(swaggerProperties)).securitySchemes(securitySchemas(swaggerProperties)) .extensions(openApiExtensionResolver.buildExtensions(bladeProperties.getName())); } /** * 配置默认的全局鉴权策略的开关,通过正则表达式进行匹配;默认匹配所有URL - * - * @return */ - private SecurityContext securityContext(SwaggerProperties swaggerProperties) { - return SecurityContext.builder() + private List securityContexts(SwaggerProperties swaggerProperties) { + return Collections.singletonList(SecurityContext.builder() .securityReferences(defaultAuth(swaggerProperties)) .forPaths(PathSelectors.regex(swaggerProperties.getAuthorization().getAuthRegex())) - .build(); + .build()); } /** * 默认的全局鉴权策略 - * - * @return */ private List defaultAuth(SwaggerProperties swaggerProperties) { - ArrayList authorizationScopeList = new ArrayList<>(); - swaggerProperties.getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription()))); - AuthorizationScope[] authorizationScopes = new AuthorizationScope[authorizationScopeList.size()]; - return Collections.singletonList(SecurityReference.builder() - .reference(swaggerProperties.getAuthorization().getName()) - .scopes(authorizationScopeList.toArray(authorizationScopes)) - .build()); + List authorizationScopeList = new ArrayList<>(); + List securityReferenceList = new ArrayList<>(); + List swaggerScopeList = swaggerProperties.getAuthorization().getAuthorizationScopeList(); + swaggerScopeList.forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription()))); + if (authorizationScopeList.size() == 0) { + authorizationScopeList.add(new AuthorizationScope("global", "accessEverywhere")); + } + AuthorizationScope[] authorizationScopes = authorizationScopeList.toArray(new AuthorizationScope[0]); + swaggerScopeList.forEach(authorizationScope -> securityReferenceList.add(new SecurityReference(authorizationScope.getName(), authorizationScopes))); + if (securityReferenceList.size() == 0) { + securityReferenceList.add(new SecurityReference(SwaggerUtil.clientInfo().getName(), authorizationScopes)); + securityReferenceList.add(new SecurityReference(SwaggerUtil.bladeAuth().getName(), authorizationScopes)); + securityReferenceList.add(new SecurityReference(SwaggerUtil.bladeTenant().getName(), authorizationScopes)); + } + return securityReferenceList; } - - private OAuth securitySchema(SwaggerProperties swaggerProperties) { - ArrayList authorizationScopeList = new ArrayList<>(); - swaggerProperties.getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription()))); - ArrayList grantTypes = new ArrayList<>(); - swaggerProperties.getAuthorization().getTokenUrlList().forEach(tokenUrl -> grantTypes.add(new ResourceOwnerPasswordCredentialsGrant(tokenUrl))); - return new OAuth(swaggerProperties.getAuthorization().getName(), authorizationScopeList, grantTypes); + /** + * 配置安全策略 + */ + private List securitySchemas(SwaggerProperties swaggerProperties) { + List swaggerApiKeyList = swaggerProperties.getAuthorization().getAuthorizationApiKeyList(); + if (swaggerApiKeyList.size() == 0) { + return Lists.newArrayList(SwaggerUtil.clientInfo(), SwaggerUtil.bladeAuth(), SwaggerUtil.bladeTenant()); + } else { + List securitySchemeList = new ArrayList<>(); + swaggerApiKeyList.forEach(authorizationApiKey -> securitySchemeList.add(new ApiKey(authorizationApiKey.getName(), authorizationApiKey.getKeyName(), authorizationApiKey.getPassAs()))); + return securitySchemeList; + } } + /** + * 配置基本信息 + */ private ApiInfo apiInfo(SwaggerProperties swaggerProperties) { return new ApiInfoBuilder() .title(swaggerProperties.getTitle()) diff --git a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java index 07c9a3c..30bf3cf 100644 --- a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java +++ b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerProperties.java @@ -55,7 +55,7 @@ public class SwaggerProperties { /** * 版本 **/ - private String version = "3.4.0"; + private String version = "3.4.1"; /** * 许可证 **/ @@ -120,6 +120,14 @@ public class SwaggerProperties { */ private List authorizationScopeList = new ArrayList<>(); + /** + * 鉴权请求头参数列表 + */ + private List authorizationApiKeyList = new ArrayList<>(); + + /** + * 接口匹配地址 + */ private List tokenUrlList = new ArrayList<>(); } @@ -127,6 +135,10 @@ public class SwaggerProperties { @NoArgsConstructor public static class AuthorizationScope { + /** + * 鉴权策略名, 需要和ApiKey的name保持一致 + */ + private String name = ""; /** * 作用域名称 */ @@ -138,4 +150,25 @@ public class SwaggerProperties { private String description = ""; } + + @Data + @NoArgsConstructor + public static class AuthorizationApiKey { + + /** + * 参数名 + */ + private String name = ""; + + /** + * 参数值 + */ + private String keyName = ""; + + /** + * 参数作用域 + */ + private String passAs = ""; + + } } diff --git a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerUtil.java b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerUtil.java index a6a0aae..6171b5a 100644 --- a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerUtil.java +++ b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerUtil.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018-2028, lengleng (wangiegie@gmail.com). + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). *

* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; * you may not use this file except in compliance with the License. @@ -17,7 +17,9 @@ package org.springblade.core.swagger; import com.google.common.base.Function; import com.google.common.base.Optional; +import org.springblade.core.launch.constant.TokenConstant; import springfox.documentation.RequestHandler; +import springfox.documentation.service.ApiKey; import java.util.List; import java.util.function.Predicate; @@ -55,4 +57,17 @@ public class SwaggerUtil { return Optional.fromNullable(input.declaringClass()); } + + public static ApiKey clientInfo() { + return new ApiKey("ClientInfo", "Authorization", "header"); + } + + public static ApiKey bladeAuth() { + return new ApiKey("BladeAuth", TokenConstant.HEADER, "header"); + } + + public static ApiKey bladeTenant() { + return new ApiKey("TenantId", "Tenant-Id", "header"); + } + } diff --git a/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerWebConfiguration.java b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerWebConfiguration.java new file mode 100644 index 0000000..54c3995 --- /dev/null +++ b/blade-core-swagger/src/main/java/org/springblade/core/swagger/SwaggerWebConfiguration.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com). + *

+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springblade.core.swagger; + + +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * swagger资源配置 + * + * @author Chill + */ +@AutoConfiguration +@EnableConfigurationProperties(SwaggerProperties.class) +public class SwaggerWebConfiguration implements WebMvcConfigurer { + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); + registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); + } + +} diff --git a/blade-core-test/pom.xml b/blade-core-test/pom.xml index 09f950f..4e06412 100644 --- a/blade-core-test/pom.xml +++ b/blade-core-test/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-tool - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-tool/pom.xml b/blade-core-tool/pom.xml index dadc4f9..ad76442 100644 --- a/blade-core-tool/pom.xml +++ b/blade-core-tool/pom.xml @@ -6,7 +6,7 @@ org.springblade blade-tool - 3.4.0 + 3.4.1 4.0.0 diff --git a/blade-core-transaction/pom.xml b/blade-core-transaction/pom.xml index acf9543..b6e089f 100644 --- a/blade-core-transaction/pom.xml +++ b/blade-core-transaction/pom.xml @@ -5,7 +5,7 @@ blade-tool org.springblade - 3.4.0 + 3.4.1 4.0.0 diff --git a/pom.xml b/pom.xml index 88eac72..53a0339 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springblade blade-tool - 3.4.0 + 3.4.1 pom blade-tool @@ -36,7 +36,7 @@ - 3.4.0 + 3.4.1 1.8 3.8.1 @@ -52,7 +52,7 @@ 1.2.5 2021.0.1.0 2.1.0 - 1.5.1.1 + 1.5.2 2.0.0.RELEASE 2.7.1