Retrieving logged in user in theme

In WPS Portal, you might require to get logged in user in any of the theme jsp, like default.jsp.
Portal tag lib provides a tag to get logged in user

<portal-fmt:user attribute="value"/>

If the user is logged in, this tag returns one of the specified user attributes, value can be any user attribute defined to Member Manager.

But in some situations, you might require to get logged in user id in a java string and pass to some method call for further processing.
Here is the code snippet to get logged in user in any of theme jsp

<%
com.ibm.portal.puma.User portalUser= (com.ibm.portal.puma.User)request.getAttribute(com.ibm.portal.RequestConstants.REQUEST_USER_OBJECT);
String loggedInUser = (String) portalUser.get("uid");
%>

2 comments:

Unknown said...

Neeraj,

Thanks for your post, I have a question.
I tried portal-fmt:user attribute="value" and it works fine but when I change the Ldap attribute value. This change affect the theme after 10 minutes. I now I can change the attributesCacheTimeOut in wmm-Ldap.xml but I don't want to do this modification. Do you have another solution about this ?

Thanks
Akram BLOUZA
Sotware Engineer
Paris

Fernando said...

Hi Akram, you can delete the jsp you have changed at /wp_profile/temp.
Regards,

Fernando