Skip to content

UsernamePasswordAuthenticationFilter

Carol edited this page Aug 28, 2024 · 1 revision

에러처리

AuthenticationException

  • AuthenticationException 사용:
    • Spring Security는 AuthenticationException을 통해 인증 실패를 처리합니다. 따라서, 이 예외를 던지면 unsuccessfulAuthentication 메서드가 정상적으로 호출됩니다.
  • 구체적인 예외 처리:
    • IOException 등 예상되는 예외에 대해 구체적인 메시지를 포함한 AuthenticationException을 던집니다. 이로 인해 사용자가 로그인 실패의 원인을 명확하게 알 수 있습니다.
    • 마지막 catch 블록에서 발생한 모든 다른 예외도 AuthenticationException으로 래핑하여 던집니다. 이를 통해 예상하지 못한 예외도 unsuccessfulAuthentication 메서드에서 처리될 수 있습니다.

successfulAuthentication()

*super.successfulAuthentication(request, response, chain, authResult);*

→ /로 redirect된다.

만약 다른 경로로 redirect 하고 싶다면

response.sendRedirect("/owner?message=" + Const.***LOGIN_COMPLETED***);

위와 같이 직접 redirect 시켜주면 된다.