Puma Spi :- It provides an exposed services in portal using which we can create, delete and modify users and group. It has some provider objects using those objects we can perform operations on users and group.
List of provider objects {Before the uses these provider objects, it must first retrieve the appropriate home interface, depending on the type of application.}:-
PumaProfile
Example for PumaProfile :-
package com.ibm.exploringpumaapi;
import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
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.PumaProfile;
import com.ibm.portal.um.User;
import com.ibm.portal.um.exceptions.PumaException;
import com.ibm.portal.um.portletservice.PumaHome;
/**
* A sample portlet
*/
public class ExploringPumaApiPortlet extends javax.portlet.GenericPortlet {
public static final Logger logger = Logger.getLogger(ExploringPumaApiPortlet.class.getName());
public String PUMA_JNDI_NAME = "portletservice/com.ibm.portal.um.portletservice.PumaHome";
public static PortletServiceHome psh = null;
/**
* @see javax.portlet.Portlet#init()
*/
public void init() throws PortletException{
super.init();
Context ctx;
try {
ctx = new InitialContext();
//Retrieve the service object
psh = (PortletServiceHome)ctx.lookup(PUMA_JNDI_NAME);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Serve up the <code>view</code> 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.getResponseContentType());
// Set the MIME type for the render response
response.setContentType(request.getResponseContentType());
PumaHome pumaHome = psh.getPortletService(PumaHome.class);
PumaProfile pumaProfile = pumaHome.getProfile(request);
try {
User user = pumaProfile.getCurrentUser();
String userId = pumaProfile.getIdentifier(user);
logger.info("UserId :-"+userId);
logger.info("ObjectId :-"+user.getObjectID());
logger.info("Listing available attribures");
List<String> attributes = pumaProfile.getMandatoryUserAttributeNames();
for (String attribute : attributes) {
logger.info("Attribute name :- "+attribute);
}
} catch (PumaException e) {
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("/_ExploringPumaApi/jsp/html/ExploringPumaApiPortletView.jsp");
//rd.include(request,response);
// or write to the response directly
response.getWriter().println("ExploringPumaApi#doView()");
}
/**
* Serve up the <code>edit</code> 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 <code>help</code> 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
}
}
Example for PumaLocator :-
List of provider objects {Before the uses these provider objects, it must first retrieve the appropriate home interface, depending on the type of application.}:-
PumaProfile
contains methods that provide read-only access to the User and Group attributes and identifiers. You can use this interface to get the User object for the current user.
PumaLocator
contains methods for looking up User and Group objects. You can use this interface to obtain a List of Group objects for all of the groups in which the current user is a member. Beginning with Version 7.0 of WebSphere® Portal, paging is supported, which means that the result set is split up into subsets (pages) and an special iterator can be used to access the pages.
PumaController
contains methods for creating and deleting Users and Groups and for modifying the User and Group profiles and membership.
PumaEnvironment
contains methods to retrieve virtual principals, access general properties for user management, and a method to bypass access control for the user and group management layer.
Example for PumaProfile :-
package com.ibm.exploringpumaapi;
import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
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.PumaProfile;
import com.ibm.portal.um.User;
import com.ibm.portal.um.exceptions.PumaException;
import com.ibm.portal.um.portletservice.PumaHome;
/**
* A sample portlet
*/
public class ExploringPumaApiPortlet extends javax.portlet.GenericPortlet {
public static final Logger logger = Logger.getLogger(ExploringPumaApiPortlet.class.getName());
public String PUMA_JNDI_NAME = "portletservice/com.ibm.portal.um.portletservice.PumaHome";
public static PortletServiceHome psh = null;
/**
* @see javax.portlet.Portlet#init()
*/
public void init() throws PortletException{
super.init();
Context ctx;
try {
ctx = new InitialContext();
//Retrieve the service object
psh = (PortletServiceHome)ctx.lookup(PUMA_JNDI_NAME);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Serve up the <code>view</code> 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.getResponseContentType());
// Set the MIME type for the render response
response.setContentType(request.getResponseContentType());
PumaHome pumaHome = psh.getPortletService(PumaHome.class);
PumaProfile pumaProfile = pumaHome.getProfile(request);
try {
User user = pumaProfile.getCurrentUser();
String userId = pumaProfile.getIdentifier(user);
logger.info("UserId :-"+userId);
logger.info("ObjectId :-"+user.getObjectID());
logger.info("Listing available attribures");
List<String> attributes = pumaProfile.getMandatoryUserAttributeNames();
for (String attribute : attributes) {
logger.info("Attribute name :- "+attribute);
}
} catch (PumaException e) {
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("/_ExploringPumaApi/jsp/html/ExploringPumaApiPortletView.jsp");
//rd.include(request,response);
// or write to the response directly
response.getWriter().println("ExploringPumaApi#doView()");
}
/**
* Serve up the <code>edit</code> 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 <code>help</code> 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
}
}
package com.ibm.exploringpumaapi;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.portlet.*;
import com.ibm.portal.portlet.service.PortletServiceHome;
import com.ibm.portal.um.PumaLocator;
import com.ibm.portal.um.PumaProfile;
import com.ibm.portal.um.User;
import com.ibm.portal.um.exceptions.PumaAttributeException;
import com.ibm.portal.um.exceptions.PumaMissingAccessRightsException;
import com.ibm.portal.um.exceptions.PumaModelException;
import com.ibm.portal.um.exceptions.PumaSystemException;
import com.ibm.portal.um.portletservice.PumaHome;
/**
* A sample portlet
*/
public class ExploringPumaFindUsersPortlet extends javax.portlet.GenericPortlet {
public String PUMA_JNDI_NAME = "portletservice/com.ibm.portal.um.portletservice.PumaHome";
public static final Logger logger = Logger.getLogger(ExploringPumaFindUsersPortlet.class.getName());
public static PortletServiceHome psh = null;
/**
* @see javax.portlet.Portlet#init()
*/
public void init() throws PortletException{
super.init();
Context ctx;
try {
ctx = new InitialContext();
//Retrieve the service object
psh = (PortletServiceHome)ctx.lookup(PUMA_JNDI_NAME);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Serve up the <code>view</code> 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.getResponseContentType());
PumaHome pumaHome = psh.getPortletService(PumaHome.class);
PumaLocator pumaLocator = pumaHome.getLocator(request);
PumaProfile pumaProfile = pumaHome.getProfile(request);
List<String> attributesList = new ArrayList<String>();
attributesList.add("uid");
attributesList.add("ibm-primaryEmail");
try {
List<User> usersLIst = pumaLocator.findUsersByAttribute("uid", "wpsadmin");
for (User user : usersLIst) {
logger.info("ObjectId :-"+user.getObjectID());
Map<String, Object> attributesMap = pumaProfile.getAttributes(user, attributesList);
logger.info("uid :-" +attributesMap.get("uid"));
logger.info("primaryEmail :-" +attributesMap.get("ibm-primaryEmail"));
//user.getObjectID()
}
} catch (PumaSystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PumaAttributeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PumaMissingAccessRightsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO: auto-generated method stub for demonstration purposes
//
catch (PumaModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Invoke the JSP to render, replace with the actual jsp name
//PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/_ExploringPumaFindUsers/jsp/html/ExploringPumaFindUsersPortletView.jsp");
//rd.include(request,response);
// or write to the response directly
response.getWriter().println("ExploringPumaFindUsers#doView()");
}
/**
* Serve up the <code>edit</code> 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 <code>help</code> 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
}
}
No comments:
Post a Comment