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

@ -25,7 +25,6 @@ public class ContextUserUtil {
* @returnthe current user LR id * @returnthe current user LR id
*/ */
protected static Long getCurrentUserId(HttpServletRequest httpServletRequest) { protected static Long getCurrentUserId(HttpServletRequest httpServletRequest) {
Cookie[] cookies = httpServletRequest.getCookies(); Cookie[] cookies = httpServletRequest.getCookies();
String userId = null; String userId = null;
String companyId = null; String companyId = null;
@ -46,6 +45,19 @@ public class ContextUserUtil {
} catch (Exception pException) { } catch (Exception pException) {
_log.warn("Exception while getting current user from cookie, returning current user from http header"); _log.warn("Exception while getting current user from cookie, returning current user from http header");
return getUserFromHeader(httpServletRequest);
}
} else {
_log.debug("Something wrong with cookies, returning current user from http header");
return getUserFromHeader(httpServletRequest);
}
} 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); String userHeaderIdString = httpServletRequest.getHeader(PortalContext.USER_ID_ATTR_NAME);
long userIdToReturn = -1; long userIdToReturn = -1;
try { try {
@ -55,10 +67,6 @@ public class ContextUserUtil {
} }
return userIdToReturn; return userIdToReturn;
} }
}
}
return null;
}
private static String hexStringToStringByAscii(String hexString) { private static String hexStringToStringByAscii(String hexString) {
byte[] bytes = new byte[hexString.length() / 2]; byte[] bytes = new byte[hexString.length() / 2];