【问题标题】:specify variable context path in spring security (3.0.x)在 Spring Security (3.0.x) 中指定变量上下文路径
【发布时间】:2012-01-16 18:17:10
【问题描述】:

我们正在开发“盒子”网络产品,所以我无法预见应用程序的部署环境。此应用程序使用 spring-security。但似乎如果 Tomcat 将应用程序不在根目录下,则以下配置失败:

<sec:http auto-config="true" >
    ....
    <sec:form-login login-page="/ui/Login" />

以下推荐:https://stackoverflow.com/a/6934712/149818 使用

#{servletContext.contextPath} 不起作用。用户而不是 http://foo/myApp/ui/Login 被重定向到 http://foo/ui/Login

所以我的问题是

  • 如何让#{servletContext.contextPath} 活着
  • 或如何强制 spring-security 识别实际 contextPath

【问题讨论】:

  • 我很确定上下文路径会自动添加到login-page。您使用哪个版本的 Spring Security?
  • 这听起来不对。处理重定向的LoginUrlAuthenticationEntryPoint 类将始终包含上下文路径作为 URL 的一部分(例如,示例应用程序具有上下文路径)。您能否发布发生重定向的调试日志的相关部分?您通常应该看到来自ExceptionTranslationFilter 的消息,如the FAQ 中所述,不久之后是“重定向到”,后跟 URL。
  • @Luke Taylor - 非常感谢。自从我开始记录以来,一切都变得正确 - 我失去了 root '/' 看看我的自我回答

标签: tomcat spring-security contextpath


【解决方案1】:

非常感谢@Luke Taylor 和@axtavt - 我的错误是在

<sec:http auto-config="true" use-expressions="true">
     <sec:intercept-url pattern="/ui/Login" 
                        access="IS_AUTHENTICATED_ANONYMOUSLY"/>

当 '/' 出现时 - #{servletContext.contextPath} 开始正常工作。

【讨论】:

    猜你喜欢
    • 2022-01-25
    • 2012-09-24
    • 2014-10-29
    • 1970-01-01
    • 2016-01-11
    • 2012-07-30
    • 2011-04-25
    • 1970-01-01
    • 2020-12-12
    相关资源
    最近更新 更多