Hi we have the following code that gets the groups that the user logged in has associated, the code works fine in WP 6.1 but not in WP 5.1.

Can some one have any idea about this.

Thanks a lot

Best Regards

Carlos Jaramillo

package com.ibm.portalservicioalcliente;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.naming.InitialContext;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import com.ibm.portal.portlet.service.PortletServiceHome;
import com.ibm.portal.um.Group;
import com.ibm.portal.um.PumaLocator;
import com.ibm.portal.um.PumaProfile;
import com.ibm.portal.um.portletservice.PumaHome;

/**
* A sample portlet
*/
public class PortalServicioAlClientePortlet extends javax.portlet.GenericPortlet {

PortletServiceHome serviceHome;
private boolean huboError = false;
private String mensajeError;
/**
* @see javax.portlet.Portlet#init()
*/
public void init() throws PortletException{
super.init();
try{
System.out.println("[PUMA] POR ACA PROBANDO PUMA");
javax.naming.Context ctx = new InitialContext();
Object home = ctx.lookup("portletservice/com.ibm.portal.um.portletservice.PumaHome");

if(home != null){
serviceHome = (PortletServiceHome)home;
}


}catch(Exception e){
System.out.println("[PUMA] Error. No se encuentra el objeto home. "+e.getMessage());
huboError = true;
mensajeError = e.getMessage();
}
}

/**
* Serve up the view mode.
*
* @see javax.portlet.GenericPortlet#doView(javax.portlet. RenderRequest, javax.portlet.RenderResponse)
*/
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// Set the MIME type for the render response
response.setContentType(request.getResponseContent Type());
//código para el manejo de los grupos
List groups = null;
List gruposSistema = null;
String gruposUsuario = new String();
com.ibm.portal.um.User usuario = null;
String login = null;
if(serviceHome!=null){
PumaHome service =(PumaHome)serviceHome.getPortletService(PumaHome. class);
PumaProfile profile = service.getProfile(request);
PumaLocator plocator = service.getLocator(request);

try{
//se obtiene el nombre de usuario y se agrega a la respuesta
usuario = profile.getCurrentUser();
List atributosUsuario = new ArrayList();
atributosUsuario.add("uid");
Map atributosUsuarioMap = profile.getAttributes(usuario, atributosUsuario);
login = (String)atributosUsuarioMap.get((String)"uid");
request.setAttribute("login", login);

//se obtienen los grupos del sistema y se agregan a la respuesta
gruposSistema = plocator.findGroupsByAttribute("cn", request.getParameter("cn"));
groups = plocator.findGroupsByPrincipal(usuario, true);
List atributosGrupos = new java.util.ArrayList();
atributosGrupos.add("cn");
Iterator itrGrupos = groups.iterator();
boolean isTheFirstGroup = true;
while(itrGrupos.hasNext()){
Group grupo = (Group)itrGrupos.next();
Map gruposMap = profile.getAttributes(grupo, atributosGrupos);
if(isTheFirstGroup){
gruposUsuario+= (String)gruposMap.get((Object)"cn");
isTheFirstGroup = false;
}
else{
gruposUsuario+= ","+(String)gruposMap.get((Object)"cn");
}
}
request.setAttribute("grupos", gruposUsuario);
}catch(Exception e){
System.out.println("[PUMA] Error. El problema es: "+e.getMessage());
e.printStackTrace();
}
}
//
// TODO: auto-generated method stub for demonstration purposes
//

// Invoke the JSP to render, replace with the actual jsp name
//PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/jsp/portalServicioAlClienteView.jsp");

//rd.include(request,response);

// or write to the response directly
//response.getWriter().println("ElPortlet#doView()");
PrintWriter out = response.getWriter();
String url = response.encodeURL(request.getContextPath() + "/jsp/portalServicioAlClienteView.jsp");
out.println(" window.open('"+url+"?login="+ login + "&grupos="+gruposUsuario+"', 'PortalServicioCliente', 'titlebar=no, menubar=0, resizable=1, status=0, left=0, top=0, width=998, height=742') ; ");
}

/**
* Serve up the edit mode.
*
* @see javax.portlet.GenericPortlet#doEdit(javax.portlet. RenderRequest, javax.portlet.RenderResponse)
*/
public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// TODO: auto-generated method stub
}

/**
* Serve up the help mode.
*
* @see javax.portlet.GenericPortlet#doHelp(javax.portlet. RenderRequest, javax.portlet.RenderResponse)
*/
protected void doHelp(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// TODO: auto-generated method stub
}

/**
* Process an action request.
*
* @see javax.portlet.Portlet#processAction(javax.portlet. ActionRequest, javax.portlet.ActionResponse)
*/
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
// TODO: auto-generated method stub
}

}