diff --git a/src/main/java/org/gcube/common/portal/ContextUserUtil.java b/src/main/java/org/gcube/common/portal/ContextUserUtil.java index 7da46d1..e1a251d 100644 --- a/src/main/java/org/gcube/common/portal/ContextUserUtil.java +++ b/src/main/java/org/gcube/common/portal/ContextUserUtil.java @@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory; import com.liferay.portal.model.Company; import com.liferay.portal.service.CompanyLocalServiceUtil; +import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.util.Encryptor; /** * @@ -48,15 +49,20 @@ public class ContextUserUtil { return getUserFromHeader(httpServletRequest); } } else { - _log.debug("Something wrong with cookies, returning current user from http header"); - return getUserFromHeader(httpServletRequest); + if (isWithinPortal()) { + _log.debug("Something wrong with cookies, returning current user from http header"); + return getUserFromHeader(httpServletRequest); + } else { //you must be in dev + _log.debug("DEV MODE Intercepted ..."); + return null; + } } } else { _log.warn("Cookies are not present, returning current user from http header"); return getUserFromHeader(httpServletRequest); } } - + private static long getUserFromHeader(HttpServletRequest httpServletRequest) { String userHeaderIdString = httpServletRequest.getHeader(PortalContext.USER_ID_ATTR_NAME); long userIdToReturn = -1; @@ -80,4 +86,18 @@ public class ContextUserUtil { throw new RuntimeException(e); } } + /** + * + * @return true if you're running into the portal, false if in development + */ + private static boolean isWithinPortal() { + try { + UserLocalServiceUtil.getService(); + return true; + } + catch (Exception ex) { + _log.trace("Development Mode ON"); + return false; + } + } } diff --git a/src/main/java/org/gcube/common/portal/PortalContext.java b/src/main/java/org/gcube/common/portal/PortalContext.java index a46607f..da6a4ba 100644 --- a/src/main/java/org/gcube/common/portal/PortalContext.java +++ b/src/main/java/org/gcube/common/portal/PortalContext.java @@ -608,7 +608,7 @@ public class PortalContext { /** * for development purposes only */ - private static GCubeUser readUserFromPropertyFile() { + protected static GCubeUser readUserFromPropertyFile() { Properties props = new Properties(); try { StringBuilder sb = new StringBuilder(getGCubeDevHome());