我正在使用带有 namespace 配置的 spring security3.1。如果我在浏览器中输入上下文路径之前的 URL,而不是登录页面的完整 URL,我想重定向到登录页面。
例如,http://xxx:8080/context/
改为 http://xxx:8080/context/login.html
我能够显示带有完整 URL 的登录页面 http://localhost:8080/context/login.html
我尝试过以下代码:
<http auto-config='true' authentication-manager-ref="authentication-manager" entry-point-ref="authenticationEntryPoint">
<beans:bean id="authenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
<beans:property name="loginFormUrl" value="/login.html"/>
<beans:property name="forceHttps" value="true"/>
</beans:bean>
....
我添加了一个 LoginUrlAuthenticationEntryPoint
条目,以便也重定向到登录页面,但它似乎不起作用。
最佳答案
如果添加一些安全限制,标准配置将重定向到登录页面。所以使用
<http use-expressions="true">
<intercept-url pattern="/**" access="isAuthenticated()" />
<form-login />
</http>
如果您请求任何 URL,您将自动重定向到登录页面。您不需要配置 AuthenticationEntryPoint
。
在尝试自定义内容之前,请确保您可以获得基本的示例。
此外,您的配置无效 - 您只发布了 http
block 的开始元素。如果您仍然无法让它工作,请发布重现您的问题的完整配置。
关于spring-security - spring security 3.1-使用上下文url重定向到登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11613389/