From 6734c059495a5541c78b7ddddf82945a09f3c6dd Mon Sep 17 00:00:00 2001 From: limju Date: Tue, 28 Nov 2023 16:50:29 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20SpringDocsConfig=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=B6=94=EA=B0=80=20=20=20=20=20=20-=20ht?= =?UTF-8?q?tp,=20https=20=EC=84=9C=EB=B2=84=20=20=20=20=20=20Cors=20yml=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/config/application-local.yml | 10 +++++----- .../resources/config/application-local.yml | 4 ---- .../resources/config/application-local.yml | 4 ---- .../core/spring/config/SpringDocsConfig.java | 18 +++++++++++++++--- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/mens-admin/src/main/resources/config/application-local.yml b/mens-admin/src/main/resources/config/application-local.yml index b018e7b..59526d8 100644 --- a/mens-admin/src/main/resources/config/application-local.yml +++ b/mens-admin/src/main/resources/config/application-local.yml @@ -47,10 +47,6 @@ logging: path: ${app.data.root.path}/mens/logs name: ${app.name} -# Spring Security cors 설정 :: CorsConfiguration 설정 값 -cors: - allowed-origins: http://localhost:8080, http://${app.api-ip}:8080, http://localhost:8082, http://${app.api-ip}:8082 - # ================================================================================================================== # SQL logging lib setting # ================================================================================================================== @@ -65,7 +61,11 @@ app: #swagger-url: 'http://localhost:${server.port}${server.servlet.context-path:}/' # Spring Security cors 설정 :: CorsConfiguration 설정 값 cors: - allowed-origins: http://localhost:8080, http://${app.api-ip}:8080, http://localhost:8082, http://${app.api-ip}:8082 + allowed-origins: + http://localhost:${server.http}, + http://${app.api-ip}:${server.http}, + https://localhost:${server.port}, + https://${app.api-ip}:${server.port} data: root: diff --git a/mens-api/src/main/resources/config/application-local.yml b/mens-api/src/main/resources/config/application-local.yml index 8852d94..73ff0d4 100644 --- a/mens-api/src/main/resources/config/application-local.yml +++ b/mens-api/src/main/resources/config/application-local.yml @@ -44,10 +44,6 @@ logging: path: ${app.data.root.path}/mens/logs name: ${app.name} -# Spring Security cors 설정 :: CorsConfiguration 설정 값 -cors: - allowed-origins: http://localhost:8080, http://${app.api-ip}:8080, http://localhost:8082, http://${app.api-ip}:8082 - # ================================================================================================================== # SQL logging lib setting # ================================================================================================================== diff --git a/mens-batch/src/main/resources/config/application-local.yml b/mens-batch/src/main/resources/config/application-local.yml index e9ed7ab..a29d698 100644 --- a/mens-batch/src/main/resources/config/application-local.yml +++ b/mens-batch/src/main/resources/config/application-local.yml @@ -56,10 +56,6 @@ logging: path: ${app.data.root.path}/mens/logs name: ${app.name} -# Spring Security cors 설정 :: CorsConfiguration 설정 값 -cors: - allowed-origins: http://localhost:8080 - # ================================================================================================================== # SQL logging lib setting # ================================================================================================================== diff --git a/mens-core/src/main/java/kr/xit/core/spring/config/SpringDocsConfig.java b/mens-core/src/main/java/kr/xit/core/spring/config/SpringDocsConfig.java index e5cf1a6..c23cae5 100644 --- a/mens-core/src/main/java/kr/xit/core/spring/config/SpringDocsConfig.java +++ b/mens-core/src/main/java/kr/xit/core/spring/config/SpringDocsConfig.java @@ -7,6 +7,7 @@ import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; import io.swagger.v3.oas.models.servers.Server; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import kr.xit.core.support.utils.Checks; @@ -36,7 +37,7 @@ import org.springframework.context.annotation.Configuration; @Configuration public class SpringDocsConfig { @Value("${server.port}") - private int SSL_PORT; + private int SERVER_PORT; @Value("${server.http:0}") private int HTTP_PORT; @Value("${app.swagger-url:}") @@ -58,8 +59,17 @@ public class SpringDocsConfig { .email("admin@xit.co.kr")); //.url("http://www.xerotech.co.kr/")); - String url = Checks.isNotEmpty(swaggerUrl)? swaggerUrl : String.format("http://localhost:%d", HTTP_PORT != 0? HTTP_PORT: SSL_PORT); - List servers = Collections.singletonList(new Server().url(url).description(name + "(" + active + ")")); + // https enabled + List servers = new ArrayList<>(); + if(HTTP_PORT != 0){ + String httpsUrl = Checks.isNotEmpty(swaggerUrl)? swaggerUrl : String.format("https://localhost:%d", SERVER_PORT); + String httpUrl = Checks.isNotEmpty(swaggerUrl)? swaggerUrl : String.format("http://localhost:%d", HTTP_PORT); + servers.add(new Server().url(httpsUrl).description(name + "(" + active + ")")); + servers.add(new Server().url(httpUrl).description(name + "(" + active + ")")); + }else { + String httpUrl = Checks.isNotEmpty(swaggerUrl)? swaggerUrl : String.format("http://localhost:%d", SERVER_PORT); + servers.add(new Server().url(httpUrl).description(name + "(" + active + ")")); + } // Security 스키마 설정 SecurityScheme securityScheme = new SecurityScheme() @@ -69,11 +79,13 @@ public class SpringDocsConfig { .in(SecurityScheme.In.HEADER) // .name(HttpHeaders.AUTHORIZATION); .name("Authorization"); + SecurityRequirement securityRequirement = new SecurityRequirement().addList("bearerAuth"); return new OpenAPI() // Security 인증 컴포넌트 설정 .components(new Components().addSecuritySchemes("bearerAuth", securityScheme)) + .components(new Components().addSecuritySchemes("bearerAuth", securityScheme)) // API 마다 Security 인증 컴포넌트 설정 //.addSecurityItem(new SecurityRequirement().addList("JWT")) .security(Collections.singletonList(securityRequirement))