java liferay,用一个简单的Java code获取当前用户的Liferay

这篇博客介绍了如何在Liferay 6.0.6环境中,结合JBoss 5.1和Struts2,通过Java代码获取当前已登录用户的信息。主要方法包括从请求对象中获取ThemeDisplay对象,然后调用getUser()方法。此外,还提供了一个通用的解决方案,即通过request.getRemoteUser()获取用户ID。
摘要由CSDN通过智能技术生成

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

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

解决方案

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 nad 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值