春天递延结果失去了HTTP会话 [英] Spring Deferred result lost http session
问题描述
使用I'm在异步模式与Spring MVC的一个Tomcat 7和Spring的安全性。
然后I'm使用DeferredResult进行异步请求。该机制运行正常,但问题是比当deferredResult做出的setResult()和返回的承诺,我失去了所有的会议,我的下一个请求给我一个403禁止的,因为我没有在我的SecurityContextHolder里我的验证。
我猜是因为承诺的回报率在不具有会话另一个线程完成。
有人可以把我在正确的方向在这里请。
解决方案:onCompletion回调方法我通过,我把我在地图创建deferredResult会话
。 deferredResult.onCompletion(新的Runnable(){
@覆盖
公共无效的run(){
。request.getSession()的setAttribute(SPRING_SECURITY_CONTEXT,securityContextContainer.get(deferredResult));
securityContextContainer.remove(deferredResult);
}
});
解决方案:onCompletion回调方法我通过我把会话,当我创建一个映射的deferredResult
。 deferredResult.onCompletion(新的Runnable(){
@覆盖
公共无效的run(){
。request.getSession()的setAttribute(SPRING_SECURITY_CONTEXT,securityContextContainer.get(deferredResult));
securityContextContainer.remove(deferredResult);
}
});
I´m using a Tomcat 7 with Spring MVC and Spring security in async mode.
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.
I guess is because the return of the promise is done in another thread that dont has the session.
Somebody can put me in the right direction here please.
Solution: onCompletion callback method I pass the session that I put when I create the deferredResult in a map.
deferredResult.onCompletion(new Runnable() {
@Override
public void run() {
request.getSession().setAttribute(SPRING_SECURITY_CONTEXT, securityContextContainer.get(deferredResult));
securityContextContainer.remove(deferredResult);
}
});
Solution: onCompletion callback method I pass the session that I put when I create the deferredResult in a map.
deferredResult.onCompletion(new Runnable() {
@Override
public void run() {
request.getSession().setAttribute(SPRING_SECURITY_CONTEXT, securityContextContainer.get(deferredResult));
securityContextContainer.remove(deferredResult);
}
});
这篇关于春天递延结果失去了HTTP会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!