2424import org .springframework .web .cors .CorsConfiguration ;
2525
2626import java .io .IOException ;
27+ import java .util .List ;
2728
2829@ Configuration
2930@ EnableWebSecurity
@@ -41,10 +42,15 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
4142 httpSecurity
4243 .cors (cors -> cors .configurationSource (request -> {
4344 CorsConfiguration configuration = new CorsConfiguration ();
44- configuration .addAllowedOrigin ("*" );
45- configuration .addAllowedMethod ("*" );
46- configuration .addAllowedHeader ("*" );
47- configuration .setAllowCredentials (true );
45+ // 명시적으로 허용할 Origin 설정
46+ configuration .setAllowedOrigins (List .of (
47+ "http://localhost:3000" ,
48+ "https://www.dgu1921.p-e.kr" ,
49+ "https://dgutestbed.netlify.app"
50+ ));
51+ configuration .setAllowedMethods (List .of ("GET" , "POST" , "PUT" , "DELETE" , "OPTIONS" ));
52+ configuration .setAllowedHeaders (List .of ("*" ));
53+ configuration .setAllowCredentials (true ); // Credentials 허용
4854 return configuration ;
4955 }))
5056 .csrf (csrf -> csrf .disable ()) // CSRF 비활성화
@@ -62,7 +68,6 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
6268 .authenticationEntryPoint (new AuthenticationEntryPoint () {
6369 @ Override
6470 public void commence (HttpServletRequest request , HttpServletResponse response , AuthenticationException authException ) throws IOException , ServletException {
65- // API에서 인증 실패 시 에러를 그대로 출력
6671 if (!request .getRequestURI ().contains ("api" )) {
6772 response .sendRedirect ("/jwt-login/authentication-fail" );
6873 } else {
@@ -85,3 +90,4 @@ public void handle(HttpServletRequest request, HttpServletResponse response, Acc
8590 return httpSecurity .build ();
8691 }
8792}
93+
0 commit comments