How can I get the current user in Liferay?

最后都变了- 提交于 2019-11-29 06:44:28

问题


How can I get the current user connected to a Liferay portal with a simple Java code?

I'm using Liferay 6.0.6


回答1:


Simply:

User currentUser = PortalUtil.getUser(request);



回答2:


In your doView/processAction method do following

User user = (User) request.getAttribute(WebKeys.USER);

or use the ThemeDisplay object. It contains another information like companyId, groupId, ...

ThemeDisplay td  =(ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
User user = td.getUser();

Classes ThemeDisplay, User and WebKeys are part of portal-service.jar.

If you need just some id to identify current user you can also use

String userId = request.getRemoteUser();

This solution is not Liferay specific and should be portable among jsr-286 portals.

Source: Get the current user Liferay using a simple Java code




回答3:


In Java Code:

  • UserLocalServiceUtil.getXXX methods are there, choose as you want.

In JSP Code:

  • themeDisplay.getUserId() will give you the current user id
  • themeDisplay.getUser() will give you the object of current User.


来源:https://stackoverflow.com/questions/10523382/how-can-i-get-the-current-user-in-liferay

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!