2 Replies Latest reply on Jan 27, 2010 9:30 AM by superdepor

    Portlet that lists all available portals for a user

    superdepor
      Hope you can help me with this problem,

      I have build a tree of portals under JBOSS-Portal.
      One portal per imaginative customer and also one role for each portal so that only authorized users gets access to the portals.

      What I want now is to create a portlet which lists all the portals a user are authorized against!

      For example user "Kim" is member of "Volov","BMW" and "Audi". So I want my portlet to show urls to those three portals and not the others!

      Thanks!
        • 1. Re: Portlet that lists all available portals for a user

          Approach 1 -

          When you create a portal and assign it the security to be viewed by a role or set or roles, that information is persisted in JBP_OBJECT_NODE_SEC, table of jboss portal schema. This table has 3 columns, PK, ROLE, NODE_KEY. If you query this table and group by role you will get the primary keys of all the portals to which a role is having access.

           

          Once you have got the primary key of portals you can access JBP_OBJECT_NODE table to get the name of portals and construct the URLs to them.

          Now, All the things that I mentioned above have few cons

           

          1- The table JBP_OBJECT_NODE_SEC is not indexed on ROLE, So if your number of portals will grow you will face performance problem

           

          2- There are portal services to get this information and probably accessing the tables directly will not be a good approach in long term(what if portal schema changes).

           

          Approach 2-

           

          1- Find all the Portals created. You can find the context and then get all the children of context to get a list of all the portals.

               To find ur current node

           

          PortalNode root = (PortalNode)request.getAttribute("org.jboss.portal.api.PORTAL_NODE");

            PortalNode portal = root;

            while (portal.getType() != PortalNode.TYPE_CONTEXT)

             {

                mainPage = portal;

                portal = portal.getParent();

             }

          portal.getChildren();

          configurator

          2-  get the domain (see the reference guide) and get the uri for each node

           

          3- Find the RoleSecurityBinding associated with each portal

           

          4- use the getRoleName() to determine that to which role the securtiy binding is asscoiated:

           

          RoleSecurityBinding roleSecurityBinding = getDomainConfigurator().getSecurityBindings(uri);

          roleSecurityBinding.getRoleName() ;

           

           

          Let us (everyone in the forum) know ur thoughts and how u finally did it (if you have something else in your mind).

          • 2. Re: Portlet that lists all available portals for a user
            superdepor

            I'm right now able to list and display all the roles a user are member of and also all my portal urls.


            this is the code

             

            MembershipModule membershipModule = (MembershipModule) new InitialContext().lookup("java:portal/MembershipModule

            Iterator iterator = membershipModule.getRoles(request.getUser()).iterator();
            //displays all roles the user are member of

            while (iterator.hasNext()) {

                 html.write("these are your roles, " + iterator.next().toString()    + "<br />");

            }

            //this code part will display links for all the portals

            PortalNode pn= request.getPortalNode().getRoot();          
            for(Object objPage : pn.getChildren()){
                if(objPage instanceof PortalNode){
                     PortalNode page = (PortalNode)objPage;
                      if(page.getType() == PortalNode.TYPE_PORTAL){
                          PortalNode childPN= page.getChild("default");

             

                          PortalNodeURL pURL = response.createRenderURL(childPN);
                          html.write("<a  href=\"" + pURL + "\">" +page.getDisplayName(request.getLocale()) + "</a><br/>");

                     }

                 }

            }

             

             

            I have tried the bellow code but got Null pointer exception at authorizationDomainRegistry.getDomain(); any idead?

             

            AuthorizationDomain authorizationDomain= authorizationDomainRegistry.getDomain(pnu.toString());// also tried with pURL.toString()

            PermissionRepository pr= authorizationDomain.getPermissionRepository();

            Iterator i= membershipModule.getRoles(request.getUser()).iterator();

            while (i.hasNext()) {

                 PortalPermission portalPermission = pr.getPermission(iterator.next().toString(), pURL.toString());

                 //haven't started to code this part..

            }