Backend 개발/Spring Security 6

Spring Security 6 BasicAuthenticationFilter 이란?

수달리즘 2025. 5. 26. 09:37
반응형

BasicAuthenticationFilter

HTTP Basic 인증 에서 사용되는 필터로서 클라이언트가 Base64로 인코딩하여 보낸 username/password 를 BasicAuthenticationConverter 를 이용하여 디코딩한다.

// BasicAuthenticationFilter 코드
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
try {
    // BasicAuthenticationConverter.convert(request)가 호출되어 username/password 디코딩 수행
    Authentication authRequest = this.authenticationConverter.convert(request);
    ..

    chain.doFilter(request, response);
}


세션 사용 여부와 상관없이 Authentication(인증 정보)을 SecurityContextHolder에 저장하지만 처리 방식은 조금 다르다.

1) 세션 사용할 경우

  • Authentication(인증 정보)를 HttpSession에 저장
  • 이후 요청은 세션을 이용하여 인증 정보 재사용

2) 세션 사용하지 않을 경우

  • Authentication(인증 정보)를 세션에 저장하지 않음
  • 이후 요청이 오면 매번 인증 다시 수행

흐름도

 

 

728x90
반응형