.:: CODE SNIPPET ::.

"Your time is limited, so don't waste it living someone else's life"

How to customize GUI base on user role with spring security


To restrict user from seeing one or more parts on any page you can use a function of spring security that check user login ‘s role. Snippet below is an example of the granted authority checking:

<sec:ifAnyGranted roles="ROLE_ADMIN">
    <li><g:link class="create" action="create">
            <g:message code="default.new.label" args="[entityName]" />
        </g:link></li>
</sec:ifAnyGranted>

The code restrict user from access a button with user role to only ADMIN. If we pre-define the role hierarchy of roles in system, we just only specify one role, otherwise you have to declare all the roles that can see the inside elements.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: