로그인 인증 실패 시 추가 로직 실행 가능

코드 작성 예시


public class MemberAuthenticationFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        sendErrorResponse(response);
    }

    private void sendErrorResponse(HttpServletResponse response) throws IOException{
        ObjectMapper mapper = new ObjectMapper();

        ErrorResponseDto errorResponseDto = ErrorResponseDto.of(ExceptionType.AUTHENTICATION_FAILED);

        response.setContentType("application/json;charset=UTF-8");
        response.setStatus(401);

        response.getWriter().write(mapper.writeValueAsString(errorResponseDto));
    }
}

핸들러 적용

Security Filter Chain 구성

해당 문서의 CustomFilterConfigurer 적용 부분 참조