1
1
package org .capstone .maru .security .config ;
2
2
3
3
4
+ import java .util .Collections ;
4
5
import lombok .extern .slf4j .Slf4j ;
5
6
import org .capstone .maru .security .service .CustomOAuth2UserService ;
6
7
import org .springframework .beans .factory .annotation .Qualifier ;
15
16
import org .springframework .security .web .AuthenticationEntryPoint ;
16
17
import org .springframework .security .web .SecurityFilterChain ;
17
18
import org .springframework .security .web .authentication .AuthenticationFailureHandler ;
19
+ import org .springframework .web .cors .CorsConfiguration ;
20
+ import org .springframework .web .cors .CorsConfigurationSource ;
18
21
19
22
@ Slf4j
20
23
@ Configuration
@@ -25,6 +28,18 @@ public class SecurityConfig {
25
28
26
29
private final AuthenticationFailureHandler authFailureHandler ;
27
30
31
+ CorsConfigurationSource corsConfigurationSource () {
32
+ return request -> {
33
+ CorsConfiguration config = new CorsConfiguration ();
34
+ config .setAllowedHeaders (Collections .singletonList ("*" ));
35
+ config .setAllowedMethods (Collections .singletonList ("*" ));
36
+ config .setAllowedOriginPatterns (
37
+ Collections .singletonList ("http://localhost:3000" )); // ⭐️ 허용할 origin
38
+ config .setAllowCredentials (true );
39
+ return config ;
40
+ };
41
+ }
42
+
28
43
public SecurityConfig (
29
44
@ Qualifier ("customAuthenticationEntryPoint" ) AuthenticationEntryPoint authEntryPoint ,
30
45
@ Qualifier ("customAuthenticationFailureHandler" ) AuthenticationFailureHandler authFailureHandler
@@ -37,7 +52,7 @@ public SecurityConfig(
37
52
@ ConditionalOnProperty (name = "spring.h2.console.enabled" , havingValue = "true" )
38
53
public WebSecurityCustomizer configureH2ConsoleEnable () {
39
54
return web -> web .ignoring ()
40
- .requestMatchers (PathRequest .toH2Console ());
55
+ .requestMatchers (PathRequest .toH2Console ());
41
56
}
42
57
43
58
@ Bean
0 commit comments