这是不可能的。但是还有另一种方式。你可以定义自己的网络表达式,该表达式将负责从URL中提取id参数。可能看起来像这样:
<security:intercept-url pattern="/user/{id}/edit" access="getIdUrlPathParameter() == principal.userId"/>为此,你需要:
1.添加扩展WebSecurityexpressionRoot的 CustomWebSecurityexpressionRoot
2.添加getIdUrlPathParameter()方法。它将有权访问HttpServletRequest对象。
3.定义CustomWebSecurityexpressionHandler,以扩展DefaultWebSecurityexpressionHandler。覆盖createSecurityexpressionRoot方法,然后在此处使用CustomWebSecurityexpressionRoot。
4.定义自定义访问决策管理器(下面的xml)
5. 通过access-decision-manager-ref属性将其注入到http元素中
<security:http access-decision-manager-ref="customAccessDecisionManagerBean" > <security:intercept-url pattern="/user/{id}/edit" access="getIdUrlPathParameter() == principal.userId"/></security:http><bean id="customWebSecurityexpressionHandler" /><bean id="customAccessDecisionManagerBean" > <property name="decisionVoters"> <list> <bean > <property name="expressionHandler" ref="customWebSecurityexpressionHandler" /> </bean> </list> </property></bean>


