From 251f2b6f227ddc3b8eea8f74e8be286e25268ef9 Mon Sep 17 00:00:00 2001 From: Jo Kyung Hyeon Date: Thu, 8 Dec 2022 09:51:28 +0900 Subject: [PATCH] =?UTF-8?q?hotfix:=20Cors=20=EC=9E=AC=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simtong/global/security/SecurityConfig.kt | 19 +-------------- .../simtong/global/config/WebMvcConfig.kt | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 simtong-presentation/src/main/kotlin/team/comit/simtong/global/config/WebMvcConfig.kt diff --git a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/global/security/SecurityConfig.kt b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/global/security/SecurityConfig.kt index 78b4bda7..b2f72d60 100644 --- a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/global/security/SecurityConfig.kt +++ b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/global/security/SecurityConfig.kt @@ -9,9 +9,6 @@ import org.springframework.security.config.http.SessionCreationPolicy import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.security.web.SecurityFilterChain -import org.springframework.web.cors.CorsConfiguration -import org.springframework.web.cors.CorsConfigurationSource -import org.springframework.web.cors.UrlBasedCorsConfigurationSource import team.comit.simtong.domain.user.model.Authority.ROLE_ADMIN import team.comit.simtong.domain.user.model.Authority.ROLE_COMMON import team.comit.simtong.domain.user.model.Authority.ROLE_SUPER @@ -36,7 +33,7 @@ class SecurityConfig( @Bean protected fun securityFilterChain(http: HttpSecurity): SecurityFilterChain { http - .cors().configurationSource(corsConfiguration()).and() + .cors().and() .csrf().disable() .formLogin().disable() @@ -107,18 +104,4 @@ class SecurityConfig( @Bean protected fun PasswordEncoder(): PasswordEncoder = BCryptPasswordEncoder() - @Bean - protected fun corsConfiguration() : CorsConfigurationSource { - return UrlBasedCorsConfigurationSource().apply { - registerCorsConfiguration( - "/**", - CorsConfiguration().apply { - allowCredentials = true - allowedOriginPatterns = listOf("*") - allowedHeaders = listOf("*") - allowedMethods = listOf("*") - } - ) - } - } } \ No newline at end of file diff --git a/simtong-presentation/src/main/kotlin/team/comit/simtong/global/config/WebMvcConfig.kt b/simtong-presentation/src/main/kotlin/team/comit/simtong/global/config/WebMvcConfig.kt new file mode 100644 index 00000000..073042a6 --- /dev/null +++ b/simtong-presentation/src/main/kotlin/team/comit/simtong/global/config/WebMvcConfig.kt @@ -0,0 +1,23 @@ +package team.comit.simtong.global.config + +import org.springframework.context.annotation.Configuration +import org.springframework.web.servlet.config.annotation.CorsRegistry +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer + +/** + * + * Cors 관련 설정을 하는 WebMvcConfig + * + * @author Chokyunghyeon + * @date 2022/12/08 + * @version 1.0.0 + **/ +@Configuration +class WebMvcConfig : WebMvcConfigurer { + + override fun addCorsMappings(registry: CorsRegistry) { + registry.addMapping("/**") + .allowedMethods("*") + .allowedOriginPatterns("*") + } +} \ No newline at end of file