3 Replies Latest reply on Jun 21, 2007 9:31 AM by Andrew Brownfield

    Portlet customization with respect to user rloes

    Georges MAHOP Newbie

      Hi

      I'am trying to customize a portlet with respect to user roles. To do so, i am using the "isUserInRole" method. Here is a sample of my jsp code :

      <%if(request.isUserInRole("Administrators")){ %>
       <a href="<portlet:renderURL .....
      <%}%>
      


      I've also tried the "renderRequest" but the result is the same: isUserInRole always returns false, it doesn't matter the role i use to log in.

      i am using jboss portal 2.4 with its default configuration.

      Do i have to modify the portlet.xml file?

        • 1. Re: Portlet customization with respect to user rloes
          Thomas Heute Master

          Yes please read the section "PLT.20.3 Programmatic Security"
          of the portlet spec.


          You must define the role Administrator in your portlet.xml descriptor.

          • 2. Re: Portlet customization with respect to user rloes
            Andrew Brownfield Newbie

            I am having problems with the same thing, actually.

            web.xml contains:

            <security-role>
             <description/>
             <role-name>Administrators</role-name>
            </security-role>
            <security-role>
             <description/>
             <role-name>Users</role-name>
            </security-role>
            

            portlet.xml contains:
            <security-role-ref>
             <role-name>Users</role-name>
             <role-link>Users</role-link>
            </security-role-ref>
            <security-role-ref>
             <role-name>Administrators</role-name>
             <role-link>Administrators</role-link>
            </security-role-ref>
            

            and I'm trying to run the following code:
            if(request.isUserInRole("Administrators"))
             System.out.println("Administrators");
            else if(request.isUserInRole("Users"))
             System.out.println("Users");
            else
             System.out.println("user is in an unknown role");
            



            The final else clause catches everything, no matter which account logs in. I've tried this in many different ways, changing capitalization and whether or not there is an 's' on the end. Nothing has worked so far.

            Is there something I'm missing in the XML configs?

            • 3. Re: Portlet customization with respect to user rloes
              Andrew Brownfield Newbie

              D'OH! Forgot that there is both a role-name and a display role-name. I was going by the display role-names in the provided Role Management portlet.

              Sorry for the stupidity and waste of forum space.


              --Andrew