로그아웃을 하게 되면
protected void configure(HttpSecurity http) throws Exception {
http.logout() // 로그아웃 처리
.logoutUrl("/logout") // 로그아웃 처리 URL
.logoutSuccessUrl("/login") // 로그아웃 성공 후 이동페이지
.deleteCookies("JSESSIONID“, "remember-me") // 로그아웃 후 쿠키 삭제
.addLogoutHandler(logoutHandler()) // 로그아웃 핸들러
.logoutSuccessHandler(logoutSuccessHandler()) // 로그아웃 성공 후 핸들러
}
protected void configure(HttpSecurity http) throws Exception {
http
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/login")
.addLogoutHandler(new LogoutHandler() {
@Override
public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
HttpSession session = request.getSession();
session.invalidate(); // 세션 무효화
}
})
.logoutSuccessHandler(new LogoutSuccessHandler() { // Url 메서드와 다르게 여러 작업을 할 수 있음
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
response.sendRedirect("/login");
}
})
.deleteCookies("remember-me") // 로그인하면 remember-me 라는 이름으로 쿠키를 발급받음
;
}