2017-06-29 6 views

答えて

2

使用

SecurityContextHolder.clearContext(); 

それとも

SecurityContextHolder.getContext().setAuthentication(null); 

HttpSession session = request.getSession(false); 
if (session != null) { 
    session.invalidate(); 
} 
1

あなたは、セッションベースauthentication.Youを使用している場合は、この目的のためにそのようなものを使用することがあります。

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http 
      .rememberMe() 
      .and() 
      .authorizeRequests() 
       .anyRequest().permitAll() 
      .and() 
      .formLogin() 
       .loginPage("/logout") 
       .loginProcessingUrl("/j_spring_security_check") 
       .defaultSuccessUrl("/my-profile") 
       .usernameParameter("username") 
       .passwordParameter("password") 
       .failureUrl("/login?error") 
      .and() 
      .logout() 
       .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) 
       .logoutSuccessUrl("/login?logout").deleteCookies("JSESSIONID") 
       .invalidateHttpSession(true); 

} 

ユーザーのプリフォームが許可されていない場合、Spring Securityは自動的にログインページにリダイレクトされます。そのため、ログアウト.loginPage("/logout")にリダイレクトし、ログアウト後にログインページにリダイレクトするのはなぜですか.logoutSuccessUrl("/login?logout")

関連する問題