Hi,
I want to know how to use the API of VAP 7.4 to ask the system that thing if it is possible.
I want to determine witch menuitems and portlets are allowed to one group.
Thanks in advance,
Mario
Mario,
Have you looked at the MenuItemUtils and AuthorizationManager classes?
--Travis
Correction on that last reply. It should be MenuItemUtils and AuthorizationUtils, not AuthorizationManager.
yes I looked that two classes but I don´t know how to get that informatión passing a Group.
The more aproximate solution I found is login with a user from group A and getVisibleNodes of that user and that menuItems are from group A, and use this solution for all groups I need to know...
With this "workarround" I have the menuItems with permission to a Group but I don´t have the portlets inside pages for that groups.
In AuthorizationUtils class I found some methods that can get Permissionable getPermittedObjectIDs but I don´t know how to invoque that method ¿?
Thank you,
Here is some additional information to help with using the API. grantees: Principal is an object that assigns and receives permissions. For example, Users and UserGroups are embedded by objects that implement the Pricipal interface. PrincipleSet is a Set of Principal objects. permissions: A Permission object encapsulates a specific permission and type of object that the permission applies to. For example, Enabled/MenuItems or Dissabled/Portlets. A single Permission cannot apply to differnt types of objects. That is the purpose of PermissionCollection, which is a Collection of Permission objects. The object type that a specific permission applies to corresponds to an AuthorizationSpace. The names for these spaces along with the names for the permissions are available as fields to AuthorizationDictionary. Here are some of the more useful space and permission names. These are required for creating the Permission/PermissionCollection. //spaces SPACE_SYSTEM SPACE_SITE SPACE_PORTLET SPACE_PAGE SPACE_MENU_ITEM //permissions VISIBLE ENABLED NOT_ENABLED context: Permissions only make sense in a specific context. For example, a Portlet or MenuItem shared to multiple Sites can be enabled for a particular group on one site, and dissabled for that same group on another site. AuthorizationContext maps to a Site.
Here is an example to find the UID's for MenuItems and Portlets that are enabled for a specific User (UID) and Site (DNS Name). I have also included the changes (in comments) for aquiring the same for a given UserGroup (UID). Please note that this is provided only as an sample/example demonstrating API usage, and is not gauranteed to work.
<%-- BEGIN permittedObjectIDs.jsp --%> <%@ page import="com.epicentric.common.*, java.io.PrintWriter, com.epicentric.navigation.*, com.epicentric.site.*, java.util.*, com.epicentric.user.*, com.epicentric.authorization.*, com.epicentric.common.website.AuthorizationUtils" contentType="text/html; charset=UTF-8" %> <html> <body> <% try { String siteDNSName = "<SITE_DNS_NAME>"; String userUID = "<USER_UID>"; AuthorizationManager am = AuthorizationManager.getAuthorizationManager(); /** grantees **/ UserManager um = UserManager.getInstance(); User user = um.getUser("uid", userUID); //non-public API PrincipalSet grantees = user.getAllParentPrincipals(false); //or for a specific UserGroup //String userGroupUID = "<USER_GROUP_UID>"; //UserGroupManager ugm = UserGroupManager.getInstance(); //UserGroup userGroup = ugm.getUserGroup("uid", userGroupUID); //PrincipalSet grantees = userGroup.getAllParentPrincipals(true); /** permissions **/ //PermissionList extends PermissionCollection PermissionList permissions = new PermissionList(); //MenuItems that are enabled AuthorizationSpace menuItemSpace = am.getAuthorizationSpace(AuthorizationDictionary.SPACE_MENU_ITEM); Permission em = menuItemSpace.getPermissionByID(AuthorizationDictionary.ENABLED); //Portlets that are enabled AuthorizationSpace portletSpace = am.getAuthorizationSpace(AuthorizationDictionary.SPACE_PORTLET); Permission ep = portletSpace.getPermissionByID(AuthorizationDictionary.ENABLED); //add these to the PermissionCollection permissions.add(em); permissions.add(ep); /** context **/ SiteManager sm = SiteManager.getInstance(); Site site = sm.getSiteFromDNSName(siteDNSName); AuthorizationContext context = (AuthorizationContext) site; Set permittedObjectIDs = AuthorizationUtils.getPermittedObjectIDs(grantees, permissions, context); Iterator i = permittedObjectIDs.iterator(); while(i.hasNext()) { String id = (String) i.next(); out.println(id + "<br>"); } } catch(Exception e) { out.println("<pre>"); e.printStackTrace(new PrintWriter(out)); out.println("</pre>"); } %> <%-- END permittedObjectIDs.jsp --%>
Here are instructions to run this in your environment.1. Create permittedObjectIDs.jsp under the deployed Portal application directory. The location of this directory depends on the appserver product you are using in your environment. Here is a tomcat example. <TOMCAT_HOME>/webapps/portal/permittedObjectIDs.jsp2. Replace the following with a valid Site DNS Name and User UID. <SITE_DNS_NAME> <USER_UID>3. Run this with a web browser by accessing the following address. <PROTOCOL>://<HOST>:<PORT>/<APPLICATION_CONTEXT>/permittedObjectIDs.jsp eg: http://localhost:8080/portal/permittedObjectIDs.jsp
You have helped me a lot. This code was exactly what I need. now I know what menuitems and portlets are enabled for one user or group.
thank you very much!