1
1
package org .flow .gateway .common .security ;
2
2
3
+ import java .util .Arrays ;
4
+
3
5
import org .springframework .context .annotation .Bean ;
4
6
import org .springframework .context .annotation .Configuration ;
5
7
import org .springframework .security .config .Customizer ;
6
8
import org .springframework .security .config .annotation .web .reactive .EnableWebFluxSecurity ;
7
9
import org .springframework .security .config .web .server .ServerHttpSecurity ;
8
10
import org .springframework .security .web .server .SecurityWebFilterChain ;
11
+ import org .springframework .web .cors .CorsConfiguration ;
12
+ import org .springframework .web .cors .reactive .CorsConfigurationSource ;
13
+ import org .springframework .web .cors .reactive .UrlBasedCorsConfigurationSource ;
9
14
10
15
@ Configuration
11
16
@ EnableWebFluxSecurity
@@ -14,7 +19,8 @@ public class SecurityConfig {
14
19
@ Bean
15
20
public SecurityWebFilterChain securityWebFilterChain (ServerHttpSecurity http ) {
16
21
http
17
- .csrf (ServerHttpSecurity .CsrfSpec ::disable )
22
+ .csrf (ServerHttpSecurity .CsrfSpec ::disable ) // CSRF 비활성화
23
+ .cors (corsSpec -> corsSpec .configurationSource (corsConfigurationSource ())) // CORS 설정 추가
18
24
.authorizeExchange (exchanges -> exchanges
19
25
.anyExchange ().permitAll ()
20
26
)
@@ -24,4 +30,17 @@ public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
24
30
return http .build ();
25
31
}
26
32
33
+ @ Bean
34
+ public CorsConfigurationSource corsConfigurationSource () {
35
+ CorsConfiguration corsConfig = new CorsConfiguration ();
36
+ corsConfig .setAllowedOrigins (Arrays .asList ("http://localhost:3000" , "http://your-other-allowed-origin.com" ));
37
+ corsConfig .setAllowedMethods (Arrays .asList ("GET" , "POST" , "PUT" , "DELETE" ));
38
+ corsConfig .setAllowedHeaders (Arrays .asList ("*" ));
39
+ corsConfig .setAllowCredentials (true );
40
+
41
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource ();
42
+ source .registerCorsConfiguration ("/**" , corsConfig );
43
+ return source ;
44
+ }
27
45
}
46
+
0 commit comments