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