No, you cannot use PUMA API to retrieve user info.
That is exactly where
Servlets and Portlets differ.
Portlets provide us a way to retrieve the User info. Portal User Management Archictecture(PUMA) has been specifically there to provide you with features to access Logged in User Profile.
Here is an example :
private PumaUtil() {
try {
Context ctx = new InitialContext();
Object puma = ctx.lookup("portletservice/com.ibm.portal.um.portletservice.PumaHome");
pumaService = (PortletServiceHome)puma;
pumaHome = (PumaHome)pumaService.getPortletService(PumaHome.class);
pumalocator = pumaHome.getLocator();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PortletServiceUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* This method returns the PumaProfile
*
* @return a PumaProfile object.
*/
private PumaProfile getPumaProfile() {
return pumaHome.getProfile();
}
/**
* This method will return the PumaController Objects
* @return
*/
public PumaController getPumaController(){
return pumaHome.getController();
}
/**
* This method will return the list of user attributes.
* @return list of User attributes
*/
public List getLoggedInUserAttributes(){
List userAttr = new ArrayList();
try {
userAttr = getPumaProfile().getDefinedUserAttributeNames();
} catch (Exception e) {
logger.logError("Error while fetching the User Attribute Map from Portal Database:::" +
" Message:::" + e.getMessage());
}
return userAttr;
}
/**
* This method will return the Map of user attributes.
* This map can be modified to update the attribute values for the user
* @return list of User attributes
*/
public Map getLoggedInUserAttributeMap(){
Map userMap = new HashMap();
try {
userMap = getPumaProfile().getAttributes(getPumaProfile().getCurrentUser(), getLoggedInUserAttributes());
}catch (Exception e) {
logger.logError("Error while fetching the User from Portal Database:::" +
" Message:::" + e.getMessage());
}
return userMap;
}