2016-07-08 2 views
1

自動ログアウトとは、ユーザーがセッションを終了するとブラウザが自動的にログアウトURLにリダイレクトされるということです。とにかく彼はログアウトURLにリダイレクトされます。Java Springブート/スプリングセキュリティ(HttpSecurity)でセッションが期限切れになったときに自動ログアウトする方法

これは私のSecurityConfigです:

輸入org.springframework.beans.factory.annotation.Autowired。インポート org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.context.annotation.Bean;インポート org.springframework.context.annotation.Configuration;インポート org.springframework.core.annotation.Order;インポート org.springframework.security.access.vote.RoleVoter;インポート org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; インポート org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy;

/** * 2011年5月5日にプラトによって作成されました。 */@Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(真prePostEnabled =) @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)publicクラス はSecurityConfigポーリングする必要がありますWebSecurityConfigurerAdapter {

@Autowired 
DatabaseAuthenticationProvider authenticationProvider; 

@Override 
public void configure(WebSecurity web) throws Exception { 
    web.ignoring().antMatchers("/js/**", "/css/**", "/img/**", "/templates/**", "/thymeleaf/**"); 
} 

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http.formLogin() 
      .loginPage("/login") 
      .failureUrl("/login?failed=true") 
      .defaultSuccessUrl("/login-success") 
      .and().logout() 
      .logoutSuccessUrl("/") 
      .and().authorizeRequests() 
      .antMatchers("/admin**", "/api/admin/**").hasAuthority("ADMIN") 
      .antMatchers("/**") 
      .permitAll() 
      .anyRequest().authenticated() 
      .and().csrf().disable() 
      .sessionManagement() 
      .maximumSessions(1) 
      .expiredUrl("/login?expired-session") 
      .and() 
      .invalidSessionUrl("/?invalid-session"); 
} 

@Autowired 
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
    auth.authenticationProvider(authenticationProvider).eraseCredentials(true); 
} } 
+0

セッションがタイムアウトしました。情報がなくなりました。ログアウトから何が起こると思いますか? –

答えて

0

クライアントを拡張します。サーバーはリダイレクトを「プッシュ」できません。

クライアントはX時間ごとにポーリングできます.Xはセッションタイムアウトより少し長い時間です。投票がそれより頻繁であれば、セッションをリフレッシュし、タイムアウトすることはありません。クライアントは、すべてのユーザー操作でタイマーをリセットできます。

関連する問題