

Http Request(요청)이 서버로 전송됩니다.
AuthenticationFilter가 요청을 받습니다.
AuthenticationFilter에서 Request의 Id,Password를 이용하여 AuthenticationToken을 생성합니다.
토큰을 AuthenticationManager가 받습니다.
AuthenticationManager는 토큰을 AuthenticationProvider에게 토큰을 넘겨줍니다.
AuthenticationProvider는 UserDetailsService로 토큰 사용자의 Id를 전달하여, 데이터베이스에서 Id존재를 확인합니다.
UserDetailsService는 데이터베이스의 회원정보를 UserDetails라는 객체로 반환 받습니다.
AuthenticationProvider는 반환받은 UserDetails 객체와 실제 사용자의 입력정보를 비교합니다.
비교가 완료되면 사용자 정보가 담긴 Authentication 객체를, 다시 SecurityContextHolder에 담은 이후 AuthenticationSuccessHandle을 실행합니다.
public interface Authentication extends Principal, Serializable {
Collection<? extends GrantedAuthority> getAuthorities();
Object getCredentials();
Object getDetails();
Object getPrincipal();
boolean isAuthenticated();
void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException;
}
Collection<? extends GrantedAuthority> getAuthorities();Object getCredentials();Object getDetails();Object getPrincipal();boolean isAuthenticated();void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException;public class UsernamePasswordAuthenticationToken extends AbstractAuthenticationToken {
private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
private final Object principal;
private Object credentials;
public UsernamePasswordAuthenticationToken(Object principal, Object credentials) {
super(null);
this.principal = principal;
this.credentials = credentials;
setAuthenticated(false);
}
public UsernamePasswordAuthenticationToken(Object principal, Object credentials,
Collection<? extends GrantedAuthority> authorities) {
super(authorities);
this.principal = principal;
this.credentials = credentials;
super.setAuthenticated(true);
}
}
private final Object principal;private Object credentials;public UsernamePasswordAuthenticationToken(Object principal, Object credentials){...}public UsernamePasswordAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {...}public interface AuthenticationManager {
Authentication authenticate(Authentication authentication) throws AuthenticationException;
}
Authentication authenticate(Authentication authentication) throws AuthenticationException;public interface AuthenticationProvider {
Authentication authenticate(Authentication authentication) throws AuthenticationException;
boolean supports(Class<?> authentication);
}
Authentication authenticate(Authentication authentication) throws AuthenticationException;boolean supports(Class<?> authentication);public class ProviderManager implements AuthenticationManager, MessageSourceAware, InitializingBean {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
Class<? extends Authentication> toTest = authentication.getClass();
AuthenticationException lastException = null;
AuthenticationException parentException = null;
Authentication result = null;
Authentication parentResult = null;
int currentPosition = 0;
int size = this.providers.size();
for (AuthenticationProvider provider : getProviders()) {...}
}
public interface UserDetailsService {
UserDetails loadUserByUsername(String username) throws UsernameNotFoundException;
}
UserDetails loadUserByUsername(String username) throws UsernameNotFoundException;
public interface UserDetails extends Serializable {
Collection<? extends GrantedAuthority> getAuthorities();
String getPassword();
String getUsername();
boolean isAccountNonExpired();
boolean isAccountNonLocked();
boolean isCredentialsNonExpired();
boolean isEnabled();
}
Collection<? extends GrantedAuthority> getAuthorities();String getPassword();String getUsername();boolean isAccountNonExpired();boolean isAccountNonLocked(); isCredentialsNonExpired();isEnabled();SecurityContextHolder.getContext().setAuthentication(authentication);
SecurityContextHolder.getContext().getAuthentication(authentication);