-
1. Re: Portlet that lists all available portals for a user
vineet_tripathi Jan 26, 2010 6:24 AM (in response to superdepor)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 Jan 27, 2010 9:30 AM (in response to vineet_tripathi)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 ofwhile (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/>");}
}
}
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..
}