PrincipalDetailsService 클래스의 내부 메서드에서 findByUsername으로 User 조회후 UserDetails 를 상속하는 PrincipalDetails 객체를 반환하도록 구현했다.
PrinciplaDetails 는 UserDetails 의 모든 메서드들을 오버라이딩한다.
이를 바탕으로 성공적인 로그인을 수행하였다.
이제 뷰를 연동하고 로그인 세션을 조회하자
ImageController 와 UserController 의 생성으로 URL과 뷰 매핑 수행
위는 로그인 요청시 시큐리티가 로그인 처리를 하는 과정이다.
PrincipalDetailsService는 username을 DB에서 확인한다.
해당 username의 User가ㅏ 존재하면 PrincipalDetails를 Authentication 객체에 담아 세션의 SecurityContextholder 에 저장한다.
스프링은 이를 쉽게 접근할 수 있도록 @AuthenticationPrincipal 어노테이션을 제공한다.
@AuthenticationPrincipal 로 세션을 찾을 수도 있고.
SecurityContextHolder.getContext.getAuthentication() 으로 직접 세션을 찾을 수도 있다.
조회 결과 세션의 User가 제대로 조회된다.