Accessing User information from JSR 168 portlet

Accessing a logged in user name in portal using JSR168 is straightforward and it is request.getRemoteUser() but in some cases you might need additional user attributes like
first name, last name, given name etc.

If you want to access such additional users information which is normally stored in coroporate directory in JSR-168 compliant way then use these steps.

First add these entries in

<description xml:lang="en">User Given Name</description> <name></name>
<description xml:lang="en">User Last name</description> <name></name>

After that you should be able to access those two attributes in your java code by using code like this

Map userInfo = (Map)request.getAttribute(PortletRequest.USER_INFO);
if(userInfo != null){
String givenName = (String)userInfo.get("");
String lastName =(String)userInfo.get("");
response.getWriter().println("Hello " + givenName +" " + lastName);

At deployment time the portal can map the requested user profile attributes to the supported profile attributes or the portal can ignore the requested attributes.

In some scenarios, you might need to access following information
-Portal group name of user to which he belongs
-All portal groups in portal
-All users for a perticular portal group.
-List of users who belongs to multiple groups....

If this kind of requirement is for IBM WebSphere portal, you can access all these info using PUMA API.

No comments: