Search code examples
grailsgrails-domain-classgrails-controller

Dynamically change menu according to user role in Grails?


I want to display different menu according to login user . If user is client then display different menu otherwise show different menu.

I have one table User which is used to authenticate user , Client table which hold the userId as foreign key . Then how we determine whether user is client or not?

Another there is any way to add controller for menu?


Solution

  • One of the best ways would be to use Spring Security plugin. Once setup (which is easy and there is good documentation around) you can control content based on user/roles in a couple ways:

    • In the controller - pass different menu options to the view based on the output of ifAllGraanted('ROLE_ADMIN') function
    • Directly in the view - <sec:ifAllGranted roles="ROLE_ADMIN">

    More info here: http://grails-plugins.github.com/grails-spring-security-core/docs/manual/guide/6%20Helper%20Classes.html