해당 게시글은 개인 프로젝트인 "데이트 장소 다이어리 제작" 중
#34 "로그아웃 기능 수정 및 자동 로그인 기능 재활성화" 이슈를 다루고 있습니다.
create table persistent_logins
(
username varchar(64) not null,
series varchar(64) primary key,
token varchar(64) not null,
last_used timestamp not null
)
public class CustomLoginFailureHandler implements AuthenticationFailureHandler {
private final String DEFAULT_FAILURE_URL = "/user/login?error=true";
@Override
public void onAuthenticationFailure(HttpServletRequest request,
HttpServletResponse response,
AuthenticationException exception) throws IOException, ServletException {
String errorMessage = null;
if (exception instanceof UsernameNotFoundException) {
errorMessage = "계정이 존재하지 않습니다.";
}
else if (exception instanceof BadCredentialsException || exception instanceof InternalAuthenticationServiceException) {
errorMessage = "아이디나 비밀번호가 맞지 않습니다.";
}
else {
errorMessage = "알 수 없는 이유로 로그인에 실패하였습니다.";
}
request.setAttribute("errorMessage", errorMessage);
request.getRequestDispatcher(DEFAULT_FAILURE_URL).forward(request, response);
}
}