minor fix when in devMode

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portal/portal-manager@134772 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-11-25 11:36:55 +00:00
parent a262793eff
commit 41919aad9a
2 changed files with 24 additions and 4 deletions

View File

@ -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;
}
}
}

View File

@ -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());