From 1e8dc11ca78129963620124e0befe6552b8f9983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=96=91=EC=A7=80=EC=9B=90?= Date: Wed, 17 Jul 2024 20:12:20 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Refactor:=20swagger=EC=97=90=EC=84=9C=20htt?= =?UTF-8?q?ps,=20http,=20local=20=ED=85=8C=EC=8A=A4=ED=8A=B8=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/global/config/CorsConfig.java | 19 +++++++++++++++++++ .../api/global/config/SwaggerConfig.java | 11 +++++++++-- .../api/global/config/WebSecurityConfig.java | 8 +++++++- 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/travelcompass/api/global/config/CorsConfig.java diff --git a/src/main/java/com/travelcompass/api/global/config/CorsConfig.java b/src/main/java/com/travelcompass/api/global/config/CorsConfig.java new file mode 100644 index 0000000..7916160 --- /dev/null +++ b/src/main/java/com/travelcompass/api/global/config/CorsConfig.java @@ -0,0 +1,19 @@ +package com.travelcompass.api.global.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +@EnableWebMvc +public class CorsConfig implements WebMvcConfigurer { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("http://localhost:3000", "http://localhost:8080", "https://travel-compass.netlify.app", "http://travel-compass.netlify.app", "https://travel-compass.persi0815.site", "http://travel-compass.persi0815.site") + .allowedMethods("*") + .allowCredentials(true) + .maxAge(3600); + } +} diff --git a/src/main/java/com/travelcompass/api/global/config/SwaggerConfig.java b/src/main/java/com/travelcompass/api/global/config/SwaggerConfig.java index 53d7199..65a27ae 100644 --- a/src/main/java/com/travelcompass/api/global/config/SwaggerConfig.java +++ b/src/main/java/com/travelcompass/api/global/config/SwaggerConfig.java @@ -1,5 +1,7 @@ package com.travelcompass.api.global.config; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.servers.Server; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; @@ -8,9 +10,14 @@ import org.springdoc.core.models.GroupedOpenApi; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +@OpenAPIDefinition( + servers = { + @Server(url = "https://travel-compass.persi0815.site", description = "umc https 서버입니다."), + @Server(url = "http://travel-compass.persi0815.site", description = "umc http 서버입니다."), + @Server(url = "http://localhost:8080", description = "umc local 서버입니다.") + } +) @Configuration public class SwaggerConfig { @Bean diff --git a/src/main/java/com/travelcompass/api/global/config/WebSecurityConfig.java b/src/main/java/com/travelcompass/api/global/config/WebSecurityConfig.java index 83da985..e32fa75 100644 --- a/src/main/java/com/travelcompass/api/global/config/WebSecurityConfig.java +++ b/src/main/java/com/travelcompass/api/global/config/WebSecurityConfig.java @@ -76,13 +76,19 @@ protected SecurityFilterChain securityFilterChain( return http.build(); } + /* @Bean CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000", "http://localhost:8080", "https://travel-compass.netlify.app", "http://travel-compass.netlify.app", "https://travel-compass.persi0815.site", "http://travel-compass.persi0815.site")); + configuration.setAllowedOriginPatterns(Arrays.asList("http://localhost:3000", "http://localhost:8080", "https://travel-compass.netlify.app", "http://travel-compass.netlify.app", "https://travel-compass.persi0815.site", "http://travel-compass.persi0815.site")); configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS")); + configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type")); + configuration.setAllowCredentials(true); + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); return source; } + + */ } \ No newline at end of file From 6051a59d684a56b8369417b6428c203d3a59b5b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=96=91=EC=A7=80=EC=9B=90?= Date: Wed, 17 Jul 2024 20:13:54 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Refactor:=20passwordEncoder=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/oauth/service/JpaUserDetailsManager.java | 6 +----- .../com/travelcompass/api/oauth/service/UserService.java | 3 --- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main/java/com/travelcompass/api/oauth/service/JpaUserDetailsManager.java b/src/main/java/com/travelcompass/api/oauth/service/JpaUserDetailsManager.java index e304be8..d53f8e6 100644 --- a/src/main/java/com/travelcompass/api/oauth/service/JpaUserDetailsManager.java +++ b/src/main/java/com/travelcompass/api/oauth/service/JpaUserDetailsManager.java @@ -9,13 +9,10 @@ import org.springframework.http.HttpStatus; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.provisioning.UserDetailsManager; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; -import java.util.Optional; - @Slf4j @Service public class JpaUserDetailsManager implements UserDetailsManager { @@ -23,8 +20,7 @@ public class JpaUserDetailsManager implements UserDetailsManager { private final UserRepository userRepository; public JpaUserDetailsManager( - UserRepository userRepository, - PasswordEncoder passwordEncoder + UserRepository userRepository ) { this.userRepository = userRepository; } diff --git a/src/main/java/com/travelcompass/api/oauth/service/UserService.java b/src/main/java/com/travelcompass/api/oauth/service/UserService.java index af03e7d..c4035d8 100644 --- a/src/main/java/com/travelcompass/api/oauth/service/UserService.java +++ b/src/main/java/com/travelcompass/api/oauth/service/UserService.java @@ -13,7 +13,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; @Service @@ -22,8 +21,6 @@ public class UserService { private final UserRepository userRepository; private final RefreshTokenRepository refreshTokenRepository; - - private final PasswordEncoder passwordEncoder; private final JpaUserDetailsManager manager; private final JwtTokenUtils jwtTokenUtils;