Skip to content

How to use the PUMA API within a WCM JSP component to print out the user and hostname sending the request

Applies to

HCL Digital Experience 8.5 and higher

Introduction

This article provides the sample code for using the PUMA API within a WCM JSP component to print out the user and hostname that initiated the request and describes how to use it.

Instructions

Refer to the following steps to use the sample code:

  1. Create a file named puma.jsp in the <wp_profile_root>\installedApps\<yourCellName>\PA_WCMLRingPortJSR286.ear\ilwwcm-localrende.war\jsp\html> directory.

  2. Copy and paste the following code in the puma.jsp file:

    Important

    DISCLAIMER OF WARRANTIES: The following enclosed code is sample code created by HCL Corporation. This sample code is provided to you solely for the purpose of assisting you in the development of your applications. The code is provided "AS IS", without warranty of any kind. HCL shall not be liable for any damages arising out of your use of the sample code, even if they have been advised of the possibility of such damages.

    <%@ page import="java.util.*,javax.servlet.jsp.JspWriter,java.io.*"%>
    
    <%@ page import="com.ibm.workplace.wcm.api.*"%>
    
    <%@ page import="com.ibm.portal.puma.InvalidMemberIdException"%>
    <%@ page import="com.ibm.portal.um.PumaProfile"%>
    <%@ page import="com.ibm.portal.um.exceptions.*"%>
    <%@ page import="com.ibm.portal.um.portletservice.PumaHome"%>
    <%@ page import="com.ibm.portal.um.*"%>
    <%@ page import="com.ibm.wps.puma.UserManager.*"%>
    <%@ page import="com.ibm.wps.services.puma.PumaService"%>
    
    <%@ page import="javax.naming.InitialContext"%>
    <%@ page import="javax.naming.Context"%>
    
    <%@ page import="com.ibm.portal.portlet.service.PortletServiceHome"%>
    
    <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
    <portlet:defineObjects/>
    
    <%
    
    out.println("remote host = " + request.getRemoteHost());
    
    Workspace workspace = WCM_API.getRepository().getWorkspace(request.getUserPrincipal());
    
    workspace.useDistinguishedNames(false);
    
    String replyAuthor = workspace.getUserProfile().getUsername();
    out.println("<br>replyAuthor: " + replyAuthor);
    
    Context context = new InitialContext();
    
    PumaHome pumaHome = (PumaHome)context.lookup(com.ibm.portal.um.PumaHome.JNDI_NAME);
    
    PortletServiceHome psh;
    javax.naming.Context ctx = new javax.naming.InitialContext();
    psh = (PortletServiceHome)ctx.lookup("portletservice/com.ibm.portal.um.portletservice.PumaHome");
    PumaHome service = (PumaHome) psh.getPortletService(PumaHome.class);
    
    PumaProfile pp = service.getProfile(renderRequest);
    User user = pp.getCurrentUser();
    
    List attributeList = new ArrayList();
    attributeList.add("sn");
    attributeList.add("givenName");
    attributeList.add("uid");
    attributeList.add("preferredLanguage");
    
    Map userAttributeMap = pp.getAttributes(user, attributeList);
    
    out.println("<br>DN of current User " + pp.getIdentifier(user) + "");
    out.println("<br>Attributes Values for current user");
    
    Iterator userAttributeIt = userAttributeMap.keySet().iterator();
    
    while(userAttributeIt.hasNext()){
    String attributeName = (String)userAttributeIt.next();
    Object attributeValue = userAttributeMap.get(attributeName);
    out.println(attributeName + " = " + attributeValue);
    out.println("");
    }
    
    %>
    
  3. Create a JSP component with /jsp/html/puma.jsp in the path field. For more information on creating JSP components, refer to Creating a JSP component.

  4. Edit a presentation template and add the JSP component created in Step 3 to the template. For more information on editing presentation templates, refer to Editing a presentation template in Presentation Designer.

  5. Go to Web Content > Web Content Libraries and create a new library to use as a site area (or use an existing one).

  6. Map the presentation template and authoring template to a site area. The content will be rendered in the Web Content Viewer portlet. For more information on mapping templates, refer to Template mappings.

  7. Add the Web Content Viewer portlet on a new or existing page in the Portal.

  8. On the Portal page, toggle Edit Mode: to ON

  9. On the Web Content Viewer portlet, go to Edit Shared settings and configure the portlet to render the site area that was mapped in step 5.

  10. Render the page and check the results. The Web Content Viewer portlet should now display the contents of the JSP file.
    For more information on the Web Content Viewer, refer to Displaying content with Web Content Viewers.