diff --git a/src/main/java/team05/integrated_feed_backend/core/config/SecurityConfig.java b/src/main/java/team05/integrated_feed_backend/core/config/SecurityConfig.java index c032243..747a305 100644 --- a/src/main/java/team05/integrated_feed_backend/core/config/SecurityConfig.java +++ b/src/main/java/team05/integrated_feed_backend/core/config/SecurityConfig.java @@ -3,11 +3,14 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import team05.integrated_feed_backend.module.auth.jwt.JwtUtil; @@ -38,15 +41,24 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // 세션 사용X .authorizeHttpRequests(authorize -> authorize .requestMatchers("/auth/**").permitAll() // 인증 없이 접근할 수 있는 경로 설정하기 (회원가입, 로그인 등) - .anyRequest().authenticated() // 그 외의 모든 요청은 인증필요 + .anyRequest().authenticated() // 그 외의 모든 요청 인증 필요 ) - .addFilterBefore(new JwtAuthenticationFilter(jwtUtil, userDetailsService), UsernamePasswordAuthenticationFilter.class); // JWT 필터 추가 + .addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); // JWT 필터 추가 return http.build(); } @Bean - public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception { - return authenticationConfiguration.getAuthenticationManager(); + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + @Bean + public AuthenticationManager authenticationManager(HttpSecurity http) throws Exception { + AuthenticationManagerBuilder authManagerBuilder = http.getSharedObject(AuthenticationManagerBuilder.class); + authManagerBuilder + .userDetailsService(userDetailsService) + .passwordEncoder(passwordEncoder()); + return authManagerBuilder.build(); } }