[SpringSecurity] 헷갈리는 개념 정리 - Authentication, UserDetails

해니·2024년 9월 11일
0

SpringBoot

목록 보기
16/24
post-thumbnail

인증(Authentication)


Authentication 인터페이스

  • 스프링 시큐리티 프레임워크 안에서 인증된 사용자의 세부 정보를 저장하는 클래스
  • UsernamePasswordAuthenticationFilter와 같은 필터는 HTTP 요청에서 usernamepassword를 추출해 Authentication 타입 객체를 준비한다.
    • POST 방식으로 넘어 왔는지, usernamepasswordnull인지 등등을 체크한다.
  • 요청이 인증되면 일반적으로 인증은 SecurityContextHolder 가 관리하는 스레드 로컬 SecurityContext 에 저장된다.

UsernamePasswordAuthenticationFilter 필터는 기본적으로 /login URL에 응답한다.



AuthenticationManager 인터페이스

  • 필터로부터 요청을 받으면 AuthenticationManager는 요청 받은 사용자의 세부 정보를 유효성 검사하기 위해서 요청을 Authentication provider들에게 위임한다.



UserDetails


UserDetailsManager 인터페이스

  • 사용자와 관련한 CRUD를 메서드를 갖고 있는 인터페이스
  • 사용자를 생성, 업데이트, 삭제, 비밀번호 변경, 유저유무 확인 등을 할 때 UserDetailsManager를 상속받아서 사용한다.
    • 매개변수로 UserDetails 객체를 받는다.


UserDetailsService 인터페이스

  • 로그인할 때 입력하는 사용자의 이름(이메일, ID)을 매개변수로 받아 UserDetails 객체를 반환한다.
  • 사용자 DAO(Data Access Object) 객체로서의 역할을 한다.
  • loadUserByUsername()
    • 비밀번호와 관련된 것은 PasswordEncoder가 처리한다.



UserDetails

  • UserDetailsServiceUserDetailsManager 인터페이스에서 사용되는 객체
  • 데이터베이스나 해쉬맵과 같은 인메모리 저장 공간에서 유저의 정보를 로드할 때 사용된다.






출처

[Spring Security] UserDetailsService와 UserDetails 및 Authentication의 차이점
Spring Security 전체 흐름 살펴보기
[Spring Security] 스프링 시큐리티란?

profile
💻 ⚾️ 🐻

0개의 댓글