I have something like 开发者_如何学Gothis
<c:forEach var="authority" items="#{SPRING_SECURITY_CONTEXT.authentication.principal.authorities}">
<c:if test="${fn:contains( ${authority} , ROLE_ADMIN) }">
</c:if>
</c:forEach>
but it does not working, any ide how can I make this? Maybe there is some other way?
//Edited
There are 2 problems:
You should not nest EL expressions. Just reference the EL variable the usual way.
<c:if test="${fn:contains(authority, ROLE_ADMIN)}">
It's not clear from the question context if
ROLE_ADMIN
is already in the EL scope. But you need to know that you cannot reference constants in EL. If it's for example anenum
, then it's good to know that they are just evaluated asString
. You need to quote it then.<c:if test="${fn:contains(authority, 'ROLE_ADMIN')}">
You're missing a closing ")" in your if test:
<c:forEach var="authority" items="#{SPRING_SECURITY_CONTEXT.authentication.principal.authorities}">
<c:if test="${fn:contains( {$authority} , ROLE_ADMIN ) }">
</c:if>
</c:forEach>
精彩评论