title: Spring Deferred result lost http session
body: <p>I´m using a Tomcat 7 with Spring MVC and Spring security in async mode. </p>
  
  <p>Then I´m using DeferredResult to make async request. The mechanism works fine, but the problem is than when the deferredResult make the setResult() and return the promise, I lost all my session, and my next request give me a 403 forbidden since I dont have my authentication on my SecurityContextHolder.</p>
  
  <p>I guess is because the return of the promise is done in another thread that dont has the session.</p>
  
  <p>Somebody can put me in the right direction here please.</p>
  
  <p>Solution: onCompletion callback method I pass the session that I put when I create the deferredResult in a map.</p>
  
  <pre><code>      deferredResult.onCompletion(new Runnable() {
          @Override
          public void run() {
              request.getSession().setAttribute(SPRING_SECURITY_CONTEXT, securityContextContainer.get(deferredResult));
              securityContextContainer.remove(deferredResult);
          }
      });
  </code></pre>