title: Spring Security & ExtJS - redirecting to login page on session timeout
body: <p>I am using ExtJS with Spring MVC/Security. I want the user to be redirected to the login page when the session has expired, and I gave this in the Spring security application context - </p>
  
  <pre><code>&lt;session-management invalid-session-url="/login.jsp"&gt;&lt;/session-management&gt;
  </code></pre>
  
  <p>But since the calls to the server are all AJAX based, the redirection does not happen.
  Please suggest the best way to implement this.
  I have a custom <code>UserNamePasswordAuthenticationFilter</code> implemented for AJAX login:</p>
  
  <pre><code>@Override
      protected void successfulAuthentication(HttpServletRequest request,
          HttpServletResponse response, Authentication authResult) throws IOException,
          ServletException {
          SavedRequestAwareAuthenticationSuccessHandler srh = new SavedRequestAwareAuthenticationSuccessHandler();
          this.setAuthenticationSuccessHandler(srh);
          srh.setRedirectStrategy(new RedirectStrategy() {
              @Override
              public void sendRedirect(HttpServletRequest httpServletRequest,
                  HttpServletResponse httpServletResponse, String s) throws IOException {
                  // do nothing, no redirect
              }
          });
          super.successfulAuthentication(request, response, authResult);
  
          HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(
           response);
          Writer out = responseWrapper.getWriter();
          out.write("{success:true}");
          out.close();
      }
  </code></pre>