使用简单的 Java 代码获取当前用户 Liferay [英] Get the current user Liferay using a simple Java code

查看:13
本文介绍了使用简单的 Java 代码获取当前用户 Liferay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用:Liferay 6.0.6JBoss 5.1Struts2.

I'm working with : Liferay 6.0.6 with JBoss 5.1 and Struts2.

我的问题是,如何使用 Java 代码在 Liferay 登录后获取当前用户.

My question is, how to get the current user in Liferay once logged in, using a Java code.

推荐答案

在你的 doView/processAction 方法中执行以下操作

In your doView/processAction method do following

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

或使用 ThemeDisplay 对象.它包含另一个信息,如 companyId、groupId、...

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

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

类 ThemeDisplay、User nad WebKeys 是 portal-service.jar 的一部分.

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

如果你只需要一些 id 来识别当前用户,你也可以使用

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

String userId = request.getRemoteUser();

这个解决方案不是 Liferay 特有的,应该可以在 jsr-286 门户之间移植.

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

这篇关于使用简单的 Java 代码获取当前用户 Liferay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆