Archive

Posts Tagged ‘grails’

How to customize GUI base on user role with spring security

December 6, 2014 Leave a comment

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
Categories: Java Tags: , ,

How to create a tree main menu in grails

December 4, 2014 Leave a comment

Build the GSP page contain the menu with one div tag named mainMenu

<body>
    <div id="spsLogo" role="banner">
        <a href="http://tranhoangminh.vn"><asset:image src="sps_logo.png" alt="Code Snippet" /></a>
    </div>
    <sec:ifLoggedIn>
        <div class="mainMenu">
            <ul>
                <li><a href="${createLink(uri: '/')}" style="text-decoration: none;"> Home</a></li>
                <li><a href="#">Resource </a>
                    <ul>
                        <li><a href="${createLink(action:'index', controller:'customer')}" style="text-decoration: none">Customer</a></li>
                        <li><a href="${createLink(action:'index', controller:'project')}" style="text-decoration: none">Project</a></li>
                        <li><a href="${createLink(action:'index', controller:'document')}" style="text-decoration: none">Document</a></li>
                        <li><a href="${createLink(action:'index', controller:'contact')}" style="text-decoration: none">Contact</a></li>
                    </ul></li>
                <li><a href="${createLink(action:'index', controller:'Search')}">Search</a></li>
                <li><a href="#">Manager</a>
                    <ul>
                        <li><a href="${createLink(action:'viewUser', controller:'User')}" style="text-decoration: none">Add User </a></li>
                        <li><a href="${createLink(action:'viewRole', controller:'User')}" style="text-decoration: none">Manager Role </a></li>
                    </ul></li>
            </ul>
        </div>
    </sec:ifLoggedIn>
    <g:layoutBody />

    <div class="footer" role="contentinfo">
        <small>&copy; Copyright 2014 CRM | Powered by &nbsp;<a>SPS VietNam</a></small>
    </div>
    <div id="spinner" class="spinner" style="display: none;">
        <g:message code="spinner.alt" default="Loading&hellip;" />
    </div>
</body>

Read more…

Categories: Java Tags: , ,

Configure spring security with ldap authentication and local system roles in grails

December 2, 2014 Leave a comment

Add plugins Add plugins of Spring security and ldap in BuildConfig

plugins {
        compile ":spring-security-core:2.0-RC4"
        compile ":spring-security-ldap:2.0-RC2"
    }

Configure spring security
Configure spring security and LDAP authentication in Config
Read more…

Categories: Java Tags: , , , ,
%d bloggers like this: