Friday, April 6, 2012

How to get Logged In portal user profile in theme

a) To get basic user information in theme if the user is logged in

1) Use following tag lib to get basic user attribute value
<%@ taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v7.0/portal-fmt" prefix="portal-fmt" %>


<portal-logic:if loggedIn="yes">
<portal-fmt:user attribute="cn"/>
</portal-logic:if>

attribute value can be any value defined in your websphere member manager directory. 

2) To get the list of groups the user belongs to use the below code snippet
<%
com.ibm.portal.puma.User user= (com.ibm.portal.puma.User)request.getAttribute(com.ibm.portal.RequestConstants.REQUEST_USER_OBJECT);
if(user!=null) {
    java.util.List groupsList = user.getGroups();
        for (int i=0; i< groups.size() ; i++){
            com.ibm.portal.puma.Group group = (com.ibm.portal.puma.Group)groupsList.get(i);
            System.out.println("group common name = " +group.getCommonName());
            System.out.println("group  name = " +group.getName());
        }
}
%>