You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Jan Kowalik <ko...@gmail.com> on 2009/06/14 15:05:19 UTC
getting user informations
Hi all,
How can I get user information like user name, group, role .., from
portlet code level ?
Do I have to add JetSpeed2 proprietary libraries ? Which ones ? Can I
do it without them ?
Thanks in advance
Regards
Jan
--
Pozdrawiam || Best Regards
Jan Kowalik
--
gg: 2048986
jabber: kowalik.jan@gmail.com
UK mobile: +44 7593 212 863
--
http://iaeste.pl
http://iaeste.polsl.pl
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org
Re: getting user informations
Posted by David Sean Taylor <d....@onehippo.com>.
>
>
> How can I get user information like user name, group, role .., from
> portlet code level ?
> Do I have to add JetSpeed2 proprietary libraries ? Which ones ? Can I
> do it without them ?
>
The username is available via getUserPrincipal() call Randy described.
String username = request.getUserPrincipal().getName();
If you are interested in getting the user's attributes such as first
or last name, email address, etc, then there is a standard way for
portlets to access a map with user information attributes via the
request attribute:
static final java.lang.String USER_INFO ("javax.portlet.userinfo")
The user information is returned as a Map object.
The portlet must define the user information attribute it is
interested in inside the user-attribute section of the deployment
descriptor. If an attribute is not supported by the current runtime
system it will not show up in the user attribute map.
If the user-attribute is supported by the runtime system, but not
defined for a particular user, then for that user the attribute exists
in the returned map and the attribute has a null value.
If the user-attribute is not defined for the current user it will
not show up in the Map.
Example:
Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
String givenName = (userInfo!=null) ? (String)
userInfo.get(PortletRequest.P3PUserInfos.USER_NAME_GIVEN) : “”;
String lastName = (userInfo!=null) ? (String)
userInfo.get(PortletRequest.P3PUserInfos.USER_NAME_FAMILY) : “”;
Here is how to define the user attributes that your application will
require in your portlet.xml:
<portlet-app>
…
<user-attribute>
<description>User Given Name</description>
<name>user.name.given</name>
</user-attribute>
<user-attribute>
<description>User Last Name</description>
<name>user.name.family</name>
</user-attribute>
<user-attribute>
<description>User eMail</description>
<name>user.home-info.online.email</name>
</user-attribute>
<user-attribute>
<description>Company Organization</description>
<name>user.business-info.postal.organization</name>
</user-attribute>
…
<portlet-app>
There is no standard way to get all roles or groups for a user,
however you can check for a user in a role with:
if (request.isUserInRole("someRole"))
> Do I have to add JetSpeed2 proprietary libraries
Well, i wouldn't exactly call the libraries proprietary, at least the
Jetspeed APIs are 'open' as in open source anyway im not going to
mince works, the answer is yes, you can retrieve everything you
require via the Jetspeed API. Best to look at the tutorial for examples:
http://portals.apache.org/jetspeed-2/tutorial/04/jetspeed-service.html
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org
Re: getting user informations
Posted by Randy Watler <wa...@wispertel.net>.
Jan,
From the 286 spec:
PLT.11.1.7 Security Attributes
The PortletRequest interface offers a set of methods that provide
security information
about the user and the connection between the user and the portal. These
methods are:
• getAuthType
• getRemoteUser
• getUserPrincipal
• isUserInRole
• isSecure
Theses can be used portably across portal implementations.
Randy
Jan Kowalik wrote:
> Hi all,
>
> How can I get user information like user name, group, role .., from
> portlet code level ?
> Do I have to add JetSpeed2 proprietary libraries ? Which ones ? Can I
> do it without them ?
>
>
> Thanks in advance
>
> Regards
> Jan
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org