From e4148bf48bd40fd79a37b3353b0698822a31b612 Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Wed, 23 May 2018 17:44:30 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=96=87=E6=A1=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- pom.xml | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 379d966..99748af 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ # 版本基础 - Spring Boot:1.5.x -- Swagger:2.8.x +- Swagger:2.9.x # 如何使用 @@ -22,13 +22,13 @@ - 在`pom.xml`中引入依赖: -> 当前最新版本 1.7.0.RELEASE +> 当前最新版本 1.7.1.RELEASE ```xml com.spring4all swagger-spring-boot-starter - 1.7.0.RELEASE + 1.7.1.RELEASE ``` diff --git a/pom.xml b/pom.xml index 2a249ca..337027e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.spring4all swagger-spring-boot-starter - 1.7.0.RELEASE + 1.7.1.RELEASE spring-boot-starter-swagger https://github.com/SpringForAll/spring-boot-starter-swagger @@ -48,7 +48,7 @@ UTF-8 1.8 - 2.8.0 + 2.9.0 1.5.10.RELEASE 1.16.18 @@ -119,4 +119,12 @@ + + + + jcenter-snapshots + jcenter + https://jcenter.bintray.com/ + + \ No newline at end of file -- Gitee From cfd2c7f0510d9631183eb6333605821bfba664be Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Sat, 1 Sep 2018 13:57:09 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=8D=87=E7=BA=A7swagger=202.9.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 337027e..ccd29b8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.spring4all swagger-spring-boot-starter - 1.7.1.RELEASE + 1.8.0.RELEASE spring-boot-starter-swagger https://github.com/SpringForAll/spring-boot-starter-swagger @@ -48,7 +48,7 @@ UTF-8 1.8 - 2.9.0 + 2.9.2 1.5.10.RELEASE 1.16.18 -- Gitee From 359f9cd7460882a625f9324acc96883f12dde78f Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Sat, 1 Sep 2018 13:58:34 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=8D=87=E7=BA=A7swagger=202.9.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index ccd29b8..ac1cb28 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,11 @@ spring-boot-configuration-processor true + + org.springframework.boot + spring-boot-starter-web + true + io.springfox springfox-swagger-ui @@ -85,11 +90,6 @@ ${version.lombok} provided - - org.springframework.boot - spring-boot-starter-web - true - -- Gitee From f262848c165bc093a4abfb09764256c6c1839a89 Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Sat, 1 Sep 2018 14:14:04 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=8D=87=E7=BA=A7swagger=202.9.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 99748af..e875b8c 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,7 @@ # 版本基础 -- Spring Boot:1.5.x -- Swagger:2.9.x +- Swagger:2.9.2 # 如何使用 @@ -22,13 +21,11 @@ - 在`pom.xml`中引入依赖: -> 当前最新版本 1.7.1.RELEASE - ```xml com.spring4all swagger-spring-boot-starter - 1.7.1.RELEASE + 1.8.0.RELEASE ``` -- Gitee From 5be30eb152d0953c9bb1c94ba52580625f108d28 Mon Sep 17 00:00:00 2001 From: suiaing Date: Tue, 19 Feb 2019 09:20:53 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=94=AF=E6=8C=81=20BasicAuth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++- .../swagger/SwaggerAutoConfiguration.java | 23 +++++++++++++++++-- .../spring4all/swagger/SwaggerProperties.java | 5 ++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e875b8c..b13f5c2 100644 --- a/README.md +++ b/README.md @@ -283,6 +283,9 @@ swagger.docket.aaa.ignored-parameter-types[1]=com.didispace.demo.Product # 鉴权策略ID,对应 SecurityReferences ID swagger.authorization.name=Authorization +# 鉴权策略,可选 ApiKey | BasicAuth | None,默认ApiKey +swagger.authorization.type=ApiKey + # 鉴权传递的Header参数 swagger.authorization.key-name=token @@ -290,7 +293,7 @@ swagger.authorization.key-name=token swagger.authorization.auth-regex=^.*$ ``` -备注:目前支持`ApiKey`鉴权模式,后续添加`Oauth2`和`BasicAuth`支持 +备注:目前支持`ApiKey` | `BasicAuth`鉴权模式,`None`除消鉴权模式,默认ApiKey,后续添加`Oauth2`支持 **使用须知** diff --git a/src/main/java/com/spring4all/swagger/SwaggerAutoConfiguration.java b/src/main/java/com/spring4all/swagger/SwaggerAutoConfiguration.java index 143dd4e..77d9e9f 100644 --- a/src/main/java/com/spring4all/swagger/SwaggerAutoConfiguration.java +++ b/src/main/java/com/spring4all/swagger/SwaggerAutoConfiguration.java @@ -107,11 +107,16 @@ public class SwaggerAutoConfiguration implements BeanFactoryAware { Docket docketForBuilder = new Docket(DocumentationType.SWAGGER_2) .host(swaggerProperties.getHost()) .apiInfo(apiInfo) - .securitySchemes(Collections.singletonList(apiKey())) .securityContexts(Collections.singletonList(securityContext())) .globalOperationParameters(buildGlobalOperationParametersFromSwaggerProperties( swaggerProperties.getGlobalOperationParameters())); + if ("BasicAuth".equalsIgnoreCase(swaggerProperties.getAuthorization().getType())) { + docketForBuilder.securitySchemes(Collections.singletonList(basicAuth())); + } else if (!"None".equalsIgnoreCase(swaggerProperties.getAuthorization().getType())) { + docketForBuilder.securitySchemes(Collections.singletonList(apiKey())); + } + // 全局响应消息 if (!swaggerProperties.getApplyDefaultResponseMessages()) { buildGlobalResponseMessage(swaggerProperties, docketForBuilder); @@ -175,11 +180,16 @@ public class SwaggerAutoConfiguration implements BeanFactoryAware { Docket docketForBuilder = new Docket(DocumentationType.SWAGGER_2) .host(swaggerProperties.getHost()) .apiInfo(apiInfo) - .securitySchemes(Collections.singletonList(apiKey())) .securityContexts(Collections.singletonList(securityContext())) .globalOperationParameters(assemblyGlobalOperationParameters(swaggerProperties.getGlobalOperationParameters(), docketInfo.getGlobalOperationParameters())); + if ("BasicAuth".equalsIgnoreCase(swaggerProperties.getAuthorization().getType())) { + docketForBuilder.securitySchemes(Collections.singletonList(basicAuth())); + } else if (!"None".equalsIgnoreCase(swaggerProperties.getAuthorization().getType())) { + docketForBuilder.securitySchemes(Collections.singletonList(apiKey())); + } + // 全局响应消息 if (!swaggerProperties.getApplyDefaultResponseMessages()) { buildGlobalResponseMessage(swaggerProperties, docketForBuilder); @@ -218,6 +228,15 @@ public class SwaggerAutoConfiguration implements BeanFactoryAware { ApiKeyVehicle.HEADER.getValue()); } + /** + * 配置基于 BasicAuth 的鉴权对象 + * + * @return + */ + private BasicAuth basicAuth() { + return new BasicAuth(swaggerProperties().getAuthorization().getName()); + } + /** * 配置默认的全局鉴权策略的开关,以及通过正则表达式进行匹配;默认 ^.*$ 匹配所有URL * 其中 securityReferences 为配置启用的鉴权策略 diff --git a/src/main/java/com/spring4all/swagger/SwaggerProperties.java b/src/main/java/com/spring4all/swagger/SwaggerProperties.java index 0a43142..17768f6 100644 --- a/src/main/java/com/spring4all/swagger/SwaggerProperties.java +++ b/src/main/java/com/spring4all/swagger/SwaggerProperties.java @@ -344,6 +344,11 @@ public class SwaggerProperties { */ private String name = "Authorization"; + /** + * 鉴权策略,可选 ApiKey | BasicAuth | None,默认ApiKey + */ + private String type = "ApiKey"; + /** * 鉴权传递的Header参数 */ -- Gitee From 7cb8ff2ab4a3c9240e299d1c13a3e26b9d365b23 Mon Sep 17 00:00:00 2001 From: zhaiyongchao Date: Wed, 3 Apr 2019 13:49:20 +0800 Subject: [PATCH 6/7] update lombok 1.18.6 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ac1cb28..5f3789f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.spring4all swagger-spring-boot-starter - 1.8.0.RELEASE + 1.9.0.RELEASE spring-boot-starter-swagger https://github.com/SpringForAll/spring-boot-starter-swagger @@ -50,7 +50,7 @@ 1.8 2.9.2 1.5.10.RELEASE - 1.16.18 + 1.18.6 -- Gitee From 420e146f0ac2fcfd3a63b43cd4d605e895502fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=8C=BFDD?= Date: Wed, 3 Apr 2019 14:17:27 +0800 Subject: [PATCH 7/7] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新文档 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b13f5c2..0a9d412 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ com.spring4all swagger-spring-boot-starter - 1.8.0.RELEASE + 1.9.0.RELEASE ``` -- Gitee