Skip to Content
Suffering builds character
아카이브18.spring Security스프링 시큐리티3.인증실습Basic 인증3.인증 처리흐름

3.인증 처리흐름

인증이 성공하거나 실패하였을 경우에 대한 상세 처리 흐름은 다음과 같음

  1. 사용자가 username과 password로 자격 증명(자신의 자격을 증명하기 위한 식별자)을 전달하면 BasicAuthenticationFilter는 인증 방식을 구분하는 Authentication 타입 중 하나인UsernamePasswordAuthenticationToken 토큰을 생성함

  2. UsernamePasswordAuthenticationToken 토큰은 AuthenticationManager에게 인증 처리를 수행하는데 사용되도록 전달됨

  3. 만약 사용자가 전달한 자격 증명이 서버가 가진 자격 증명 정보와 일치하지 않아 인증이 실패할 경우, SecurityContextHolder가 지워지고, AuthenticationEntryPoint는 WWW-Authenticate 헤더를 다시 응답하기 위해 호출됨

  4. 만약 인증이 성공할 경우, 인증된 사용자의 자격 증명, 권한 정보 등이 담긴 Authentication 객체가 SecurityContextHolder에 저장되고, BasicAuthenticationFilter 는 doFilter(request,response)를 통해 다음 필터를 호출함

스프링 시큐리티의 기본 옵션

사실 스프링 시큐리티는 아래와 같이 별도의 SecurityConfig.java와 같은 설정 파일을 작성하지 않아도 인증을 위한 기본 방식으로 HTTP Basic 인증을 활성화해두었음

하지만 아래와 같이 별도의 클래스로 직접 SecurityFilterChain을 설정할 경우 명시적으로 HTTP Basic 인증을 활성화해야함

SecurityConfig.java

@Bean public SecurityFilterChain filterChain(HttpSecurity http) { http // ... .httpBasic(withDefaults()); return http.build(); }
Last updated on