This commit is contained in:
Massimiliano Assante 2016-11-15 17:17:59 +00:00
parent 6e1dd2d46d
commit e6bbddf015
1 changed files with 20 additions and 12 deletions

View File

@ -24,8 +24,7 @@ public class ContextUserUtil {
* @param httpServletRequest
* @returnthe current user LR id
*/
protected static Long getCurrentUserId(HttpServletRequest httpServletRequest) {
protected static Long getCurrentUserId(HttpServletRequest httpServletRequest) {
Cookie[] cookies = httpServletRequest.getCookies();
String userId = null;
String companyId = null;
@ -46,18 +45,27 @@ public class ContextUserUtil {
} catch (Exception 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;
return getUserFromHeader(httpServletRequest);
}
} else {
_log.debug("Something wrong with cookies, returning current user from http header");
return getUserFromHeader(httpServletRequest);
}
}
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;
try {
userIdToReturn = Long.parseLong(userHeaderIdString);
} catch (NumberFormatException e) {
_log.error("The userId is not a number -> " + userHeaderIdString);
}
return userIdToReturn;
}
private static String hexStringToStringByAscii(String hexString) {