This is very useful sample code to retrieve user groups of websphere portal 6.0 using PUMA API. There are some changes in PUMA API in 6.1 but the basics still remains the same.
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.portlet.PortletRequest;
import javax.servlet.http.HttpServletRequest;
import com.ibm.portal.portlet.service.PortletServiceHome;
import com.ibm.portal.puma.Group;
import com.ibm.portal.puma.User;
import com.ibm.portal.um.PumaHome;
import com.ibm.portal.um.PumaLocator;
import com.ibm.portal.um.PumaProfile;
import com.ibm.wps.pe.pc.std.core.PortletUtils;
public class GroupInformation {
public List getUserGroups(PortletRequest prequest){
//Start get the servlet request from the portlet request
HttpServletRequest httpRequest = null;
try{
httpRequest = PortletUtils.getIncludeServletRequest(prequest);
}
catch (Exception e){
e.printStackTrace();
}
//End
PortletServiceHome psh;
PumaHome pumahome = null;
List groupsNames = new ArrayList();
try{
javax.naming.Context context = new javax.naming.InitialContext();
psh = (PortletServiceHome) context.lookup ("portletservice/com.ibm.portal.um.portletservice.PumaHome");
if (psh != null)
pumahome = (PumaHome) psh.getPortletService(PumaHome.class);
PumaProfile pumaprofile = (PumaProfile)pumahome.getProfile(httpRequest);
User user = (User) pumaprofile.getCurrentUser();
PumaLocator pumalocator = pumahome.getLocator(httpRequest);
List groups = pumalocator.findGroupsByPrincipal(user, false);
Iterator iter = groups.iterator();
while (iter.hasNext()){
Group grp = (Group) iter.next();
groupsNames.add(grp.getName());
}
}
catch (Exception e){
e.printStackTrace();
}
return groupsNames;
}
}
No comments:
Post a Comment