AuthenticationManager에서 인증을 하고 만들어진 Authentication 객체가 있다.
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Object principal = authentication.getPrincipal();
이렇게 꺼낼 수 있었었다. 언제 들어 갔을까?
크게 두가지 필터가 넣어 준다.
UsernamePasswordAuthenticationFilter
SecurityContextPersistenceFilter
디버거로 확인을 해보자.
- SecurityContextPersistenceFilter에서 유저 정보를 찾지 못했다.
- 유저를 생성하고 dashboard에 접근해 보자
- 다시 SecurityContextPersistenceFilter에 걸린다. Null authentication이다.
- 이미 만들어진 데이터를 Context에서 읽어 오려는 것이다.
- 로그인 폼이 떠서 로그인하자.
- 로그인 시도, 아직 로그인 처리가 되기 전이다.
- UsernamePasswordAuthenticationFilter에서 폼 인증을 처리하려고 한다.
- authenticationManager를 가져와서 인증을 시도한다.
- 이전 강좌의 과정이 진행된다.
- 인증이 끝나게 되면 UsernamePasswordAuthenticationFilter에서 만들어진 Authenticaiton 객체를 리턴한다.