Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

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).

...

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.

Code Block
xml
xml

<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:

Code Block
java
java

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

...

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.

Code Block
xml
xml

<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:

Code Block
java
java

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

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

 

Making User Attributes Available from uPortal

...