Accessing Portal Roles and User Attributes

Accessing uPortal groups and user attributes from the portlet environment.One of the main issues we encountered when developing portlets is that the portal and the portlets run in different Tomcat contexts, which prevents from accessing the portal objects from the portlets, in particular, the groups and the user attributes (Note: hopefully this separation has many advantages).

JSR-168 Support for Roles and User Attributes

The JSR-168 specification provides support for requesting user role and attribute information from the portal. Both desired roles names and user attribute names should be listed in the application's portlet.xml.

Roles

To make a role available to your application, include a security-role-ref element in your portlet.xml for each desired role. This declaration should be outside the portlet declarations.

<security-role-ref>
    <role-name>everyone</role-name>
    <role-link>local.0</role-link>
</security-role-ref>
<security-role-ref>
    <role-name>student</role-name>
    <role-link>local.34</role-link>
</security-role-ref>

Once this declaration is in your portlet.xml file, you can test for role membership through the portlet API:

boolean isStudent = request.isUserInRole("student");

User attributes

To make a user attribute available to your application, include a user-attribute element in your portlet.xml for each desired attribute. This declaration should be outside the portlet declarations.

<user-attribute>
    <name>user.login.id</name>
</user-attribute>
<user-attribute>
    <name>password</name>
</user-attribute>

Once this declaration is in your portlet.xml file, you can query user attributes using the Java API:

Map<String,String> userInfo = (Map<String,String>) request.getAttribute(PortletRequest.USER_INFO);
String userId = userInfo.get("user.login.id");

uPortal-specific extension to get multi-valued attributes

req.getAttribute("org.jasig.portlet.USER_INFO_MULTIVALUED")

 

Making User Attributes Available from uPortal

TODO: Describe UserInfoService API.

Other Options

The package esup-portal-ws solves this issue by providing a web service (executed by uPortal and interrogated by the portlets) which gives access to the portal groups and user attributes.
Documentation and downloads are available at http://sourcesup.cru.fr/esup-portal-ws. We think that this project can be useful for the whole JASIG community, especially the people who develop portlets or port existing uPortal channels to portlets, and who want to keep a close integration between their portlets and the portal Information System.
PA

 

Additional References

 

Having problems with these instructions?

Please send us feedback at uportal-user@lists.ja-sig.org