@@ -107,11 +107,16 @@ public List<Docket> createRestApi(SwaggerProperties swaggerProperties) {
107
107
Docket docketForBuilder = new Docket (DocumentationType .SWAGGER_2 )
108
108
.host (swaggerProperties .getHost ())
109
109
.apiInfo (apiInfo )
110
- .securitySchemes (Collections .singletonList (apiKey ()))
111
110
.securityContexts (Collections .singletonList (securityContext ()))
112
111
.globalOperationParameters (buildGlobalOperationParametersFromSwaggerProperties (
113
112
swaggerProperties .getGlobalOperationParameters ()));
114
113
114
+ if ("BasicAuth" .equalsIgnoreCase (swaggerProperties .getAuthorization ().getType ())) {
115
+ docketForBuilder .securitySchemes (Collections .singletonList (basicAuth ()));
116
+ } else if (!"None" .equalsIgnoreCase (swaggerProperties .getAuthorization ().getType ())) {
117
+ docketForBuilder .securitySchemes (Collections .singletonList (apiKey ()));
118
+ }
119
+
115
120
// 全局响应消息
116
121
if (!swaggerProperties .getApplyDefaultResponseMessages ()) {
117
122
buildGlobalResponseMessage (swaggerProperties , docketForBuilder );
@@ -175,11 +180,16 @@ public List<Docket> createRestApi(SwaggerProperties swaggerProperties) {
175
180
Docket docketForBuilder = new Docket (DocumentationType .SWAGGER_2 )
176
181
.host (swaggerProperties .getHost ())
177
182
.apiInfo (apiInfo )
178
- .securitySchemes (Collections .singletonList (apiKey ()))
179
183
.securityContexts (Collections .singletonList (securityContext ()))
180
184
.globalOperationParameters (assemblyGlobalOperationParameters (swaggerProperties .getGlobalOperationParameters (),
181
185
docketInfo .getGlobalOperationParameters ()));
182
186
187
+ if ("BasicAuth" .equalsIgnoreCase (swaggerProperties .getAuthorization ().getType ())) {
188
+ docketForBuilder .securitySchemes (Collections .singletonList (basicAuth ()));
189
+ } else if (!"None" .equalsIgnoreCase (swaggerProperties .getAuthorization ().getType ())) {
190
+ docketForBuilder .securitySchemes (Collections .singletonList (apiKey ()));
191
+ }
192
+
183
193
// 全局响应消息
184
194
if (!swaggerProperties .getApplyDefaultResponseMessages ()) {
185
195
buildGlobalResponseMessage (swaggerProperties , docketForBuilder );
@@ -218,6 +228,15 @@ private ApiKey apiKey() {
218
228
ApiKeyVehicle .HEADER .getValue ());
219
229
}
220
230
231
+ /**
232
+ * 配置基于 BasicAuth 的鉴权对象
233
+ *
234
+ * @return
235
+ */
236
+ private BasicAuth basicAuth () {
237
+ return new BasicAuth (swaggerProperties ().getAuthorization ().getName ());
238
+ }
239
+
221
240
/**
222
241
* 配置默认的全局鉴权策略的开关,以及通过正则表达式进行匹配;默认 ^.*$ 匹配所有URL
223
242
* 其中 securityReferences 为配置启用的鉴权策略
0 commit comments