⏰ 2024. 06. 12 수
✔ 스프링 이론 강의를 듣고 정리하면서 작성했습니다.
Security 이해하기
Spring Security 프레임워크는 Spring 서버에 필요한 인증 및 인가를 위해 많은 기능을 제공해 줌으로써 개발의 어려움을 줄여준다.Spring에서 모든 호출은 DispatchServlet을 통과하고 이후 각 요청을 담당하는 Controller로 분배된다.
각 요청에 대해 공통적으로 처리해야할 필요가 있을 때, DistpatcherServlet 이전의 단계가 필요하고 이것이 Filter이다.

Spring Security도 인증 및 인가를 처리하기 위해 Filter를 사용하고, Spring Security는 FilterChainProxy를 통해 상세로직을 구현한다.

From Login 기반 인증은 인증이 필요한 URL 요청이 들어왔을 때 인증이 되지 않으면 로그인 페이지를 반환하는 형태이다.
UsernamePasswordAuthenticationFilter는 Spring Security의 필터인 AbstracAuthenticationProcessingFilter를 상속한 Filter이다.
기본적으로 Form Login 기반을 사용할 때 username과 password를 확인하고 인증한다.
UsernamePasswordAuthenticationToken을 만들어 AuthenticationManager에게 넘겨 인증을 시도한다.SecurityContextHolder를 비운다.Authentication을 저장한다.
현재 인증된 사용자를 나타내며 SecurityContext에서 가져올 수 있다.
Principal : 사용자를 식별하고, Username/Password 방식으로 인증할 때 일반적으로 UserDetails 인스턴스이다.
Credentials : 주로 비밀번호, 대부문 사용자 인증에 사용한 후 비운다.
Authorities : 사용자에게 부여한 권한을 GrantedAuthority로 추상화하여 사용한다.
UsernamePasswordAuthenticationToken은 Authentication을 implements한
AbstractAuthenticationToken의 하위 클래스로, 인증객체를 만드는데 사용된다.
UserDetails를 반환한다.UserDetailsServiceImpl의 형태로 Custom하여 Bean으로 등록 후 사용 가능하다.Authentication을 만들 때 사용된다.SecurityContextHolder에 저장된다.UserDetailsService와 마찬가지로 UserDetailsImpl읜 형태로 Custom하여 사용 가능하다.