본문 바로가기
Spring/Spring Security

UserDetailsService 로 인증처리할때 password

by doriver 2024. 6. 10.

Spring Security에서는 

DB에서 username으로 User정보( password 포함되있음 ) 가져와서, 사용자 입력 password랑 비교함


( 사용자가 입력한 password ) 와 ( DB에 저장된 password ) 의 비교가
AuthenticationProvider에 의해 자동으로 처리됨

 

기본적으로 Spring Security는 DaoAuthenticationProvider를 사용
DaoAuthenticationProvider는 PasswordEncoder를 사용하여 비교

( 사용자가 입력한 자격 증명 ) 과 ( UserDetailsService를 통해 로드된 사용자 정보 ) 을 비교합니다.

 

비교과정

1. 사용자 로그인 시도
2. AuthenticationManager 호출
로그인 폼 데이터는 UsernamePasswordAuthenticationToken으로 변환되어 AuthenticationManager에게 전달됨

 

3. AuthenticationProvider 실행
AuthenticationManager는 등록된 AuthenticationProvider 목록 중 하나를 사용하여 인증을 시도합니다. 기본적으로 DaoAuthenticationProvider가 사용됩니다.

4. 사용자 정보 로드
DaoAuthenticationProvider는 UserDetailsService를 사용하여 데이터베이스에서 사용자 정보를 로드합니다.

5. 비밀번호 비교
DaoAuthenticationProvider는 사용자가 입력한 비밀번호를 로드된 UserDetails 객체의 비밀번호와 비교합니다. 이때 비밀번호 비교는 PasswordEncoder를 사용하여 이루어집니다.

 

 

'Spring > Spring Security' 카테고리의 다른 글

토큰기반 인증, JWT  (0) 2024.11.04
Security 메커니즘  (0) 2024.10.12
formLogin()로 사용자가 로그인했을때 HttpSession  (1) 2024.06.08
MD5형식으로 암호화  (0) 2024.05.21
Spring Security 쓰는 이유 서치  (0) 2024.04.18