当用户单击登录/注册页面(/user/add)时,我想从http切换到https,并保持https session 直到注销。 主页无需 https 即可访问。 我在 security.xml 中的代码:
<http auto-config="true">
<intercept-url pattern="/home*" access="ROLE_USER" />
<intercept-url pattern="/user/add*" access="ROLE_USER" requires-channel="https"/>
<form-login login-page="/user/add" default-target-url="/" authentication-failure-url="/user/add" />
<port-mappings>
<port-mapping http="8080" https="8181"/>
</port-mappings>
</http>
我正在使用 Glassfish 4.0、Spring MVC 和 Spring Security 3.0
当我单击按钮进入/user/add 页面时,出现此错误:
ERR_TOO_MANY_REDIRECTS
有什么建议吗?
最佳答案
由于您将登录页面设置为“/user/add”(当然,这不是页面 - 您应该将此地址设置为真实的登录页面),因此您获得了太多重定向。但是,当用户到达此地址时,他会被阻止,因为您将“/user/add*”定义为需要进行身份验证的安全资源之前的行。身份验证失败,然后用户被重定向到“/user/add”,因为这被定义为“authentication-failure-url”。
这就是解释。
希望有帮助:-)
PS,如果您想查看如何做您想做的事情的示例,请查看 here (搜索“表单登录”)
关于java - Spring Security HTTPs - 尝试使用 https 登录时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22046180/