2012-04-10 3 views
3

pattern = hasCollege('college1',college2')のようなインターセプトURLパターンを指定したいと思います。そのために、私は、次のアプローチを考えています:スプリングセキュリティ - カスタムSPELアクセス式を作成します。私のアプローチは正しいのですか?

A)

<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カスタム式ハンドラを使用するようにWebExpressionVoterを設定)EEWebSecurityExpressionHandlerDefaultWebSecurityExpressionHandlerの方法で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)MyWebSecurityExpressionRootWebSecurityExpressionRootを拡張し、新しいSPEL式に対応した新しいメソッドを宣言してください:

public final boolean hasCollege(String... colleges){ 
     // logic goes here 
    } 

は、これは問題にアプローチする正しい方法ですか?

+0

[こちら](http://forum.springsource.org/showthread.php?75331-Configuration-of-Spring-Security-3-0M1-Expression-Handler-bug&p=271798#post271798)と[こちら](http://stackoverflow.com/questions/6632982/how-to-create-custom-methods-for-use-in-spring-security-expression-language-anno) – nobeh

答えて

1

あなたの春のセキュリティ設定では、次のようにすることができます。

<http use-expressions="true"> 
    <intercept-url pattern="/**" access="isFullyAuthenticated() and principal.college matches 'Duke|USC'"/> 

これは、あなたのpricipalにgetCollege()メソッドがあると仮定しています。

関連する問題