final String md5password = DigestUtils.md5Hex(password);
_sessionId = new LazyRef<String>() {
@Override
protected String fetch() {
UserAuth userAuth = new UserAuth();
userAuth.setUserName(username);
userAuth.setPassword(md5password);
logger.debug("Logging in as '{}', with application name '{}'", username, applicationName);
EntryValue response = _service.login(userAuth, applicationName, new NameValueList());
String sessionId = response.getId();
logger.info("Started session with SugarCRM. Session ID: {}", sessionId);
return sessionId;