88import lombok .RequiredArgsConstructor ;
99import org .springframework .context .annotation .Bean ;
1010import org .springframework .context .annotation .Configuration ;
11+ import org .springframework .http .HttpMethod ;
12+ import org .springframework .security .config .Customizer ;
1113import org .springframework .security .config .annotation .method .configuration .EnableMethodSecurity ;
1214import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
1315import org .springframework .security .config .annotation .web .configurers .AbstractHttpConfigurer ;
@@ -35,6 +37,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
3537 // 인가 규칙 설정
3638 .authorizeHttpRequests (
3739 auth -> auth
40+ .requestMatchers (HttpMethod .OPTIONS , "/**" ).permitAll () // CORS Preflight 요청 허용
3841 .requestMatchers ("/api/auth/**" , "/oauth2/**" , "/login/oauth2/**" ).permitAll ()
3942 .requestMatchers ("api/ws/**" , "/ws/**" ).permitAll ()
4043 .requestMatchers ("/api/rooms/*/messages/**" ).permitAll () //스터디 룸 내에 잡혀있어 있는 채팅 관련 전체 허용
@@ -59,7 +62,6 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
5962 // JWT 필터 추가
6063 .addFilterBefore (jwtAuthenticationFilter , UsernamePasswordAuthenticationFilter .class )
6164
62- // 기타 설정
6365 .headers (
6466 headers -> headers
6567 .frameOptions (
@@ -68,6 +70,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
6870 )
6971 .csrf (
7072 AbstractHttpConfigurer ::disable
73+ )
74+ .cors (
75+ Customizer .withDefaults ()
7176 );
7277
7378 return http .build ();
@@ -82,7 +87,7 @@ public void addCorsMappings(CorsRegistry registry) {
8287 .allowedOrigins (
8388 "http://localhost:3000" // Next.js 개발 서버
8489 )
85- .allowedMethods ("GET" , "POST" , "PUT" , "DELETE" )
90+ .allowedMethods ("GET" , "POST" , "PUT" , "DELETE" , "PATCH" , "OPTIONS" )
8691 .allowedHeaders ("*" )
8792 .allowCredentials (true );
8893 }
0 commit comments