}
/** Get Liferay user by given servlet request */
protected User getLiferayUser(HttpServletRequest req) throws ServletException
{
User userByScreenName = null;
/* Try to authorized user by given servlet request.
* We have to use cookies, otherwise authentication
* won't work on WebSphere
*/
String userId = null;
String password = null;
String companyId = null;
for (Cookie c : req.getCookies())
{
if ("COMPANY_ID".equals(c.getName())) {
companyId = c.getValue();
} else if ("ID".equals(c.getName())) {
userId = hexStringToStringByAscii(c.getValue());
} else if ("PASSWORD".equals(c.getName())) {
password = hexStringToStringByAscii(c.getValue());
}
}
if (userId != null && password != null && companyId != null) {
try {
KeyValuePair kvp = UserLocalServiceUtil.decryptUserId(Long.parseLong(companyId), userId, password);
userByScreenName = UserLocalServiceUtil.getUserById(Long.valueOf(kvp.getKey()));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(userByScreenName == null)
{
logger.warning("Failed to authorize user");
return null;
}
logger.info("Successfully authorized user: " + userByScreenName.getScreenName());
return userByScreenName;
}