11package 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 ;
36import com .somemore .auth .jwt .filter .JwtAuthFilter ;
47import com .somemore .auth .jwt .filter .JwtExceptionFilter ;
8+ import com .somemore .auth .jwt .usecase .GenerateTokensOnLoginUseCase ;
59import com .somemore .auth .oauth .handler .failure .CustomOAuthFailureHandler ;
610import com .somemore .auth .oauth .handler .success .CustomOAuthSuccessHandler ;
711import com .somemore .auth .oauth .service .CustomOAuth2UserService ;
812import lombok .RequiredArgsConstructor ;
913import org .springframework .context .annotation .Bean ;
1014import org .springframework .context .annotation .Configuration ;
15+ import org .springframework .security .authentication .AuthenticationManager ;
16+ import org .springframework .security .config .annotation .authentication .configuration .AuthenticationConfiguration ;
1117import org .springframework .security .config .annotation .method .configuration .EnableMethodSecurity ;
1218import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
1319import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
1420import org .springframework .security .config .annotation .web .configurers .AbstractHttpConfigurer ;
1521import org .springframework .security .config .http .SessionCreationPolicy ;
22+ import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
23+ import org .springframework .security .crypto .password .PasswordEncoder ;
1624import org .springframework .security .web .SecurityFilterChain ;
1725import 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