spring-security를 통해 로그인이 되는 방식이 궁금했다.
spring-security에서는 어떻게 로그인 처리가 될까?
1. Spring Security 설정(SecurityConfig)
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.formLogin(loginForm -> loginForm // 커스텀 form 방식 로그인 사용
.loginPage("/login")
.defaultSuccessUrl("/index", true)
.permitAll())
return http.build();
}
위와 같이 http.formLogin()을 builder에 추가하면 요청 처리 filter에 UsernamePasswordAuthenticationFilter가 추가된다
요청 >>> 요청처리1 >>> 요청처리2 >>> 요청처리3 >>> ....
-------SpringSecurity에서 http.formLogin() 추가 된 후-------
요청 >>> 요청처리1 >>> 요청처리2 >>> (UsernamePasswordAuthenticationFilter) >>> 요청처리3 >>> ....
'/login'라는 키워드가 포함된 path는 UsernamePasswordAuthenticationFilter에서 username과 pathword를 추출한 뒤 AuthenticationManager에게 인증처리하는 로직을 수행하게 된다
AuthenticationManager는 내부적으로 DaoAuthenticationProvider를 이용하여 인증을 수행하는데 이때 UserDetailsService 인터페이스를 이용한다. UserDetailsService 상속받은 객체를 구현했다면 요청이 들어왔을 때, UserDetailsService 구현한 서비스가 동작하게 된다.
'오픈소스 > Spring' 카테고리의 다른 글
Spring JPA에서 연관관계 맵핑 (0) | 2025.01.11 |
---|---|
Spring(벡엔드)가 최종적으로 제공하는 것 (0) | 2024.10.14 |
Spring-Bean Container에 대한 예제와 이에 대한 후기 (0) | 2024.10.14 |
Spring SOLID 원칙 (1) | 2024.09.24 |