2017-12-29 37 views
0

私は春のセキュリティでThymeleafを使用しています。 はhtmlコードでは、私は、ユーザーの役割をチェックしています:ThymelafとSpring Security - カスタムSpEL式

<li class="has-sub" sec:authorize="hasRole('ROLE_ADMIN')"> 
</li> 

を私は

@PreAuthorize(「hasAccess(」例えば、コントローラで使用できるように、春に私は自分のCustomSecurityExpressionRootを実装しました許可)」)」)

hasAccess(およびその他のもの)を使用できるようにThymeleafを接続することは可能です私のCustomSecurityExpressionRootのメソッド)?私はシングルトンのSpring Beanにロジックを入れているだろう

答えて

0

@Component 
public class AccessEvaluator { 
    public boolean hasAccess(Authentication authentication, String permission) { 
     // implementation 
    } 
} 

そしてThymeleafコードで:正解です

<li th:if="${@accessEvaluator.hasAccess(#request.userPrincipal, 'PERMISSION')}"> 
</li> 
+0

。そのアイデアの一つの欠点は、マルチマスクhasAccessの実装(Thymeleafとspring [コントローラなど]のため)です。 – Inweo

関連する問題