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 | package daeucna.Security.config; | 1 | package daeucna.Security.config; |
2 | 2 | ||
3 | +import java.util.List; | ||
4 | + | ||
3 | import org.springframework.context.annotation.Bean; | 5 | import org.springframework.context.annotation.Bean; |
4 | import org.springframework.context.annotation.Configuration; | 6 | import org.springframework.context.annotation.Configuration; |
5 | 7 | ||
@@ -7,12 +9,14 @@ import springfox.documentation.builders.ApiInfoBuilder; | @@ -7,12 +9,14 @@ import springfox.documentation.builders.ApiInfoBuilder; | ||
7 | import springfox.documentation.builders.PathSelectors; | 9 | import springfox.documentation.builders.PathSelectors; |
8 | import springfox.documentation.builders.RequestHandlerSelectors; | 10 | import springfox.documentation.builders.RequestHandlerSelectors; |
9 | import springfox.documentation.service.ApiInfo; | 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 | import springfox.documentation.spi.DocumentationType; | 15 | import springfox.documentation.spi.DocumentationType; |
16 | +import springfox.documentation.spi.service.contexts.SecurityContext; | ||
11 | import springfox.documentation.spring.web.plugins.Docket; | 17 | import springfox.documentation.spring.web.plugins.Docket; |
12 | -import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
13 | 18 | ||
14 | @Configuration | 19 | @Configuration |
15 | -@EnableSwagger2 | ||
16 | public class SwaggerConfig { | 20 | public class SwaggerConfig { |
17 | 21 | ||
18 | @Bean | 22 | @Bean |
@@ -24,9 +28,30 @@ public class SwaggerConfig { | @@ -24,9 +28,30 @@ public class SwaggerConfig { | ||
24 | .apis(RequestHandlerSelectors.basePackage("daeucna.Security.web.controller")) | 28 | .apis(RequestHandlerSelectors.basePackage("daeucna.Security.web.controller")) |
25 | .paths(PathSelectors.any()) | 29 | .paths(PathSelectors.any()) |
26 | .build() | 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 | private ApiInfo apiInfo() { | 55 | private ApiInfo apiInfo() { |
31 | return new ApiInfoBuilder() | 56 | return new ApiInfoBuilder() |
32 | .title("Swagger Test") | 57 | .title("Swagger Test") |