0

I try to replace

<div sec:authorize="hasRole('ADMIN')"></div>

by

<div sec:authorize="hasRole(${T(com.mypackage.Role).ADMIN.getText()})"></div>

but it does not work. Then I tried

<div th:with="role=${T(com.mypackage.Role).ADMIN.getText()}" sec:authorize="hasRole(${role})"></div>

and with preprocessing

<div th:with="role=${T(com.mypackage.Role).ADMIN.getText()}" sec:authorize="hasRole(__${role}__)"></div>

but is still not working.

Kevin O.
  • 355
  • 3
  • 11

2 Answers2

1

Something like this should work:

<div th:if="${#authorization.expression('hasRole(''' + T(com.mypackage.Role).ADMIN.getText() + ''')')}">
  
</div>

(I don't think the sec: attributess interpret Thymeleaf expressions same as other tags... at least I couldn't find any examples of it.)

Metroids
  • 18,999
  • 4
  • 41
  • 52
1
<div sec:authorize="hasRole(T(com.mypackage.Role).ADMIN)"></div>

Thanks @ChetanAhirrao

Kevin O.
  • 355
  • 3
  • 11