diff --git a/src/main/java/com/thirdparty/ticketing/global/config/SecurityConfig.java b/src/main/java/com/thirdparty/ticketing/global/config/SecurityConfig.java index d32ddfc0..5ee5665a 100644 --- a/src/main/java/com/thirdparty/ticketing/global/config/SecurityConfig.java +++ b/src/main/java/com/thirdparty/ticketing/global/config/SecurityConfig.java @@ -14,8 +14,8 @@ import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; import com.thirdparty.ticketing.domain.member.MemberRole; import com.thirdparty.ticketing.domain.member.service.JwtProvider; @@ -55,18 +55,21 @@ public SecurityFilterChain filterChain(HttpSecurity http, JwtProvider jwtProvide .addFilterBefore( new AuthenticationFilter(jwtProvider), UsernamePasswordAuthenticationFilter.class) - .cors(cors -> cors.configurationSource(corsConfigurationSource())) .build(); } - private CorsConfigurationSource corsConfigurationSource() { - CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(List.of("http://localhost:8080")); - configuration.setAllowedMethods( - List.of("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")); + @Bean + public CorsFilter corsFilter() { + CorsConfiguration config = new CorsConfiguration(); + config.setAllowedOrigins(List.of("http://localhost:3000/")); + config.setAllowedMethods(List.of("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")); + config.setAllowCredentials(true); + config.setAllowedHeaders(List.of("*")); + config.setExposedHeaders(List.of("Authorization")); + config.setMaxAge(3600L); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/**", configuration); - return source; + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); } @Bean