【问题标题】:In Spring Security, Can we use nested <intercept-url>?在 Spring Security 中,我们可以使用嵌套的 <intercept-url> 吗?
【发布时间】:2015-01-06 18:14:45
【问题描述】:

我的要求如下:

假设“dbservice”下有许多 url。例如 1. /db服务/添加 2. /dbservice/更新 3. /dbservice/remove 等

因此,对于每个 url,我必须编写单独的行(考虑到它们具有不同的访问级别)。 所以它看起来像这样:

<security:intercept-url pattern="/dbservice/add" access="permitAll"/>
<security:intercept-url pattern="/dbservice/update" access="isAuthenticated"/>
<security:intercept-url pattern="/dbservice/remove" access="hasRole('ROLE_ADMIN')"/>

如果字符串 dbservice 发生变化,那么我必须在所有我不想要的地方更新。

有没有办法让我只声明一次 dbservice,我会在详细的 url 中使用一些变量,或者可能是这样的:

<security:intercept-url pattern="/dbservice">
         <security:intercept-url pattern="/add" access="permitAll"/>
         <security:intercept-url pattern="/remove" access="hasRole('ROLE_ADMIN')"/>
</security:intercept-url>

还要考虑 http 中的其他标签,例如 custom-filter 和 remember-me。

【问题讨论】:

    标签: spring security spring-security


    【解决方案1】:

    这样试试

       <http pattern="/dbservice/**">
            <intercept-url pattern="/add"  access="permitAll" />
            <intercept-url pattern="/remove" access="hasRole('ROLE_ADMIN')" />
       </http>
    

    【讨论】:

    • 您好 Boopathi,感谢您的回复,但其他标签如自定义过滤器和记住我的服务呢?它们将如何工作?
    • 只在 中包含 remember-me 和您的自定义过滤器
    • 我试过了,但是没有用。我想对于每个部分,我们必须明确声明记住我。
    猜你喜欢
    • 2012-08-03
    • 1970-01-01
    • 2017-01-18
    • 2011-10-16
    • 2013-07-03
    • 2021-12-06
    • 1970-01-01
    • 2014-11-28
    • 2011-01-05
    相关资源
    最近更新 更多