User attributes are defined in portlet.xml (using the <user-attribute> elements) and are made available as a request attribute by the portlet container to the portlets.
The name of the request attribute is the value of the PortletRequest interface’s USER_INFO constant. Portlets can obtain user attributes from the request and display them in the portlet or use it in processing the request
In Portlet.xml
<user-attribute>
        <description>user first name</description>
        <name>user.name.given</name>
    </user-attribute>
    <user-attribute>
        <description>user last name</description>
        <name>user.name.family</name>
   </user-attribute>
In The portlet  classm
Map<String, Object> userAttributeMap =
(Map<String, Object>)request.getAttribute(PortletRequest.USER_INFO)
String firstName = (String)userAttributeMap.get("user.name.given");
Possible User attribute names defined in PortletRequest's inner class
 
No comments:
Post a Comment