From e1d5d3fea80cb48e8be2a35a1d6a34de836fd0d0 Mon Sep 17 00:00:00 2001 From: Kim Yongbin <80311590+yongbin97@users.noreply.github.com> Date: Fri, 4 Oct 2024 00:52:25 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]=20Config=20=EC=88=98=EC=A0=95=20(#46)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 게시물 api url 대응 (#45) * fix: swagger config (#44) --- build.gradle | 4 ++-- .../backend/common/config/SecurityConfig.java | 6 +++--- .../backend/common/config/SwaggerConfig.java | 13 ++++++++++++- .../project/backend/security/jwt/JwtFilter.java | 6 +++--- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index aef4a43..ac8c824 100644 --- a/build.gradle +++ b/build.gradle @@ -44,9 +44,9 @@ dependencies { implementation 'org.springframework.ai:spring-ai-vertex-ai-gemini-spring-boot-starter:1.0.0-SNAPSHOT' // Swagger - implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0' - implementation group: 'org.json', name: 'json', version: '20090211' + implementation group: 'org.json', name: 'json', version: '20231013' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' diff --git a/src/main/java/project/backend/common/config/SecurityConfig.java b/src/main/java/project/backend/common/config/SecurityConfig.java index d2f6e42..2b3e886 100644 --- a/src/main/java/project/backend/common/config/SecurityConfig.java +++ b/src/main/java/project/backend/common/config/SecurityConfig.java @@ -50,9 +50,9 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .requestMatchers("/exception/**").permitAll() .requestMatchers("/swagger-ui/**").permitAll() .requestMatchers("/api-docs/**").permitAll() - .requestMatchers(HttpMethod.POST, "/post").permitAll() - .requestMatchers(HttpMethod.GET, "/post/*").permitAll() - .requestMatchers(HttpMethod.PATCH, "/post/*/summary").permitAll() + .requestMatchers(HttpMethod.POST, "/posts").permitAll() + .requestMatchers(HttpMethod.GET, "/posts/*").permitAll() + .requestMatchers(HttpMethod.PATCH, "/posts/*/summary").permitAll() .anyRequest().authenticated() ) .addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class) diff --git a/src/main/java/project/backend/common/config/SwaggerConfig.java b/src/main/java/project/backend/common/config/SwaggerConfig.java index b4c9095..9b61700 100644 --- a/src/main/java/project/backend/common/config/SwaggerConfig.java +++ b/src/main/java/project/backend/common/config/SwaggerConfig.java @@ -9,9 +9,11 @@ import java.util.List; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration -public class SwaggerConfig { +public class SwaggerConfig implements WebMvcConfigurer { private static final String BEARER_TOKEN_PREFIX = "Bearer"; @@ -45,4 +47,13 @@ private Info apiInfo() { .description("스위프 6기 5팀 API") // API에 대한 설명 .version("1.0.0"); // API의 버전 } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("swagger-ui.html") + .addResourceLocations("classpath:/META-INF/resources/"); + + registry.addResourceHandler("/webjars/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/"); + } } \ No newline at end of file diff --git a/src/main/java/project/backend/security/jwt/JwtFilter.java b/src/main/java/project/backend/security/jwt/JwtFilter.java index c737e3d..d6b9a7c 100644 --- a/src/main/java/project/backend/security/jwt/JwtFilter.java +++ b/src/main/java/project/backend/security/jwt/JwtFilter.java @@ -84,12 +84,12 @@ private void setErrorResponse(HttpServletResponse response) throws IOException { private static boolean isRequestSummaryURI(HttpServletRequest request) { // 요약하기 - if (request.getRequestURI().equals("/post") && request.getMethod() - .equals(HttpMethod.POST.name())) { + if (request.getRequestURI().equals("/posts") && request.getMethod() + .equals(HttpMethod.POST.name())) { return true; } // 재요약하기 - if (request.getRequestURI().matches("/post/[0-9]+/summary") && request.getMethod().equals( + if (request.getRequestURI().matches("/posts/[0-9]+/summary") && request.getMethod().equals( HttpMethod.PATCH.name())) { return true; }