views:

74

answers:

1

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?

A: 

Value of the access attribute is a SpEL expression, evaluated against WebSecurityExpressionRoot, so you can use all its methods and all SpEL syntax.

Also you can customize creation of the evaluation context by declaring a custom WebSecurityExpressionHandler as a bean (then you can add your own methods and variables).

axtavt
I use the following to simulate a control statement<security:authorize access="hasRole('ROLE_ADMIN')"> got com admin</security:authorize><security:authorize access="!hasRole('ROLE_ADMIN')"> no com admin</security:authorize>
Blake

related questions