AuthenticationManager
。Spring Security에서HTTP Request로 전달되는사용자 인증(Authentication)의검증을 담당하는인터페이스
。AuthenticationProvider들을 등록 및 관리하는 역할을 수행
▶특정 인증방식(password,JWT등 )에 대한검증기능이 구현된 수많은AuthenticationProvider를사전등록
▶ 각사용자가 다양한사용자인증정보을 통한로그인을 수행하더라도 해당인증에 대한검증을 제공하는AuthenticationProvider를자동으로 식별후인증에 대한검증을 수행
。보통WebSecurityConfiguration를 담당하는@Configuration Class내에서@Bean method를 통해Spring Bean으로 등록// @Configuration Class @Bean public AuthenticationManager authenticationManagerBean(AuthenticationConfiguration authenticationConfiguration) throws Exception { return authenticationConfiguration.getAuthenticationManager(); }
AuthenticationManager객체.authenticate(Authentication객체)public interface AuthenticationManager { Authentication authenticate(Authentication authentication) throws AuthenticationException; }。
HTTP Request를 통해credentials만 포함된 미완성된Authentication 구현체를 전달 시사용자의Authentication를검증
▶검증 성공시principal,authorities가 추가된 완전한Authentication 구현체를 반환
▶검증 실패시AuthenticationException발생.
。Authentication 구현체의credentials에 저장된사용자인증종류 (jwt,password등 )에 대한 적절한검증기능을 지닌AuthenticationProvider를 적절하게 식별 후UserDetailsService의UserDetails와 전달된credentials를 비교하여검증
AuthenticationProvider
。Spring Security의 특정사용자인증(jwt,password등 )에 대한검증을 수행하는인터페이스
▶AuthenticationManager에 등록되어 활용
。사용자가특정 인증 방식(JWT)의로그인 요청을 보낼 경우Authenticatiion Manager에 의해 해당 인증 방식을 검증하는AuthenticationProvider가 식별되어검증을 수행
。UserDetailsService를 통해인증에 필요한사용자 정보를DB에서 가져와서UserDetails 구현체를 생성 후 활용
JWT기반의로그인 로직을 통해Security Context Holder에 저장되는 과정
1.Authentication 구현체의Credential의인증정보( =JWT) 획득 및AuthenticationManager에 의해 해당인증정보에 적합한AuthenticationProvider식별
。식별된AutheticationProvider:JwtAutheticationProvider
JwtAutheticationProvider는 전달된JWT 토큰의서명을 검증
- 해당
JWT의Claims에 포함된username를 토대로UserDetailsService를 호출하여DB에서UserDetails 구현체를 생성 후 사용자 정보를 포함한Authentication 구현체를 생성 후 반환
。검증이 성공할 경우,principal,authorities정보를 추가로 포함한 완전한Authentication 구현체를 생성하여 반환
▶ 이후SecurityContextHolder에 저장되어인증상태유지
AuthenticationProvider종류
JwtAutheticationProvider:
。JWT기반 인증을 처리하는AuthenticationProvider.