我希望指定一个拦截 URL 模式,例如pattern = hasCollege('college1',college2')
. 为此,我正在考虑以下方法:
a) 配置WebExpressionVoter
为使用自定义表达式处理程序
<beans:bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
<beans:property name="decisionVoters">
<beans:list>
<beans:bean class="org.springframework.security.web.access.expression.WebExpressionVoter">
<beans:property name="expressionHandler" ref="myWebSecurityExpressionHandler"/>
</beans:bean>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="myWebSecurityExpressionHandler" class="com.daud.security.EEWebSecurityExpressionHandler"/>
b)以设置自定义根对象的方式实现EEWebSecurityExpressionHandler
和使用。WebSecurityExpressionHandler
DefaultWebSecurityExpressionHandler
createEvaluationContext
@Override
public EvaluationContext createEvaluationContext(Authentication authentication, FilterInvocation fi) {
StandardEvaluationContext ctx = new StandardEvaluationContext();
SecurityExpressionRoot root = new MyWebSecurityExpressionRoot(authentication, fi);
root.setTrustResolver(trustResolver);
root.setRoleHierarchy(roleHierarchy);
ctx.setRootObject(root);
return ctx;
}
c)MyWebSecurityExpressionRoot
扩展WebSecurityExpressionRoot
并声明一个对应于新 SPEL 表达式的新方法:
public final boolean hasCollege(String... colleges){
// logic goes here
}
这是解决问题的正确方法吗?