留言板

How get user Id in my portlet

marco pancioni,修改在17 年前。

How get user Id in my portlet

New Member 帖子: 7 加入日期: 06-12-11 最近的帖子
I have develop a struts portlet and i would get the id of user.

I use req.getAtribute("USER"), but i have some problem!!

Are there other way to get the user id?
thumbnail
Mika Koivisto,修改在17 年前。

RE: How get user Id in my portlet

Liferay Legend 帖子: 1519 加入日期: 06-8-7 最近的帖子
request.getUserPrincipal() gets you the Principal if its not null you can call getName() from that or you can use request.getRemoteUser()
marco pancioni,修改在17 年前。

RE: How get user Id in my portlet

New Member 帖子: 7 加入日期: 06-12-11 最近的帖子
thanks a lot!

I've found another way, but I don't know if it is correct.

Map info = (Map) req.getAttribute(PortletRequest.USER_INFO);
String userI= info.get("liferay.user.id").toString();
thumbnail
Brett Swaim,修改在17 年前。

RE: How get user Id in my portlet

Regular Member 帖子: 112 加入日期: 06-4-14 最近的帖子
you can also just do user.getUserId() in your portlet I believe.
Pablo García Sánchez,修改在17 年前。

RE: How get user Id in my portlet

New Member 帖子: 8 加入日期: 06-10-30 最近的帖子
To avoid create a new thread...

I'm using the user.getThings methods (documented here) in my JSP portlet to get information of the user, but the user.getPasswordUnencrypted() returns a null String. Why? How can I get the password without encryption?

Thanks! ; )
thumbnail
alfonso lopez,修改在16 年前。

RE: How get user Id in my portlet

Regular Member 帖子: 132 加入日期: 07-4-25 最近的帖子
Pablo García Sánchez:
To avoid create a new thread...

I'm using the user.getThings methods (documented here) in my JSP portlet to get information of the user, but the user.getPasswordUnencrypted() returns a null String. Why? How can I get the password without encryption?

Thanks! ; )


Anybody can explaing how to use this class User (documented here)

an example please!

thanks vm
max tan,修改在16 年前。

RE: How get user Id in my portlet

New Member 帖子: 7 加入日期: 07-5-13 最近的帖子
The password a user has is typically stored hashed using SHA encryption.

The encryption is a one-way function, however, when creating the user account, the admin has the option to save the password as plain text (unhashed). When that is the case, calling the function will enable you to obtain the password without encryption.

BTW, its a little rude hijacking people's threads emoticon
thumbnail
Shawn Hartsock,修改在17 年前。

RE: How get user Id in my portlet

New Member 帖子: 11 加入日期: 06-12-18 最近的帖子

String remoteUserId = request.getRemoteUser();

Gets you the string of the remote userId which will be something like "liferay.com.1" or whatever.

That might be enough for you... and you can stop there... however for my uses I need the email address and other user info... so...

Then I use the UserServiceSoapProxy to get data about the user. These classes are in the portal-client.jar or you can point your SOAP client generator at the WSDL file at: http://localhost:8080/tunnel/axis ( assuming your host is localhost running on port 8080 ) and have it generate a client for you... or you could write your own... whatever makes you happy.

Now that you have a SOAP proxy...

First, set it up to talk to the correct endpoint ( something like http://hostname:port/tunnel/axis/Portal_UserService ) which I can figure out by doing:

 int port = request.getServerPort();
 String host = request.getServerName();
 String scheme = request.getScheme();


You assemble your SOAP endpoint string like this:

String endpoint = scheme + "://" + host + ":" Integer.toString(port) +
                  "/tunnel/axis/Portal_UserService";

Then when you want to talk to the Liferay User service...

usrSvc = new UserServiceSoapProxy();
usrSvc.setEndpoint(endpoint);
UserModel user = usrSvc.getUserById(request.getRemoteUser());


The service uses the same permissions scheme as the portal. So your logged in users can only do through the services whatever they can do through the regular portals. That means you still need to understand permissions and such. But, I'll bet nearly every user has permission to look at their own information.

Nothing liferay specific about:

String remoteUserId = request.getRemoteUser();

either... and using the SOAP service to get more info about the user means your code stays nice and separate. Probably makes upgrading liferay easier later on... and keeps you from mucking around with liferay internals too much.
thumbnail
Mika Koivisto,修改在17 年前。

RE: How get user Id in my portlet

Liferay Legend 帖子: 1519 加入日期: 06-8-7 最近的帖子
Best way to access current users information is to use the way specified in JSR-168 specification. That is add following to 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></portlet-app></portlet-app>


and in your code

Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
String givenName = (userInfo!=null)
? (String) userInfo.get(“user.name.given”) : “”;
String lastName = (userInfo!=null)
? (String) userInfo.get(“user.name.family”) : “”;


Here is all of the attributes defined in the spec.

Attribute Name
user.bdate
user.gender
user.employer
user.department
user.jobtitle
user.name.prefix
user.name.given
user.name.family
user.name.middle
user.name.suffix
user.name.nickName
user.home-info.postal.name
user.home-info.postal.street
user.home-info.postal.city
user.home-info.postal.stateprov
user.home-info.postal.postalcode
user.home-info.postal.country
user.home-info.postal.organization
user.home-info.telecom.telephone.intcode
user.home-info.telecom.telephone.loccode
user.home-info.telecom.telephone.number
user.home-info.telecom.telephone.ext
user.home-info.telecom.telephone.comment
user.home-info.telecom.fax.intcode
user.home-info.telecom.fax.loccode
user.home-info.telecom.fax.number
user.home-info.telecom.fax.ext
user.home-info.telecom.fax.comment
user.home-info.telecom.mobile.intcode
user.home-info.telecom.mobile.loccode
user.home-info.telecom.mobile.number
user.home-info.telecom.mobile.ext
user.home-info.telecom.mobile.comment
user.home-info.telecom.pager.intcode
user.home-info.telecom.pager.loccode
user.home-info.telecom.pager.number
user.home-info.telecom.pager.ext
user.home-info.telecom.pager.comment
user.home-info.online.email
user.home-info.online.uri
user.business-info.postal.name
user.business-info.postal.street
user.business-info.postal.city
user.business-info.postal.stateprov
user.business-info.postal.postalcode
user.business-info.postal.country
user.business-info.postal.organization
user.business-info.telecom.telephone.intcode
user.business-info.telecom.telephone.loccode
user.business-info.telecom.telephone.number
user.business-info.telecom.telephone.ext
user.business-info.telecom.telephone.comment
user.business-info.telecom.fax.intcode
user.business-info.telecom.fax.loccode
user.business-info.telecom.fax.number
user.business-info.telecom.fax.ext
user.business-info.telecom.fax.comment
user.business-info.telecom.mobile.intcode
user.business-info.telecom.mobile.loccode
user.business-info.telecom.mobile.number
user.business-info.telecom.mobile.ext
user.business-info.telecom.mobile.comment
user.business-info.telecom.pager.intcode
user.business-info.telecom.pager.loccode
user.business-info.telecom.pager.number
user.business-info.telecom.pager.ext
user.business-info.telecom.pager.comment
user.business-info.online.email
user.business-info.online.uri
NOTE: The user.bdate must consist of a string that represents the time in milliseconds
since January 1, 1970, 00:00:00 GMT.
thumbnail
Shawn Hartsock,修改在17 年前。

RE: How get user Id in my portlet

New Member 帖子: 11 加入日期: 06-12-18 最近的帖子
Mika Koivisto:
Best way to access current users information is to use the way specified in JSR-168 specification. That is add following to 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></portlet-app></portlet-app>


and in your code

Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
String givenName = (userInfo!=null)
? (String) userInfo.get(“user.name.given”) : “”;
String lastName = (userInfo!=null)
? (String) userInfo.get(“user.name.family”) : “”;




Thanks for the tip. That works like a champ, and I can save the SOAP services for the portlets that really need it. I guess I'll go spend a little more time with the JSR168 spec. I tend to want to use SOAP because I'm familiar with it.
Trey Jarnagin,修改在17 年前。

RE: How get user Id in my portlet

New Member 帖子: 2 加入日期: 06-12-22 最近的帖子
Mika,

Liferay doesn't seem to support many of those attributes from the JSR168 spec. Atleast, i would assume user.business-info.postal.organization or user.employe would be supported considering the extent of user attributes. Do you know if it is documented which of these are supported?

Thanks,
Trey
Naman Joshi,修改在17 年前。

RE: How get user Id in my portlet

New Member 帖子: 3 加入日期: 07-4-23 最近的帖子
Hi,

I was trying to implement this feature in Orbeon Xforms by writing a Java Processor. I had to change a few little things and the Java code looks like:

  PortletExternalContext externalContext = (PortletExternalContext) context.getAttribute (PipelineContext.EXTERNAL_CONTEXT);

  PortletRequest portletReq = (PortletRequest) externalContext.getNativeRequest();
  
  Map userInfo = (Map) portletReq.getAttribute(PortletRequest.USER_INFO);


I also defined the user-attributes in orbeon's portlet.xml as shown above but unfortunately I couldn't extract FirstName or anything, the only keys I get out of the Map is:

{liferay.company.id=liferay.com, liferay.user.id=njoshi1}

Any ideas what the problem is?

NJ
Kao Richard,修改在16 年前。

RE: How get user Id in my portlet

New Member 帖子: 21 加入日期: 07-1-11 最近的帖子
I am trying to keeping with the JSR-168 spec. However, with 4.3 and the new meaning of userId. How is it possible to access the screenName? Is it mapped to something in the JSR-168 spec?
thumbnail
Mika Koivisto,修改在16 年前。

RE: How get user Id in my portlet

Liferay Legend 帖子: 1519 加入日期: 06-8-7 最近的帖子
Kao Richard:
I am trying to keeping with the JSR-168 spec. However, with 4.3 and the new meaning of userId. How is it possible to access the screenName? Is it mapped to something in the JSR-168 spec?


You are absolutely right there is no standard way to get to it. I've opened a JIRA issue LEP-3342 for it. My suggestion is to use the user.name.nickName attribute for it since there is no other nickname in Liferay 4.3.
thumbnail
Santosh B Biradar,修改在6 年前。

RE: How get user Id in my portlet

Junior Member 帖子: 41 加入日期: 15-8-4 最近的帖子
Hi All,
Please try below code to get LoggedIn UserId,
ThemeDisplay themeDisplay =(ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long userId = themeDisplay.getUserId();

Regards
Santosh B B(Zensar Technology)