diff --git a/src/main/java/com/gamegoo/config/SecurityConfig.java b/src/main/java/com/gamegoo/config/SecurityConfig.java index 5efc0c01..2c44e2b8 100644 --- a/src/main/java/com/gamegoo/config/SecurityConfig.java +++ b/src/main/java/com/gamegoo/config/SecurityConfig.java @@ -18,10 +18,15 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; import java.util.Arrays; import java.util.List; +import static org.springframework.security.config.Customizer.withDefaults; + @Configuration @EnableWebSecurity @RequiredArgsConstructor @@ -55,7 +60,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .csrf(AbstractHttpConfigurer::disable) .formLogin(AbstractHttpConfigurer::disable) .httpBasic(AbstractHttpConfigurer::disable) - + .cors(withDefaults()) .authorizeHttpRequests((auth) -> auth .antMatchers("/", "/api/member/join", "/api/member/login", "/api/member/email/**", "/api/member/refresh", "/api/member/riot").permitAll() @@ -69,4 +74,16 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http.build(); } + + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + config.addAllowedOrigin("http://localhost:3000"); + config.addAllowedHeader("*"); + config.addAllowedMethod("*"); + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); + } }