Skip to content

Commit fb0e75f

Browse files
committed
feat(SecurityConfig): IdPwAuthFilter 추가 및 의존성 처리 개선
- authenticationManager Bean 명시적 처리 - passwordEncoder Bean 추가 - idPwAuthFilter의 필터 경로 설정 및 SecurityConfig에서 생성 후 사용 - idPwAuthFilter 의존성 주입 처리 - authenticationManager와의 순환 참조 문제 해결을 위해 idPwAuthFilter를 Component로 관리하지 않고 SecurityConfig에서 직접 생성
1 parent 9704394 commit fb0e75f

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/main/java/com/somemore/global/configure/SecurityConfig.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
package com.somemore.global.configure;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.somemore.auth.cookie.CookieUseCase;
5+
import com.somemore.auth.idpw.filter.IdPwAuthFilter;
36
import com.somemore.auth.jwt.filter.JwtAuthFilter;
47
import com.somemore.auth.jwt.filter.JwtExceptionFilter;
8+
import com.somemore.auth.jwt.usecase.GenerateTokensOnLoginUseCase;
59
import com.somemore.auth.oauth.handler.failure.CustomOAuthFailureHandler;
610
import com.somemore.auth.oauth.handler.success.CustomOAuthSuccessHandler;
711
import com.somemore.auth.oauth.service.CustomOAuth2UserService;
812
import lombok.RequiredArgsConstructor;
913
import org.springframework.context.annotation.Bean;
1014
import org.springframework.context.annotation.Configuration;
15+
import org.springframework.security.authentication.AuthenticationManager;
16+
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
1117
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
1218
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1319
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
1420
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
1521
import org.springframework.security.config.http.SessionCreationPolicy;
22+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
23+
import org.springframework.security.crypto.password.PasswordEncoder;
1624
import org.springframework.security.web.SecurityFilterChain;
1725
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
1826

@@ -29,7 +37,20 @@ public class SecurityConfig {
2937
private final JwtExceptionFilter jwtExceptionFilter;
3038

3139
@Bean
32-
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
40+
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
41+
return authenticationConfiguration.getAuthenticationManager();
42+
}
43+
44+
@Bean
45+
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity,
46+
AuthenticationManager authenticationManager,
47+
GenerateTokensOnLoginUseCase generateTokensOnLoginUseCase,
48+
CookieUseCase cookieUseCase,
49+
ObjectMapper objectMapper) throws Exception {
50+
51+
IdPwAuthFilter idPwAuthFilter = new IdPwAuthFilter(authenticationManager, generateTokensOnLoginUseCase, cookieUseCase, objectMapper);
52+
idPwAuthFilter.setFilterProcessesUrl("/api/center/sign-in");
53+
3354
httpSecurity
3455
.csrf(AbstractHttpConfigurer::disable)
3556
.httpBasic(AbstractHttpConfigurer::disable)
@@ -41,6 +62,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
4162
.authorizeHttpRequests(request ->
4263
request
4364
.requestMatchers(
65+
"/api/center/sign-in",
4466
"/**"
4567
// "/login",
4668
// "/oauth2/**",
@@ -64,8 +86,14 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
6486

6587

6688
return httpSecurity
89+
.addFilterBefore(idPwAuthFilter, UsernamePasswordAuthenticationFilter.class)
6790
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class)
6891
.addFilterBefore(jwtExceptionFilter, JwtAuthFilter.class)
6992
.build();
7093
}
94+
95+
@Bean
96+
public PasswordEncoder passwordEncoder() {
97+
return new BCryptPasswordEncoder();
98+
}
7199
}

0 commit comments

Comments
 (0)