Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Security Taglibs control statement

Is there a way to implement control statement with Spring Security taglibs?

Currently we can only check if a user has a role...

<security:authorize access="hasRole('ROLE_ADMIN')">
   // display something
</security:authorize>

How about else?

like image 438
Blake Avatar asked May 17 '10 11:05

Blake


People also ask

What is Spring Security Taglibs?

Spring Security has its own taglib which provides basic support for accessing security information and applying security constraints in JSPs.

What is the purpose of the security authorize /> tag?

Authorize Tag This tag is used for authorization purpose. This tag evaluates and check whether the request is authorized or not. It uses two attributes access and URL to check request authorization.

Which of the following tags are used to secure View layer of application in spring?

In Spring MVC applications using JSP, we can use the Spring Security tags for applying security constraints as well as for accessing security information. Spring Security Tag library provides basic support for such operations.


1 Answers

The question is old, but anyway..

You can store the result of tag evaluation into variable (at least at version 3.1) and then use it within standard if/else construction. I think this is more useful solution than previous one.

<security:authorize access="hasRole('ROLE_ADMIN')" var="isAdmin" />
<c:choose>
   <c:when test="${isAdmin}">superuser</c:when>
   <c:otherwise>ordinary user</c:otherwise>
</c:choose>
like image 99
nKognito Avatar answered Jan 19 '23 05:01

nKognito