这是不可能的。但还有另一种方法。你可以定义你自己的web表达式,它将负责从URL中提取id参数。它可能看起来像这样:
<security:intercept-url pattern="/user/{id}/edit" access="getIdUrlPathParameter() == principal.userId"/>
要做到这一点,你需要:扩展WebSecurityExpressionRoot
2.添加getIdUrlPathParameter()方法
1.添加CustomWebSecurityExpressionRoot。它将有权访问HttpServletRequest对象。
3.定义可扩展的CustomWebSecurityExpressionHandler DefaultWebSecurityExpressionHandler。重写createSecurityExpressionRoot方法abd在这里使用您的CustomWebSecurityExpressionRoot。
4.定义自定义访问决策管理器(如下XML)
5.通过访问决策管理-ref属性
<security:http access-decision-manager-ref="customAccessDecisionManagerBean" >
<security:intercept-url pattern="/user/{id}/edit" access="getIdUrlPathParameter() == principal.userId"/>
</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>
想我发现了这把它注射到你的HTTP元素,但事实并非如此工作 http://forum.springsource.org/showthread.php?130413-Web-Security-Expressions-and-PathVariables – knoma