【问题标题】:Spring security 3 intercept-url pattern with index带有索引的 Spring Security 3 拦截 URL 模式
【发布时间】:2015-04-08 22:59:17
【问题描述】:

我正在尝试将 Spring Security v3.2 用于项目。目前我总是使用一个coldfusion文件来调用其他文件来构建视图。所以我所有的网址都通过index.cfm?blablah

现在我坚持允许匿名用户进入主视图。跟着Spring Security request matcher is not working with regex,我编了这段代码:

<http use-expressions="true">
    <intercept-url pattern="^.*index.cfm\?action=home.*$" access="permitAll" />
    <intercept-url pattern="/root/index.cfm" access="isAuthenticated()" />
    <intercept-url pattern="/**" access="isAuthenticated()" />
    <form-login />
</http>

但无论我尝试什么,我总是输入登录字段。

【问题讨论】:

  • 这很正常,你的规则说总是输入登录字段。看看你的最后一条规则。你有没有用 intercept-url 测试你的正则表达式?我想,为什么不呢,比如:&lt;http pattern="^.*index.cfm\?action=home.*$" security="none"/&gt;
  • 自己发现后才看到你的答案。但是你还需要一个 request-matcher 属性,因为 request-matcher 默认是 'ant'。

标签: regex spring spring-security


【解决方案1】:

经过更多尝试,我找到了解决方案:

<http request-matcher="regex" pattern="^.*index.cfm\?action=home.*$" security="none"/>

<http use-expressions="true">
    <intercept-url pattern="/root/index.cfm" access="isAuthenticated()" />
    <intercept-url pattern="/root/**" access="permitAll" />
    <intercept-url pattern="/**" access="isAuthenticated()" />
    <form-login />
 </http>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-11
    • 2013-06-17
    • 2012-08-15
    • 2013-06-04
    • 1970-01-01
    • 1970-01-01
    • 2023-01-30
    • 1970-01-01
    相关资源
    最近更新 更多