AuthenticationManager가 실제로 인증을 관리한다.
구현체로는 ProviderManager를 많이 사용한다. 직접 구현할 일은 많이 없다.
전달 받은 Authentication
이것을 이용해서 유저를 인증한다. 이 과정에서 우리가 만든 UserDetailsService 구현체를 이용해서 유저 정보를 가져온다.
result라는 객체를 최종적으로 return 하게 되는데
principal이 달라졌다. User라는 객체인데 이 객체는 우리가 구현한 UserDetailsService에서 리턴한 객체이다.
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Account account = accountRepository.findByUsername(username);
if (account == null) {
throw new UsernameNotFoundException(username);
}
return User.builder()
.username(account.getUsername())
.password(account.getPassword())
.roles(account.getRole())
.build();
}
이 객체가 이제 securityContextHolder에 저장이 되고 credential은 사라진다.