removed ASL Session, ported to gCube Client Context

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portal/portal-manager@134195 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-11-15 14:27:19 +00:00
parent d034412bbe
commit 6e1dd2d46d
1 changed files with 14 additions and 1 deletions

View File

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