diff --git a/src/main/java/org/gcube/common/portal/ContextUserUtil.java b/src/main/java/org/gcube/common/portal/ContextUserUtil.java index 9dba846..7600496 100644 --- a/src/main/java/org/gcube/common/portal/ContextUserUtil.java +++ b/src/main/java/org/gcube/common/portal/ContextUserUtil.java @@ -6,6 +6,9 @@ import java.security.Key; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.liferay.portal.model.Company; import com.liferay.portal.service.CompanyLocalServiceUtil; import com.liferay.util.Encryptor; @@ -15,12 +18,14 @@ import com.liferay.util.Encryptor; * */ public class ContextUserUtil { + private static final Logger _log = LoggerFactory.getLogger(PortalContext.class); /** * * @param httpServletRequest * @returnthe current user LR id */ protected static Long getCurrentUserId(HttpServletRequest httpServletRequest) { + Cookie[] cookies = httpServletRequest.getCookies(); String userId = null; String companyId = null; @@ -40,7 +45,15 @@ public class ContextUserUtil { return Long.valueOf(userIdPlain); } catch (Exception pException) { - throw new RuntimeException(pException); + _log.warn("Exception while getting current user from cookie, returning current user from http header"); + String userHeaderIdString = httpServletRequest.getHeader(PortalContext.USER_ID_ATTR_NAME); + long userIdToReturn = -1; + try { + userIdToReturn = Long.parseLong(userHeaderIdString); + } catch (NumberFormatException e) { + _log.error("The userId is not a number -> " + userHeaderIdString); + } + return userIdToReturn; } } }