26
26
import org .springframework .security .web .authentication .UsernamePasswordAuthenticationFilter ;
27
27
import org .springframework .web .cors .CorsConfiguration ;
28
28
29
+ import java .util .Arrays ;
29
30
import java .util .Collections ;
30
31
31
32
@ Configuration
@@ -60,9 +61,8 @@ public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws
60
61
// cors 필터
61
62
http
62
63
.cors (corsCustomizer -> corsCustomizer .configurationSource (request -> {
63
-
64
64
CorsConfiguration configuration = new CorsConfiguration ();
65
- configuration .setAllowedOrigins (Collections . singletonList ("http://localhost:3000" ));
65
+ configuration .setAllowedOrigins (Arrays . asList ("http://localhost:3000" , "http://localhost:8080 " ));
66
66
configuration .setAllowedMethods (Collections .singletonList ("*" ));
67
67
configuration .setAllowCredentials (true );
68
68
configuration .setAllowedHeaders (Collections .singletonList ("*" ));
@@ -90,6 +90,14 @@ public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws
90
90
.csrf (AbstractHttpConfigurer ::disable )
91
91
.formLogin (AbstractHttpConfigurer ::disable )
92
92
.httpBasic (AbstractHttpConfigurer ::disable );
93
+ // oauth2
94
+ http
95
+ .oauth2Login ((oauth2 ) -> oauth2
96
+ .userInfoEndpoint ((userInfo ) -> userInfo
97
+ .userService (customOAuth2MemberService ))
98
+ .successHandler (customSuccessHandler )
99
+ .failureHandler (customFailureHandler )
100
+ );
93
101
94
102
// 경로별 인가 작업
95
103
http
@@ -98,9 +106,11 @@ public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws
98
106
.requestMatchers ("/api/member/register" , "/api/member/login" ,
99
107
"/api/member/logout" ,"/api/member/find-user-id" ,
100
108
"/api/member/find-password" ).permitAll ()
109
+ .requestMatchers ("/api/member/oauth2/**" ).permitAll ()
101
110
.requestMatchers ("/api/member/admin" ).hasRole ("ADMIN" )
102
111
.requestMatchers ("/api/member/**" ).hasAnyRole ("USER" ,"ADMIN" )
103
112
.requestMatchers ("/api/address/**" ).permitAll ()
113
+ .requestMatchers ("/api/member-file-test" ).permitAll ()
104
114
// Swagger UI 관련 경로 허용
105
115
.requestMatchers ("/swagger-ui/**" ).permitAll ()
106
116
.requestMatchers ("/v3/api-docs/**" ).permitAll ()
@@ -116,24 +126,5 @@ public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws
116
126
.addFilterBefore (logoutFilter , JWTFilter .class );
117
127
return http .build ();
118
128
}
119
- @ Bean
120
- public SecurityFilterChain oauth2SecurityFilterChain (HttpSecurity http ) throws Exception {
121
- http
122
- .csrf (AbstractHttpConfigurer ::disable )
123
- .formLogin (AbstractHttpConfigurer ::disable )
124
- .httpBasic (AbstractHttpConfigurer ::disable )
125
- .authorizeHttpRequests ((auth ) -> auth
126
- .requestMatchers ("/oauth2/**" ).permitAll ()
127
- .anyRequest ().denyAll () // OAuth2 경로 외에는 이 체인에서 거부
128
- )
129
- .oauth2Login ((oauth2 ) -> oauth2
130
- .userInfoEndpoint ((userInfo ) -> userInfo
131
- .userService (customOAuth2MemberService ))
132
- .successHandler (customSuccessHandler )
133
- .failureHandler (customFailureHandler )
134
- );
135
-
136
- return http .build ();
137
- }
138
129
}
139
130
0 commit comments