Results 1 to 8 of 8

Thread: Hide menu items based on the authentication

  1. #1
    Join Date
    Apr 2012
    Posts
    17

    Default Hide menu items based on the authentication

    Hi,

    I created a CRUD UI for several entities and i want to hide/show menu items based on the spring security based authentication. Can somone please tell me an efficeint way of doing this??

    Thank you in advance.

  2. #2
    Join Date
    Jan 2010
    Location
    Mislata - Valencia - Spain
    Posts
    162

    Default

    gvNIX menu addon can help you:

    http://code.google.com/p/gvnix/wiki/DocMenu

    Grant page access to roles from Roo shell.
    Currently, for Roo 1.1.5 versions.
    Mario Martínez Sánchez
    Project Manager & Software Architect
    --------------------------
    Disid Technologies S.L.
    http://www.disid.com
    --------------------------
    gvNIX
    http://gvnix.googlecode.com
    http://www.gvnix.org

  3. #3
    Join Date
    Jun 2008
    Location
    Philadelphia, PA, USA
    Posts
    212

    Default

    Quote Originally Posted by pathfinder92 View Post
    Hi,

    I created a CRUD UI for several entities and i want to hide/show menu items based on the spring security based authentication. Can somone please tell me an efficeint way of doing this??

    Thank you in advance.
    If you've installed the Spring Security configurarion, you can use the security tags to wrap those methods. See the Spring Security taglib documentation.

    Ken
    Ken Rimple
    Chariot Solutions
    email: krimple@chariotsolutions.com
    work: www.chariotsolutions.com/education
    personal: www.rimple.com

    Author: Spring Roo in Action (Manning)
    MEAP Site: manning.com/rimple

  4. #4
    Join Date
    Apr 2012
    Posts
    17

    Default

    Hi,
    thank you for replying. I installed spring security configuraton and implmented the login page using an external database. Where should i used the taglibs??? I tried to edit menu.jspx using the 'authorize' to wrap the menu items. But it didn't work.

  5. #5
    Join Date
    Jun 2008
    Location
    Philadelphia, PA, USA
    Posts
    212

    Default

    Quote Originally Posted by pathfinder92 View Post
    Hi,
    thank you for replying. I installed spring security configuraton and implmented the login page using an external database. Where should i used the taglibs??? I tried to edit menu.jspx using the 'authorize' to wrap the menu items. But it didn't work.
    Any page you want. Can you post a snippet? What happens when Roo hits that tag, do you get a stack trace, or a blank page, or what?
    Ken Rimple
    Chariot Solutions
    email: krimple@chariotsolutions.com
    work: www.chariotsolutions.com/education
    personal: www.rimple.com

    Author: Spring Roo in Action (Manning)
    MEAP Site: manning.com/rimple

  6. #6
    Join Date
    Apr 2012
    Posts
    17

    Default

    this is the code snippet of menu.jspx

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <div xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:menu="urn:jsptagdir:/WEB-INF/tags/menu" id="menu" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:output omit-xml-declaration="yes"/>
    <menu:menu id="_menu" z="nZaf43BjUg1iM0v70HJVEsXDopc=">
    <sec:authorize ifAllGranted="ROLE_ADMIN">
    <menu:category id="c_topping" z="Xm13w68rCIyzL6WIzqBtcpfiNQU=">
    <menu:item id="i_topping_new" messageCode="global_menu_new" url="/toppings?form" z="e1a5iGUXU+AnmE3TsSiRG0anau4="/>
    <menu:item id="i_topping_list" messageCode="global_menu_list" url="/toppings?page=1&amp;size=${empty param.size ? 10 : param.size}" z="XzlIdR9bro/F4JpeR+A0AAJ/u7g="/>
    </menu:category>
    </sec:authorize>
    <menu:category id="c_pizza" z="mXqKC1ELexS039/pkkCrZVcSry0=">

    <menu:item id="i_pizza_new" messageCode="global_menu_new" url="/pizzas?form" z="FJyKGGTINgIyGIqDihlwLSFEytE="/>
    <menu:item id="i_pizza_list" messageCode="global_menu_list" url="/pizzas?page=1&amp;size=${empty param.size ? 10 : param.size}" z="xeipeDE0x1I+04qwdIrWrLg/6lc="/>
    </menu:category>
    </menu:menu>
    </div>
    when i login as an admin user, home page is shown without a left menu bar. At the same time an exception occurred as shown below. The other menu item is also not visible.

    org.apache.jasper.JasperException: /WEB-INF/views/menu.jspx(6,43) The prefix "sec" for element "sec:
    authorize" is not bound.

  7. #7
    Join Date
    Apr 2012
    Posts
    17

    Default

    Hi,
    i just noticed that i haven't included
    xmlns:sec="http://www.springframework.org/security/tags"
    part in the xml.
    Anyway thanx a lot for replying.

  8. #8
    Join Date
    Jun 2008
    Location
    Philadelphia, PA, USA
    Posts
    212

    Default

    No problem. Was going to point that out as it is a common mistake but you got to it first. Glad to hear you have it working...
    Ken Rimple
    Chariot Solutions
    email: krimple@chariotsolutions.com
    work: www.chariotsolutions.com/education
    personal: www.rimple.com

    Author: Spring Roo in Action (Manning)
    MEAP Site: manning.com/rimple

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •