-
로그아웃SPRING/스프링 시큐리티 2021. 8. 1. 16:04
아래와 같이 로그아웃 관련 설정을 할 수 있다.
@Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { // 모든 리소스에 대한 인증완료시 접근 허용 http .authorizeRequests() .anyRequest().authenticated(); // form Login 사용 http .formLogin(); // LogOut http .logout() // 로그아웃 처리 .logoutUrl("/logout") // 로그아웃 처리 URL .logoutSuccessUrl("/login") // 로그아웃 성공 후 이동페이지 .addLogoutHandler(new LogoutHandler() { // 로그아웃 후 쿠기 삭제 @Override public void logout(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) { HttpSession session = httpServletRequest.getSession(); session.invalidate(); } }) .logoutSuccessHandler(new LogoutSuccessHandler() { // 로그아웃 핸들러 @Override public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException { httpServletResponse.sendRedirect("/login"); } }) .deleteCookies("remember-me"); // 로그아웃 후 쿠키 삭제 } }
'SPRING > 스프링 시큐리티' 카테고리의 다른 글
세션 정책 및 고정세션 공격방지 (0) 2021.08.03 remember-me (0) 2021.08.01 FORM 인증 - 기본 (0) 2021.08.01 Security Configuration 클래스 기본 설정 (0) 2021.08.01 의존성 추가 및 기본 세팅 (0) 2021.08.01