Retrieving logged in user is essential in every system, especially for logging purpose or authentication and authorization.
Steps to retrieve Liferay Logged in user in JSF portlet:
1. get the PortletRequest from JSF context
2. get the logged in user id
3. get the user model with Liferay API
Done!!
Steps to retrieve Liferay Logged in user in JSF portlet:
1. get the PortletRequest from JSF context
PortletRequest portletRequest = (PortletRequest) FacesContext .getCurrentInstance()
.getExternalContext().getRequest();
2. get the logged in user id
String userId = portletRequest .getRemoteUser();
3. get the user model with Liferay API
User user = UserServiceUtil.getUserById(Long.valueOf(userId));
Done!!
No comments:
Post a Comment