掲示板

How to get real user in portlet?

11年前 に Gwowen Fu によって更新されました。

How to get real user in portlet?

Expert 投稿: 315 参加年月日: 10/12/27 最新の投稿
Hi,

After impersonating a user, how could I get the real user object or id?

Thanks!
Gwowen
thumbnail
11年前 に mohammad azaruddin によって更新されました。

RE: How to get real user in portlet?

Expert 投稿: 492 参加年月日: 12/09/17 最新の投稿
ThemeDisplay td =(ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
User user = td.getUser();
11年前 に Gwowen Fu によって更新されました。

RE: How to get real user in portlet?

Expert 投稿: 315 参加年月日: 10/12/27 最新の投稿
mohammad azaruddin:
ThemeDisplay td =(ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
User user = td.getUser();


Tried that already and ThemeDisplay.getUser() returns the impersonated user, not the real user.
Also tried PortalUtil.getUserId(request) and it also returns the impersonated user ID.
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: How to get real user in portlet?

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
To get the real user id:

1. enable the com.liferay.portal.servlet.filters.audit.AuditFilter by setting it to true in portal-ext.properties.
2. use the following code:

AuditRequestThreadLocal auditRequest = AuditRequestThreadLocal.getAuditThreadLocal();
if (auditRequest != null) realUserId = auditRequest.getRealUserId();


Or you can do it the way AuditFilter does by getting the original http request, get the session from the request, then extract the WebKeys.USER_ID attribute.
11年前 に Gwowen Fu によって更新されました。

RE: How to get real user in portlet? (回答)

Expert 投稿: 315 参加年月日: 10/12/27 最新の投稿
Thanks for the reply. I missed the ThemeDisplay.getRealUser() method. ThemeDisplay.getRealUser() works.