Spring的SecurityContextHolder.getContext()。getAuthentication()在HTTPS / SSL中使用RedirectView后返回null

我有一个典型的Spring MVC在Tomcat上运行。 将系统切换为在HTTPS上运行后(一切都在普通HTTP下运行正常),登录停止工作。 原因是Spring的SecurityContextHolder.getContext().getAuthentication()对象在使用RedirectView后变为null

我已经搜索了答案,我发现了唯一一个在viewResolver bean设置中将属性redirectHttp10Compatible设置为falseviewResolver 。 这没有用。

我还检查了整个重定向,我的会话ID保持不变,连接仍然是安全的,即http和https之间的变化(反之亦然)不是问题(至少就我所知)。

可能是什么问题呢?

                  

UpdateContextHolder.getContext SecurityContextHolder.getContext().getAuthentication()在重定向正确后变为null,因为它是线程绑定的。 但它应该从会议中重新填充。 因此,请尝试跟踪会话中的SPRING_SECURITY_CONTEXT属性。 以下是一些获得想法的示例代码:

 HttpSession session = request.getSession(true); System.out.println(session.getAttribute("SPRING_SECURITY_CONTEXT")); 

在Spring Security文档中,有一篇关于HTTPS / HTTP切换如何搞砸了会话的部分,也许在那里的某个地方有一个提示你的问题。 http://static.springsource.org/spring-security/site/faq.html#d0e223

以上常见问题解答可以检查您的应用程序中如何处理会话。 我可能会开始查看AuthenticationSuccessHandler实现。 (如果你愿意,你可以把它写进你的问题。)

有关如何在Web应用程序中处理安全上下文的更多详细信息,请参阅以下内容:(第5.4节): http : //static.springsource.org/spring-security/site/docs/3.0.x/reference/technical-overview。 HTML