2017-08-14 27 views
1

あなたは私がカスタムisTeamMemberというメソッドを定義している見ることができるように、私はMethodSecurityExpressionOperationsの登録方法

public class CustomMethodSecurityExpressionRoot extends SecurityExpressionRoot implements MethodSecurityExpressionOperations { 
     private Object filterObject; 
     private Object returnObject; 

     CustomMethodSecurityExpressionRoot(Authentication authentication) { 
      super(authentication); 
     } 

     public boolean isTeamMember(Job job) { 
      //very interesting logic 
     } 

     @Override 
     public Object getFilterObject() { 
      return this.filterObject; 
     } 

     @Override 
     public Object getReturnObject() { 
      return this.returnObject; 
     } 

     @Override 
     public Object getThis() { 
      return this; 
     } 

     @Override 
     public void setFilterObject(Object obj) { 
      this.filterObject = obj; 
     } 

     @Override 
     public void setReturnObject(Object obj) { 
      this.returnObject = obj; 
     } 
    } 

の次の実装を持っています。このメソッドは、次の事前承認アノテーションによって正常に評価されます。@PreAuthorize("isTeamMember(#job)")ただし、残念ながらSpring SpEL関数としては解決されません。

see the warning

SPEL機能としてisTeamMemberを登録するための任意の春Bootishオートマジック方法はありますか?私はこれを言うだろう

答えて

0

はのIntelliJ IDEAの懸念とSPELでFunctionサポートに完全に無関係です:

あなたが式の文字列の中に呼び出すことができるユーザー定義関数を登録することにより、SPELを拡張することができます。

SpEL、Spring Framework、またはSpring Boot側からは何もありません。必要なのはすでにCustomMethodSecurityExpressionRoot経由であるからです。

あなたのWARNにあるものは、SpEL評価コンテキストのルートオブジェクトに関するIDEAの知識があなたのカスタムCustomMethodSecurityExpressionRootスコープ外のポインタです。

#this.isTeamMember(#obj)または#root.isTeamMember(#obj)と同じ結果が得られる場合もありますが、それでも機能については何もありません。自分を混乱させないでください。

関連する問題