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 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;