Commit 0bdcae6af6f210eade489453b26c9abfc5691fbd
1 parent
3d786a36
Merge branch 'master' of
http://daeuServer.iptime.org/grp_cna/auth_jwt_api.git
Showing
1 changed file
with
28 additions
and
3 deletions
Show diff stats
src/main/java/daeucna/Security/config/SwaggerConfig.java
| 1 | 1 | package daeucna.Security.config; |
| 2 | 2 | |
| 3 | +import java.util.List; | |
| 4 | + | |
| 3 | 5 | import org.springframework.context.annotation.Bean; |
| 4 | 6 | import org.springframework.context.annotation.Configuration; |
| 5 | 7 | |
| ... | ... | @@ -7,12 +9,14 @@ import springfox.documentation.builders.ApiInfoBuilder; |
| 7 | 9 | import springfox.documentation.builders.PathSelectors; |
| 8 | 10 | import springfox.documentation.builders.RequestHandlerSelectors; |
| 9 | 11 | import springfox.documentation.service.ApiInfo; |
| 12 | +import springfox.documentation.service.ApiKey; | |
| 13 | +import springfox.documentation.service.AuthorizationScope; | |
| 14 | +import springfox.documentation.service.SecurityReference; | |
| 10 | 15 | import springfox.documentation.spi.DocumentationType; |
| 16 | +import springfox.documentation.spi.service.contexts.SecurityContext; | |
| 11 | 17 | import springfox.documentation.spring.web.plugins.Docket; |
| 12 | -import springfox.documentation.swagger2.annotations.EnableSwagger2; | |
| 13 | 18 | |
| 14 | 19 | @Configuration |
| 15 | -@EnableSwagger2 | |
| 16 | 20 | public class SwaggerConfig { |
| 17 | 21 | |
| 18 | 22 | @Bean |
| ... | ... | @@ -24,9 +28,30 @@ public class SwaggerConfig { |
| 24 | 28 | .apis(RequestHandlerSelectors.basePackage("daeucna.Security.web.controller")) |
| 25 | 29 | .paths(PathSelectors.any()) |
| 26 | 30 | .build() |
| 27 | - .apiInfo(apiInfo()); | |
| 31 | + .apiInfo(apiInfo()) | |
| 32 | + .securityContexts(List.of(this.securityContext())) // SecurityContext 설정 | |
| 33 | + .securitySchemes(List.of(this.apiKey())); // ApiKey 설정 | |
| 28 | 34 | } |
| 29 | 35 | |
| 36 | + // JWT SecurityContext 구성 | |
| 37 | + private SecurityContext securityContext() { | |
| 38 | + return SecurityContext.builder() | |
| 39 | + .securityReferences(defaultAuth()) | |
| 40 | + .build(); | |
| 41 | + } | |
| 42 | + | |
| 43 | + private List<SecurityReference> defaultAuth() { | |
| 44 | + AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); | |
| 45 | + AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; | |
| 46 | + authorizationScopes[0] = authorizationScope; | |
| 47 | + return List.of(new SecurityReference("X-AUTH-TOKEN", authorizationScopes)); | |
| 48 | + } | |
| 49 | + | |
| 50 | + // ApiKey 정의 | |
| 51 | + private ApiKey apiKey() { | |
| 52 | + return new ApiKey("X-AUTH-TOKEN", "JWT", "header"); | |
| 53 | + } | |
| 54 | + | |
| 30 | 55 | private ApiInfo apiInfo() { |
| 31 | 56 | return new ApiInfoBuilder() |
| 32 | 57 | .title("Swagger Test") | ... | ... |