Develop a custom portlet
Use the default Impersonation portlet to impersonate specific users. Alternatively, we can create a resource environment provider to enable impersonation and develop a custom portlet for impersonating users.
Sample code
If we do not want to use the WebSphere Portal Impersonation portlet, use the following sample to develop a portlet to impersonate users:
import com.ibm.portal.portlet.service.impersonation.ImpersonationService; import com.ibm.portal.portlet.service.PortletServiceHome; public class MyImpersonationPortlet extends GenericPortlet { private PortletServiceHome psh; @Override public void init() throws PortletException { try { javax.naming.Context ctx = new javax.naming.InitialContext(); psh = (PortletServiceHome) ctx.lookup(ImpersonationService. JNDI_NAME); } catch (Exception ex) { // error handling } } @Override public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { // obtain the service object and use the service ImpersonationService impersonationService = (ImpersonationService) psh.getPortletService(ImpersonationService.class); try { impersonationService.doImpersonate(request, response, stringuserDN); } catch (Exception e) { // error handling } } }We can enter the information for the user to impersonate in the stringuserDN. Alternatively, use the PUMA SPI User object.
The impersonation feature becomes active with the next request.