title: Configuring spring security to redirect user to previous location after session timeout
body: <p>I have a slight issue with my configuration of spring security and the InvalidSessionStrategy implementation I use.</p>
  
  <p>Say a user is connected to the app and is viewing page: <code>/userArea/thePage</code> and <strong>their session times out</strong>, the user will <strong>first be redirected to</strong> the <code>/signin</code> page. Then, upon successful signin, they will <strong>be redirected to the home page of they personal area</strong> (<code>/userArea</code>) <strong>whereas I want them to come back to where they were located when the session timed out</strong> i.e. <code>/userArea/thePage</code>. </p>
  
  <p>Is this possible? </p>
  
  <p>If so how do I need to alter my config/app?</p>
  
  <p>Here is my current config:</p>
  
  <pre><code>&lt;beans:bean id="sessionManagementFilter" class="org.springframework.security.web.session.SessionManagementFilter"&gt;
          &lt;beans:constructor-arg name="securityContextRepository" ref="httpSessionSecurityContextRepository" /&gt;
          &lt;beans:property name="invalidSessionStrategy" ref="simpleRedirectInvalidSessionStrategy" /&gt;
      &lt;/beans:bean&gt;
  
  &lt;beans:bean id="simpleRedirectInvalidSessionStrategy" class="org.springframework.security.web.session.SimpleRedirectInvalidSessionStrategy"&gt;
      &lt;beans:constructor-arg name="invalidSessionUrl" value="/signin" /&gt;
      &lt;beans:property name="createNewSession" value="true" /&gt;
  &lt;/beans:bean&gt;
  
  
  &lt;http auto-config="true" use-expressions="true"&gt;
          &lt;custom-filter ref="sessionManagementFilter" before="SESSION_MANAGEMENT_FILTER" /&gt;
          &lt;form-login login-processing-url="/resources/j_spring_security_check" login-page="/signin" authentication-failure-url="/signin?login_error=t" default-target-url="/userArea" /&gt;
          &lt;logout logout-url="/resources/j_spring_security_logout" logout-success-url="/signin" /&gt;
  ...
  </code></pre>
  
  <p><strong>edit 1</strong>: Let me better specify my requirements:</p>
  
  <ul>
  <li>When a user session times out, I want the user to be redirected to the saved request (the url they requested before being redirected to the signin page).</li>
  <li>However, when they initially signin with the app, I want them to be redirected to the home page of the personal area.</li>
  </ul>
  
  <p>Are my requirements possible to implement using solution suggested by Carsten (see below)?</p>