33import com .swunitzel .fiterview .jwt .JWTFilter ;
44import com .swunitzel .fiterview .jwt .JWTUtil ;
55import com .swunitzel .fiterview .jwt .LoginFilter ;
6+ import com .swunitzel .fiterview .oauth .CustomOAuth2UserService ;
7+ import com .swunitzel .fiterview .oauth .OAuth2LoginFailureHandler ;
8+ import com .swunitzel .fiterview .oauth .OAuth2SuccessHandler ;
69import com .swunitzel .fiterview .repository .UserRepository ;
710import jakarta .servlet .http .HttpServletRequest ;
11+ import lombok .RequiredArgsConstructor ;
812import org .springframework .context .annotation .Bean ;
913import org .springframework .context .annotation .Configuration ;
1014import org .springframework .security .authentication .AuthenticationManager ;
2327
2428@ Configuration
2529@ EnableWebSecurity
30+ @ RequiredArgsConstructor
2631public class SecurityConfig {
2732
2833 private final AuthenticationConfiguration authenticationConfiguration ;
2934 private final JWTUtil jwtUtil ;
3035 private final UserRepository userRepository ;
31-
32- public SecurityConfig (AuthenticationConfiguration authenticationConfiguration , JWTUtil jwtUtil , UserRepository userRepository ) {
33- this .authenticationConfiguration = authenticationConfiguration ;
34- this .jwtUtil = jwtUtil ;
35- this .userRepository = userRepository ;
36- }
36+ private final CustomOAuth2UserService customOAuth2UserService ;
37+ private final OAuth2LoginFailureHandler oAuth2LoginFailureHandler ;
38+ private final OAuth2SuccessHandler oAuth2SuccessHandler ;
3739
3840 //AuthenticationManager Bean 등록
3941 @ Bean
@@ -42,12 +44,6 @@ public AuthenticationManager authenticationManager(AuthenticationConfiguration c
4244 return configuration .getAuthenticationManager ();
4345 }
4446
45- @ Bean
46- public BCryptPasswordEncoder bCryptPasswordEncoder () {
47-
48- return new BCryptPasswordEncoder ();
49- }
50-
5147
5248 @ Bean
5349 public SecurityFilterChain filterChain (HttpSecurity http ) throws Exception {
@@ -91,8 +87,19 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
9187 //경로별 인가 작업
9288 http
9389 .authorizeHttpRequests ((auth ) -> auth
94- .requestMatchers ("/api/user/login" , "/" , "/api/user/join" , "/api/user/reissue" ).permitAll ()
95- .anyRequest ().authenticated ());
90+ .requestMatchers ("/login/**" , "/" , "/api/user/join" , "/api/user/reissue" ,
91+ "/oauth/login/kakao/**" , "/api/user/auth/**"
92+ // , "/oauth2"
93+ ).permitAll ()
94+
95+ .anyRequest ().authenticated ())
96+ .oauth2Login (oauth ->
97+ oauth
98+ // .loginPage("/oauth2/authorization/kakao")
99+ .userInfoEndpoint (c -> c .userService (customOAuth2UserService ))
100+ .successHandler (oAuth2SuccessHandler )
101+ .failureHandler (oAuth2LoginFailureHandler )
102+ );
96103
97104 // 필터 추가
98105 http
0 commit comments