Versions Compared

Key

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

...

You need to add to your portlet.xml something like

Code Block
xml
xml
titleDeclaring a user attribute in portlet.xmlxml
<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
java
java
titleAccessing a user attribute from JSR-168 Java implementationjava
Map userInfo = (Map)request.getAttribute(PortletRequest.USER_INFO);
String surname = (String)userInfo.get("user.name.family");

...

In portletContainerContext.xml, enhance the existing declaration:

Code Block
xml
xml
titleuserInfoService declaration in portletContainerContext.xmlxml
<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:

Code Block
xml
xml
titleuserInfoService declaration modified to reference the cached password service in portletContainerContext.xmlxml
<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:

Code Block
xml
xml
titleintroduce a cachedPasswordUserInfoService declaration in portletContainerContext.xmlxml
<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

Code Block
xml
xml
titleDeclaring password user attribute in portlet.xmlxml
<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
java
java
titleAccessing a user attribute from JSR-168 Java implementationjava
Map userInfo = (Map)request.getAttribute(PortletRequest.USER_INFO);
String password = (String)userInfo.get("password");