Results 1 to 4 of 4

Thread: Tiles menu items + Acegi

  1. #1
    Join Date
    Sep 2006
    Location
    San Jose, Costa Rica
    Posts
    16

    Default Tiles menu items + Acegi

    I have the following code:

    Code:
            <definition name="access_page" page="/WEB-INF/jsp/template.jsp" >        
     			<put name="window.html.title" value="My App"/>       
                <put name="selected" value="perm.do"/>        
            	<putList name="tabList">
    				<item value="Tab 1" tooltip="Tab 1 Tooltip" link="tab1.do" icon="/images/permission.gif" classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>        
    				<item value="Tab 2" tooltip="Tab 3 Tooltip" link="tab2.do" icon="/images/role.gif" classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
    				<item value="Tab 3" tooltip="Tab 3 Tooltip" link="tab3.do" icon="/images/group.gif" classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
    			</putList>
            </definition>
    An thats how I "paint" the menu in the template page:

    Code:
    			<c:forEach items="${tabList}" var="item">
    				<!-- 
    				 unless item.link is the same as 'selected',
    				 menu class is the default class (inherits CSS from elsewhere) 
    				 -->
    				<c:set var="menuClass" value=""/>					
    				<c:if test="${item.link eq selected}">
    					<c:set var="menuClass" value="itemSelected"/>
    				</c:if>
    				<li class="${menuClass}">
    					<a href="${item.link}">
    						<img src="<c:url value="${item.icon}"/>" width="25" height="25"  
    							class="navicon" alt="${item.tooltip}" /> 
    						${item.value}
    					</a>
    				</li>				
    			</c:forEach>
    I want to create a menu, but just display menu items to the user according the roles assigned to this user.

    Im using Acegi + Spring 2.0 and I want use tiles. How can I set up the tiles definition to decide which menu items will be displayed to the user?

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Acegi does have a taglib for things like <authz:authorize ifAnyGranted="ROLE_ADMIN"> which will do the permissions checks for you. Not sure if you use them with tiles though.

  3. #3
    Join Date
    Sep 2006
    Location
    San Jose, Costa Rica
    Posts
    16

    Default

    Thanks for your reply,

    The problem is that in the tiles definition I don't know how to add the necessary information to use the Acegi Taglib.

    If I have a menu like this:

    Item 1 | Item 2 | Item 3
    ------------------------


    Suppose the user with role ADMIN can see only Item1 and, role USER can see only Item 2 and Item 3.

    I set up a list in the tiles definitions, and I use a forEach in the JSP to render the menu. I don't see how to use the acegi taglib in this case.

  4. #4
    Join Date
    Sep 2006
    Location
    San Jose, Costa Rica
    Posts
    16

    Exclamation

    I found a solution. Create more than one role, a list per system role. And when I will go to render the page I can use the Acegi taglib depending on which list I'm rendering.

    if auth = roleA
    forEach
    render menu here
    endif

    if auth = roleB
    forEach
    render menu here
    endif

    I think the best solution for my problem is as following:


    Code:
    			<c:forEach items="${tabList}" var="item">
    				<!-- 
    				 unless item.link is the same as 'selected',
    				 menu class is the default class (inherits CSS from elsewhere) 
    				 -->
    				<c:set var="menuClass" value=""/>					
    				<c:if test="${item.link eq selected}">
    					<c:set var="menuClass" value="itemSelected"/>
    				</c:if>
    				<authz:authorize ifAnyGranted="${item.roles}">
    				<li class="${menuClass}">
    					<a href="${item.link}">
    						<img src="<c:url value="${item.icon}"/>" width="25" height="25"  
    							class="navicon" alt="${item.tooltip}" /> 
    						${item.value}
    					</a>
    				</li>
                                    </authz:authorize>
    			</c:forEach>
    Then, create a class that implements MenuItem interface and add the new attribute "roles" to set up wich roles can see the content.
    Also, its necessary change the template definition in the tiles configuration file.
    Code:
    <item value="Tab 1" tooltip="Tab 1 Tooltip" link="tab1.do" icon="/images/permission.gif" classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
    to
    Code:
    			<bean classtype="tiles.RoleMenuItem" >
    				<set-property property="value" value="Clients"/>
    				<set-property property="tooltip" value="Clients"/>
    				<set-property property="link" value="list_clients.do"/>
    				<set-property property="icon" value="/images/client.png"/>
    				<set-property property="roles" value="ROLE_SALES_ACCT,ROLE_SYSTEM_ADMIN"/>
    			</bean>
    Last edited by fragus; Nov 29th, 2006 at 08:59 AM.

Posting Permissions

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