Commit 7976840c51003041649493805d598cbf13c90333
1 parent
9d3b7722
swagger设置全局token,解决接口需要token验证的问题
Showing
1 changed file
with
19 additions
and
5 deletions
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/config/Swagger2Config.java
1 | 1 | package org.jeecg.config; |
2 | 2 | |
3 | 3 | import java.util.ArrayList; |
4 | +import java.util.Collections; | |
4 | 5 | import java.util.List; |
5 | 6 | |
6 | 7 | import org.jeecg.modules.shiro.vo.DefContants; |
... | ... | @@ -12,6 +13,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
12 | 13 | import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI; |
13 | 14 | |
14 | 15 | import io.swagger.annotations.ApiOperation; |
16 | +import springfox.documentation.service.ApiKey; | |
15 | 17 | import springfox.documentation.service.Parameter; |
16 | 18 | import lombok.extern.slf4j.Slf4j; |
17 | 19 | import springfox.documentation.builders.ApiInfoBuilder; |
... | ... | @@ -20,6 +22,7 @@ import springfox.documentation.builders.PathSelectors; |
20 | 22 | import springfox.documentation.builders.RequestHandlerSelectors; |
21 | 23 | import springfox.documentation.schema.ModelRef; |
22 | 24 | import springfox.documentation.service.ApiInfo; |
25 | +import springfox.documentation.service.SecurityScheme; | |
23 | 26 | import springfox.documentation.spi.DocumentationType; |
24 | 27 | import springfox.documentation.spring.web.plugins.Docket; |
25 | 28 | import springfox.documentation.swagger2.annotations.EnableSwagger2; |
... | ... | @@ -62,9 +65,20 @@ public class Swagger2Config implements WebMvcConfigurer { |
62 | 65 | .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) |
63 | 66 | .paths(PathSelectors.any()) |
64 | 67 | .build() |
65 | - .globalOperationParameters(setHeaderToken()); | |
68 | + .securitySchemes(Collections.singletonList(securityScheme())); | |
69 | + //.globalOperationParameters(setHeaderToken()); | |
66 | 70 | } |
67 | 71 | |
72 | + /*** | |
73 | + * oauth2配置 | |
74 | + * 需要增加swagger授权回调地址 | |
75 | + * http://localhost:8888/webjars/springfox-swagger-ui/o2c.html | |
76 | + * @return | |
77 | + */ | |
78 | + @Bean | |
79 | + SecurityScheme securityScheme() { | |
80 | + return new ApiKey(DefContants.X_ACCESS_TOKEN, DefContants.X_ACCESS_TOKEN, "header"); | |
81 | + } | |
68 | 82 | /** |
69 | 83 | * JWT token |
70 | 84 | * @return |
... | ... | @@ -90,11 +104,11 @@ public class Swagger2Config implements WebMvcConfigurer { |
90 | 104 | .version("1.0") |
91 | 105 | // .termsOfServiceUrl("NO terms of service") |
92 | 106 | // 描述 |
93 | - .description("restful 风格接口") | |
107 | + .description("后台API接口") | |
94 | 108 | // 作者 |
95 | -// .contact(new Contact("scott", "http://jeecg.org", "jeecgos@163.com")) | |
96 | -// .license("The Apache License, Version 2.0") | |
97 | -// .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") | |
109 | + .contact("JEECG团队") | |
110 | + .license("The Apache License, Version 2.0") | |
111 | + .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") | |
98 | 112 | .build(); |
99 | 113 | } |
100 | 114 | |
... | ... |