3
3
import codeview .main .auth .handler .OAuth2SuccessHandler ;
4
4
import codeview .main .auth .jwt .TokenAuthenticationFilter ;
5
5
import codeview .main .auth .jwt .TokenExceptionFilter ;
6
- import codeview .main .auth .jwt .TokenProvider ;
7
6
import codeview .main .auth .service .CustomOAuth2UserService ;
8
7
import lombok .RequiredArgsConstructor ;
9
8
import org .springframework .context .annotation .Bean ;
19
18
import org .springframework .security .web .authentication .UsernamePasswordAuthenticationFilter ;
20
19
import org .springframework .security .web .util .matcher .AntPathRequestMatcher ;
21
20
import org .springframework .web .cors .CorsConfiguration ;
21
+ import org .springframework .web .cors .CorsConfigurationSource ;
22
22
import org .springframework .web .cors .UrlBasedCorsConfigurationSource ;
23
- import org .springframework .web .filter .CorsFilter ;
24
23
25
24
import java .util .Arrays ;
26
25
@@ -32,7 +31,7 @@ public class SecurityConfig {
32
31
33
32
private final CustomOAuth2UserService customOAuth2UserService ;
34
33
private final TokenAuthenticationFilter tokenAuthenticationFilter ;
35
- private final TokenProvider tokenProvider ;
34
+ private final OAuth2SuccessHandler successHandler ;
36
35
37
36
@ Bean
38
37
public WebSecurityCustomizer webSecurityCustomizer () {
@@ -49,7 +48,6 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
49
48
.logout (AbstractHttpConfigurer ::disable )
50
49
.headers (c -> c .frameOptions (HeadersConfigurer .FrameOptionsConfig ::disable ).disable ())
51
50
.sessionManagement (c -> c .sessionCreationPolicy (SessionCreationPolicy .STATELESS ))
52
-
53
51
.authorizeHttpRequests (request -> request .requestMatchers (
54
52
new AntPathRequestMatcher ("/" ),
55
53
new AntPathRequestMatcher ("/home" ),
@@ -58,35 +56,21 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
58
56
new AntPathRequestMatcher ("/api/oauth2/**" )
59
57
).permitAll ()
60
58
.anyRequest ().authenticated ())
61
-
62
59
.oauth2Login (oauth -> oauth
63
60
.loginPage ("/login" )
64
- .successHandler (new OAuth2SuccessHandler ( tokenProvider ) )
61
+ .successHandler (successHandler )
65
62
.userInfoEndpoint (userInfo -> userInfo
66
63
.userService (customOAuth2UserService )))
67
64
.addFilterBefore (tokenAuthenticationFilter , UsernamePasswordAuthenticationFilter .class )
68
65
.addFilterBefore (new TokenExceptionFilter (), TokenAuthenticationFilter .class )
69
-
70
66
.exceptionHandling ((exceptions ) -> exceptions
71
67
.authenticationEntryPoint (new CustomAuthenticationEntryPoint ())
72
68
.accessDeniedHandler (new CustomAccessDeniedHandler ()));
73
69
return http .build ();
74
70
}
75
71
76
72
@ Bean
77
- public CorsFilter corsFilter () {
78
- UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource ();
79
- CorsConfiguration config = new CorsConfiguration ();
80
- config .setAllowCredentials (true );
81
- config .setAllowedOrigins (Arrays .asList ("http://localhost:3000" ));
82
- config .setAllowedMethods (Arrays .asList ("GET" , "POST" , "PUT" , "DELETE" ));
83
- config .setAllowedHeaders (Arrays .asList ("*" ));
84
- source .registerCorsConfiguration ("/**" , config );
85
- return new CorsFilter (source );
86
- }
87
-
88
- @ Bean
89
- public UrlBasedCorsConfigurationSource corsConfigurationSource () {
73
+ public CorsConfigurationSource corsConfigurationSource () {
90
74
CorsConfiguration config = new CorsConfiguration ();
91
75
config .setAllowCredentials (true );
92
76
config .setAllowedOrigins (Arrays .asList ("http://localhost:3000" ));
0 commit comments