【问题标题】:Custom SecurityExpressionRoot method with Spring Security 3.1.3使用 Spring Security 3.1.3 自定义 SecurityExpressionRoot 方法
【发布时间】:2013-01-03 15:23:39
【问题描述】:

我正在将我的 Spring Security 从 3.1.0 升级到 3.1.3,并遇到了一个破坏我设置的更改。

我一直在使用自定义 SecurityExpressionRoot 来公开用于拦截 URL 条目的方法。

 <http entry-point-ref="forbiddenAccessEntryPoint" use-expressions="true" create-session="never"
      access-decision-manager-ref="webAccessDecisionManager">

    <intercept-url pattern="/licenses*" access="hasProjectAuthority('LICENSES')"/>

SecurityExpressionRoot 是通过自定义 DefaultMethodSecurityExpressionHandler 注入的。

这在 3.1.0 中运行良好,但升级到 3.1.3 后 Spring 无法评估“hasProjectAuthority”方法:

EL1004E:(pos 0):方法调用:在 org.springframework.security.web.access.expression.WebSecurityExpressionRoot 类型上找不到方法 hasProjectAuthority(java.lang.String)

这是移动到某个地方了吗?

【问题讨论】:

    标签: spring-security


    【解决方案1】:
    • 尝试将您的代码从自定义 SecurityExpressionRoot 移动到自定义 WebSecurityExpressionRoot。
    • 确保您的自定义 WebSecurityExpressionRoot 通过 DefaultWebSecurityExpressionHandler.createSecurityExpressionRoot 注入到您的 WebExpressionVoter

    您的 xml 可能如下所示:

    <security:http access-decision-manager-ref="customAccessDecisionManagerBean">
        ....
    <security:http/>
    
    <bean id="customWebSecurityExpressionHandler" class="com.domain.security.CustomWebSecurityExpressionHandler"/>
    <bean id="customAccessDecisionManagerBean" class="org.springframework.security.access.vote.AffirmativeBased">
        <property name="decisionVoters">
            <list>
                <bean class="org.springframework.security.web.access.expression.WebExpressionVoter">
                    <property name="expressionHandler" ref="customWebSecurityExpressionHandler" />
                </bean>
            </list>
        </property>
    </bean>
    

    【讨论】:

    • 我将它切换到 WebSecruityExpressionRoot 而不仅仅是 SecurityExpressionRoot 但它没有帮助。同样的问题。
    • 它通过自定义 SecurityExpressionHandler 注入到您的 WebExpressionVoter 中?
    • 它由 DefaultMethodSecurityExpressionHandler(即 SecurityExpressionHandler)的 createSecurityExpressionRoot 方法返回
    • 您需要使用 DefaultWebSecurityExpressionHandler.createSecurityExpressionRoot 而不是 DefaultMethodSecurityExpressionHandler.createSecurityExpressionRoot 因为您想保护 URL,而不是方法调用
    猜你喜欢
    • 2022-10-19
    • 2018-10-09
    • 2016-05-18
    • 1970-01-01
    • 2018-02-20
    • 2013-10-29
    • 2014-12-04
    • 2018-11-26
    • 2016-09-04
    相关资源
    最近更新 更多