From 2dcf07f5a5d063196f0f2afce99141f5b7bf2d89 Mon Sep 17 00:00:00 2001 From: Kang Duoh Date: Thu, 21 Nov 2024 12:54:13 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Test[#10]:=20Swagger=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../groom/swipo/global/config/SecurityConfig.java | 3 +-- .../com/groom/swipo/global/config/SwaggerConfig.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/groom/swipo/global/config/SecurityConfig.java b/src/main/java/com/groom/swipo/global/config/SecurityConfig.java index 4e40fbe..cb5d3b3 100644 --- a/src/main/java/com/groom/swipo/global/config/SecurityConfig.java +++ b/src/main/java/com/groom/swipo/global/config/SecurityConfig.java @@ -24,8 +24,7 @@ public class SecurityConfig { "swagger-ui/**", "v3/api-docs/**", "/v1/**", - "/profile", - "/**" // 테스트용 + "/profile" }; @Bean diff --git a/src/main/java/com/groom/swipo/global/config/SwaggerConfig.java b/src/main/java/com/groom/swipo/global/config/SwaggerConfig.java index 064ea1c..0e05407 100644 --- a/src/main/java/com/groom/swipo/global/config/SwaggerConfig.java +++ b/src/main/java/com/groom/swipo/global/config/SwaggerConfig.java @@ -6,8 +6,11 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; 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; @Configuration @@ -28,6 +31,8 @@ private Info apiInfo() { @Bean public OpenAPI openAPI() { + String authHeader = "Authorization"; + Server localServer = new Server(); localServer.description("Local Server") .url(localUrl); @@ -38,6 +43,13 @@ public OpenAPI openAPI() { return new OpenAPI() .info(apiInfo()) + .addSecurityItem(new SecurityRequirement().addList(authHeader)) + .components(new Components() + .addSecuritySchemes(authHeader, new SecurityScheme() + .name(authHeader) + .type(SecurityScheme.Type.HTTP) + .scheme("Bearer") + .bearerFormat("accessToken"))) .servers(Arrays.asList(localServer, prodServer)); } }