Dim*_*uba 10 java https spring tomcat spring-security
我有一个典型的Spring MVC在Tomcat上运行.切换系统以在HTTPS上运行(一切正常在HTTP下运行正常)后,登录停止工作.其原因是,Spring的SecurityContextHolder.getContext().getAuthentication()对象变成null后RedirectView使用.
我已经搜索的答案,我发现的唯一一个提议设置属性redirectHttp10Compatible,以false在viewResolverbean的设置.这没有用.
我还检查了整个重定向,我的会话ID保持不变,连接仍然是安全的,即http和https之间的变化(反之亦然)不是问题(至少就我所知).
可能是什么问题呢?
<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<http auto-config="true">
<intercept-url pattern="/**" requires-channel="https" />
<intercept-url pattern="/index*" access="ROLE_USER"/>
<intercept-url pattern="/dashboard*" access="ROLE_USER" requires-channel="https"/>
<intercept-url pattern="/login*" access="ROLE_GUEST, ROLE_ANONYMOUS, ROLE_USER"/>
<intercept-url pattern="/signin*" access="ROLE_GUEST, ROLE_ANONYMOUS, ROLE_USER"/>
<intercept-url pattern="/signup*" access="ROLE_GUEST, ROLE_ANONYMOUS, ROLE_USER"/>
<form-login login-page="/home"
default-target-url="/home"
authentication-failure-url="/home?authentication_error=true"
authentication-success-handler-ref="redefineTargetURL"
/>
<anonymous username="guest" granted-authority="ROLE_GUEST" key="anonymousKey"/>
<logout invalidate-session="true" logout-success-url="/logout?message=Logout Successful" />
</http>
<authentication-manager alias="authenticationManager">
<authentication-provider user-service-ref="userDetailsService" />
</authentication-manager>
<beans:bean id="redefineTargetURL" class="com.groupskeed.common.RedefineTargetURL" />
<beans:bean id="userDetailsService" class="com.groupskeed.security.UserDetailsServiceImpl" />
Run Code Online (Sandbox Code Playgroud)
Car*_*ten 26
将SecurityContextHolder.getContext().getAuthentication()成为空重定向后是正确的,因为它是threadbound.但它应该从会议中重新填充.因此,请尝试跟踪SPRING_SECURITY_CONTEXT会话中的属性.以下是一些获得想法的示例代码:
HttpSession session = request.getSession(true);
System.out.println(session.getAttribute("SPRING_SECURITY_CONTEXT"));
Run Code Online (Sandbox Code Playgroud)
在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
| 归档时间: |
|
| 查看次数: |
34871 次 |
| 最近记录: |