-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: springdoc 의존성 추가 * feat: 스웨거 전역 헤더 설정 추가 * feat: 스웨거 URL 상수 추가 * feat: 스웨거 프로퍼티 추가 * feat: 스웨거가 운영환경에 맞는 서버 url로 요청하도록 설정 * feat: 개발 및 운영환경에서의 스웨거 Basic 인증 추가 * refactor: 불린 원시 타입을 사용하도록 개선 * chore: 스웨거 계정정보 수정 * feat: 리다이렉트 수정 테스트 * feat: 스웨거 전용 filterChain 추가 * feat: 개발서버 쿠키 설정을 위해 클라이언트 https 도메인 추가 * refactor: `@ConditionalOnProperty` 를 사용하도록 개선 * feat: 스웨거 전용 헤더 로직 추가 * refactor: 상수 이름 수정
- Loading branch information
Showing
13 changed files
with
193 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/gdschongik/gdsc/global/common/constant/SwaggerUrlConstant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.gdschongik.gdsc.global.common.constant; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum SwaggerUrlConstant { | ||
SWAGGER_RESOURCES_URL("/swagger-resources/**"), | ||
SWAGGER_UI_URL("/swagger-ui/**"), | ||
SWAGGER_API_DOCS_URL("/v3/api-docs/**"), | ||
; | ||
|
||
private final String value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/gdschongik/gdsc/global/config/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.gdschongik.gdsc.global.config; | ||
|
||
import static com.gdschongik.gdsc.global.common.constant.EnvironmentConstant.*; | ||
import static com.gdschongik.gdsc.global.common.constant.UrlConstant.*; | ||
import static org.springframework.http.HttpHeaders.*; | ||
|
||
import com.gdschongik.gdsc.global.util.EnvironmentUtil; | ||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
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.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class SwaggerConfig { | ||
|
||
private final EnvironmentUtil environmentUtil; | ||
|
||
@Bean | ||
public OpenAPI openAPI() { | ||
return new OpenAPI() | ||
.servers(swaggerServers()) | ||
.addSecurityItem(securityRequirement()) | ||
.components(authSetting()); | ||
} | ||
|
||
private List<Server> swaggerServers() { | ||
Server server = new Server().url(getServerUrl()); | ||
return List.of(server); | ||
} | ||
|
||
private String getServerUrl() { | ||
return switch (environmentUtil.getCurrentProfile()) { | ||
case PROD -> PROD_SERVER_URL; | ||
case DEV -> DEV_SERVER_URL; | ||
default -> LOCAL_SERVER_URL; | ||
}; | ||
} | ||
|
||
private Components authSetting() { | ||
return new Components() | ||
.addSecuritySchemes( | ||
"Authorization", | ||
new SecurityScheme() | ||
.type(SecurityScheme.Type.HTTP) | ||
.scheme("bearer") | ||
.bearerFormat("JWT") | ||
.in(SecurityScheme.In.HEADER) | ||
.name(AUTHORIZATION)); | ||
} | ||
|
||
private SecurityRequirement securityRequirement() { | ||
return new SecurityRequirement().addList(AUTHORIZATION); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/gdschongik/gdsc/global/property/SwaggerProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.gdschongik.gdsc.global.property; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@ConfigurationProperties(prefix = "swagger") | ||
public class SwaggerProperty { | ||
|
||
private final String username; | ||
private final String password; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
spring: | ||
config: | ||
activate: | ||
on-profile: "security" | ||
|
||
swagger: | ||
username: ${SWAGGER_USER:default} | ||
password: ${SWAGGER_PASSWORD:default} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ spring: | |
- redis | ||
- storage | ||
- security | ||
- swagger | ||
|
||
logging: | ||
level: | ||
|