4

我正在将我的 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)

这是否移动到某个地方?

4

1 回答 1

7
  • 尝试将您的代码从自定义 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>
于 2013-01-03T15:50:29.133 回答