added method for getting the user form PortalDelegateServlets

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portal/portal-manager@141523 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2017-01-12 10:52:20 +00:00
parent 16f03b92db
commit aa60ad1c38
1 changed files with 30 additions and 1 deletions

View File

@ -26,6 +26,8 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.VirtualHost;
import com.liferay.portal.service.CompanyLocalServiceUtil;
@ -82,7 +84,7 @@ public class PortalContext {
private static PortalContext singleton = new PortalContext();
private UserManager userManager;
private String infra;
private String vos;
@ -169,6 +171,33 @@ public class PortalContext {
}
return null;
}
/**
* <p>
* Please note that this method works with Liferay's PortalDelegateServlet feature {@link com.liferay.portal.kernel.servlet.PortalDelegateServlet}.
* For documentation on PortalDelegateServlet @see <a href="https://wiki.gcube-system.org/gcube/Portal_Context#Liferay.27s_PortalDelegateServlet_.28Custom_servlets_running_in_the_ROOT_context.29">gCube WIKI PortalDelegateServlet page</a>
* </p>
*
* @param httpServletRequest the {@link HttpServletRequest} object
* @return the current user, or <code>null</code> if a current user could not be found
* @see {@link GCubeUser}
*/
public GCubeUser getCurrentUserPortalDelegateServlet(HttpServletRequest httpServletRequest) {
try {
if (PortalUtil.getUser(httpServletRequest) != null) {
long userId = PortalUtil.getUser(httpServletRequest).getUserId();
return userManager.getUserById(userId);
}
else {
//the user is not logged in or session expired
_log.debug("Can't find the user, session expired or your not using ");
return null;
}
} catch (PortalException | SystemException | UserManagementSystemException | UserRetrievalFault e) {
_log.error("Could not read the current userid, either session expired or user not logged in, exception: " + e.getMessage());
e.printStackTrace();
}
return null;
}
/**
* @param scopeGroupId the liferay groupid number (as String) of the VRE/VO
* @return the scope (context)