Equivalent to the deprecated ifNotGranted attribute

前端 未结 2 1776
伪装坚强ぢ
伪装坚强ぢ 2021-02-14 04:37

I would like to prevent an image having a link if a user does NOT have a certain role. e.g.



        
相关标签:
2条回答
  • 2021-02-14 04:59

    In case if you have many files to update, I recommend use the regular express to search and replace

    find

    <sec:authorize\s+ifAnyGranted="([^"]+)"
    

    replace with

    <sec:authorize access="hasAnyRole('$1')"
    

    and search

    <sec:authorize\s+ifNotGranted="([^"]+)"
    

    replace with

    <sec:authorize access="!hasAnyRole('$1')"
    

    Hope this can save you time

    0 讨论(0)
  • 2021-02-14 05:18

    SpEL expression can be negated with ! operator:

    <sec:authorize access="!hasRole('ROLE_ACCOUNTS')">...</sec:authorize> 
    

    See also:

    • 6. Spring Language (SpEL)
    0 讨论(0)
提交回复
热议问题