Thymelaf and Spring Security - custom SpEL expression

Inweo

I'm using Thymeleaf with spring security. In html code I'm checking user role:

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

but in spring I implemented own CustomSecurityExpressionRoot so I can use in controller for example

@PreAuthorize("hasAccess('PERMISSION')")

It is possible to connect Thymeleaf to be able to use hasAccess (and others) methods from my CustomSecurityExpressionRoot?

holmis83

I would have put the logic in a singleton Spring bean:

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

And then in Thymeleaf code:

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

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Accessing nested headers with Spring Expression Language (SpEL)

分類Dev

spEL(Spring Expression Language)の有効な用途は何ですか?

分類Dev

Spring Expression Language(SpEL)で2つの文字列を連結する方法

分類Dev

Spring security custom login redirection conflict

分類Dev

Configuring a Custom LDAP Authentication Provider with Spring Security

分類Dev

Spring security custom authentication provider not working

分類Dev

Spring Expression Language(SpEL)がJPA / Hibernateエンティティで機能しない

分類Dev

Spring Expression Language(SpEL)がJPA / Hibernateエンティティで機能しない

分類Dev

org.springframework.expression.spel.SpelEvaluationException

分類Dev

Autowiring of Services not working in Spring Security Java config Custom Auth provider

分類Dev

Spring Security Oauth 2 custom token end point url

分類Dev

SPRING java.lang.NoSuchMethodError:クォーツスケジュールの追加後のorg.springframework.expression.spel.SpelParserConfiguration

分類Dev

Springマイクロサービス-原因:java.lang.ClassNotFoundException:org.springframework.expression.spel.support.SimpleEvaluationContext

分類Dev

Spring Session and Spring Security

分類Dev

ロールのためのSpring Spel

分類Dev

java 8 spring spEL repeatable binding slows each iterations

分類Dev

java 8 spring spEL repeatable binding slows each iterations

分類Dev

Spring EL(SpEL)コードの実行

分類Dev

Spring - SpEL evaluates entity argument as null reference in @PreAuthorize("hasPermission")

分類Dev

Spring - SpEL evaluates entity argument as null reference in @PreAuthorize("hasPermission")

分類Dev

Spring @Cacheable with Ehcache、spel find null for valid object

分類Dev

Spring Expression Language(SPEL)は、指定されたアノテーションを持つBeanフィールドへのアクセスを制限します

分類Dev

Blazor Security - Razor Pages custom authentication/security

分類Dev

Maven:Spring 4 + Spring Security

分類Dev

Spring SecurityのAuthenticationSuccessHandler

分類Dev

Spring Security Java Config

分類Dev

Authenticate user with Spring Security

分類Dev

Spring Security - Oauth implementations

分類Dev

Spring Security BadCredentialsException

Related 関連記事

  1. 1

    Accessing nested headers with Spring Expression Language (SpEL)

  2. 2

    spEL(Spring Expression Language)の有効な用途は何ですか?

  3. 3

    Spring Expression Language(SpEL)で2つの文字列を連結する方法

  4. 4

    Spring security custom login redirection conflict

  5. 5

    Configuring a Custom LDAP Authentication Provider with Spring Security

  6. 6

    Spring security custom authentication provider not working

  7. 7

    Spring Expression Language(SpEL)がJPA / Hibernateエンティティで機能しない

  8. 8

    Spring Expression Language(SpEL)がJPA / Hibernateエンティティで機能しない

  9. 9

    org.springframework.expression.spel.SpelEvaluationException

  10. 10

    Autowiring of Services not working in Spring Security Java config Custom Auth provider

  11. 11

    Spring Security Oauth 2 custom token end point url

  12. 12

    SPRING java.lang.NoSuchMethodError:クォーツスケジュールの追加後のorg.springframework.expression.spel.SpelParserConfiguration

  13. 13

    Springマイクロサービス-原因:java.lang.ClassNotFoundException:org.springframework.expression.spel.support.SimpleEvaluationContext

  14. 14

    Spring Session and Spring Security

  15. 15

    ロールのためのSpring Spel

  16. 16

    java 8 spring spEL repeatable binding slows each iterations

  17. 17

    java 8 spring spEL repeatable binding slows each iterations

  18. 18

    Spring EL(SpEL)コードの実行

  19. 19

    Spring - SpEL evaluates entity argument as null reference in @PreAuthorize("hasPermission")

  20. 20

    Spring - SpEL evaluates entity argument as null reference in @PreAuthorize("hasPermission")

  21. 21

    Spring @Cacheable with Ehcache、spel find null for valid object

  22. 22

    Spring Expression Language(SPEL)は、指定されたアノテーションを持つBeanフィールドへのアクセスを制限します

  23. 23

    Blazor Security - Razor Pages custom authentication/security

  24. 24

    Maven:Spring 4 + Spring Security

  25. 25

    Spring SecurityのAuthenticationSuccessHandler

  26. 26

    Spring Security Java Config

  27. 27

    Authenticate user with Spring Security

  28. 28

    Spring Security - Oauth implementations

  29. 29

    Spring Security BadCredentialsException

ホットタグ

アーカイブ