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

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

问题描述

我的工作:的Liferay 6.0.6 的JBoss 5.1 Struts2的

我的问题是,如何让当前用户的的Liferay 登录后,使用的Java code。

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,用户NAD WebKeys是门户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 code获取当前用户的Liferay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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