【发布时间】:2012-04-22 16:58:32
【问题描述】:
我希望指定一个拦截 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 以DefaultWebSecurityExpressionHandler 的方式实现WebSecurityExpressionHandler 并使用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
}
这是解决问题的正确方法吗?
【问题讨论】:
标签: java spring spring-security