Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

You need to add to your portlet.xml something like

Code Block
xmlxml
titleDeclaring a user attribute in portlet.xml
xml
<user-attribute>
  <description>User Family Name</description>
  <name>user.name.family</name>
</user-attribute>

...

Then from within your Portlet code you can access the values like this

Code Block
javajava
titleAccessing a user attribute from JSR-168 Java implementation
java
Map userInfo = (Map)request.getAttribute(PortletRequest.USER_INFO);
String surname = (String)userInfo.get("user.name.family");

...

In portletContainerContext.xml, enhance the existing declaration:

xml
Code Block
xml
titleuserInfoService declaration in portletContainerContext.xml
xml
<bean id="userInfoService" class="org.jasig.portal.portlet.container.services.MergingUserInfoService">
    <property name="userInfoServices">
        <list>
            <ref bean="personDirectoryUserInfoService"/>
            <ref bean="casTicketUserInfoService"/>
        </list>
    </property>
</bean>

to additionally reference the cached password service:

xml
Code Block
xml
titleuserInfoService declaration modified to reference the cached password service in portletContainerContext.xml
xml
<bean id="userInfoService" class="org.jasig.portal.portlet.container.services.MergingUserInfoService">
    <property name="userInfoServices">
        <list>
            <ref bean="personDirectoryUserInfoService"/>
            <ref bean="casTicketUserInfoService"/>
            <ref bean="cachedPasswordUserInfoService"/>
        </list>
    </property>
</bean>

Of course, that reference needs to point at a bean declaration, so introduce a bean like this:

xml
Code Block
xml
titleintroduce a cachedPasswordUserInfoService declaration in portletContainerContext.xml
xml
<bean id="cachedPasswordUserInfoService"  class="org.jasig.portal.portlet.container.services.CachedPasswordUserInfoService">
    <property name="portalRequestUtils" ref="portalRequestUtils" />
    <property name="userInstanceManager" ref="userInstanceManager" />
    <property name="portletWindowRegistry" ref="portletWindowRegistry" />
    <property name="portletEntityRegistry" ref="portletEntityRegistry" />
    <property name="portletDefinitionRegistry" ref="portletDefinitionRegistry" />
    <property name="passwordKey" value="password"/>
</bean>

...

Consuming the attributes once available

xml
Code Block
xml
titleDeclaring password user attribute in portlet.xml
xml
<user-attribute>
  <description>Specially treated user attribute name that will be 
populated with the end user's cached password, if available</description>
  <name>password</name>
</user-attribute>

Then from within your Portlet code you can access the password like this

Code Block
javajava
titleAccessing a user attribute from JSR-168 Java implementation
java
Map userInfo = (Map)request.getAttribute(PortletRequest.USER_INFO);
String password = (String)userInfo.get("password");