inblog logo
|
vosw1
    Spring

    Spring Security 정리

    Feb 14, 2024
    Spring Security 정리

    notion image

    1. 클라이언트가 요청 : post, /login

    2. UsernamePasswordAuthenticationFilter : 사용자 자격 증명 추출

    1) x-www-form-urlencoded (키값) 파싱
    다른 타입을 하고 싶으면 커스터 마이징 해야함
    2) 키값 : username, password
    3) UsernamePasswordAuthentication Token(DTO) 객체에 키값 담기

    3. Authentication Manager : 사용자 인증 / session 기반 인증

    1) UserDetail의 loadUserByUsername() 호출
    AuthenticationProvider 목록을 반복하여 인증을 시도
    DaoAuthenticationProvider는 UserDetailsService를 사용하여 사용자 정보를 검색
    UserDetailsService는 사용자 이름으로 데이터베이스나 다른 저장소에서 사용자 정보를 조회
    2) 응답 : null → Filter Security Intercenptor : 오류를 터뜨림 → failurl로 이동
    3) 정상 → password 비교
    DaoAuthenticationProvider는 사용자 정보를 찾음
    저장된 비밀번호와 클라이언트가 제출한 비밀번호를 비교
    * 해시 함수를 사용하여 암호화되어 있으므로, 비밀번호를 해시하여 비교
    4) Authentication 객체 생성후 반환
    사용자 정보와 해당 사용자의 권한 정보로 구성

    4. Authentication Context Holder : 저장

    1) Authentication 안에 getter 들로 검사
    2) 인증 성공시 session에 저장
    Authentication 객체를 Authentication Context Holder에 저장
    현재 스레드의 보안 관련 정보를 저장하는데 사용
    Authentication 객체는 이후 인증 및 권한 부여를 위해 사용
    3) 구조
    principal : UserDetails(MyLoginUsewr)
    credentials : password
    authorities : 권한
    4) 회원정보가 변경된 경우
    수정된 user 객체를 UserDetail에 넣고 principal에 덮어 씌우기
    → 통으로 session 바꾸기

    5. Filter Security Intercenptor : sucessurl로 이동

     
     
     
     
     
    Share article

    vosw1

    RSS·Powered by Inblog