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에 등록되어 활용
。사용자가AuthenticationProvider가 다루는인증 방식(JWT)의로그인 요청을 보낼 경우AuthenticationManager에 의해 식별되어검증을 수행
AuthenticationProvider에 의한검증순서
1.Authentication 구현체의Credential의인증정보( =JWT) 획득 및AuthenticationManager에 의해 해당인증정보에 적합한AuthenticationProvider식별
。식별된AutheticationProvider:JwtAutheticationProvider
- 해당
JWT의Claims에 포함된username를 토대로UserDetailsService를 호출하여DB에서UserDetails 객체를 가져온 후JWT획득
- 해당
해싱된JWT를 서로비교검증을 수행
▶검증이 성공할 경우,principal,authorities정보를 추가로 포함한 완전한Authentication 구현체를 반환
AuthenticationProvider종류
JwtAutheticationProvider:
。JWT기반 인증을 처리하는AuthenticationProvider.