title: How to log out automatically with Spring Security
body: <p>I have a spring web application and I did user authentication using Spring security. </p>
  
  <p>Everything works well. Log in and Log out works perfect!</p>
  
  <p>Now, I want to implement in order to log out automatically. For example, if user has a window opened for about 30 minutes and do nothing (Sessions expired for instance) system should log out automatically. How can I implement this? </p>
  
  <p>It might be implemented by client side (I send requests every 1 minutes and check if session is ended). But can't I do this automatically from Spring?</p>
  
  <p>I have this config:</p>
  
  <pre><code>&lt;http auto-config="true" use-expressions="true"&gt;
  
  
          &lt;intercept-url pattern="/admin**" /&gt;
          &lt;access-denied-handler error-page="/403" /&gt;
  
          &lt;form-login login-page="/login" 
              default-target-url="/admin"
              authentication-failure-url="/login?error" 
              username-parameter="NAME"
              password-parameter="PASSWORD"  /&gt;
  
          &lt;logout invalidate-session="true" 
               logout-success-url="/login?logout"/&gt;
  
      &lt;/http&gt;
  </code></pre>
  
  <p>and in web.xml</p>
  
  <pre><code>&lt;session-config&gt;
    &lt;session-timeout&gt;1&lt;/session-timeout&gt;
  &lt;/session-config&gt;
  </code></pre>
  
  <p>after 1 minute, I see that session was destroyed.   kill the session after 1 minute. but page was not redirected to /login?logout</p>