String openIdAccName = (String) session.getAttribute(OpenIdConstants.HTTPSESSION_OPENID_ID);
String openIdProvider = (String) session.getAttribute(OpenIdConstants.HTTPSESSION_OPENID_PROVIDER);
String salt = (String) session.getAttribute(AuthenticationConstants.NEW_SALT);
if (userOpenId == null && salt != null) {
UserData userData = AuthenticationUtil.createUserData(UserId.getUserId(userName));
userData.setProperty(OpenIdUtil.REGISTRATION_RESULT_PROP, OpenIdConstants.REGISTER_USER_ERROR);
return userData;
}
User user = MetaProjectManager.getManager().getMetaProject().getUser(userName);
if (user != null) {
UserData userData = AuthenticationUtil.createUserData(UserId.getUserId(userName));
userData.setProperty(OpenIdUtil.REGISTRATION_RESULT_PROP, OpenIdConstants.USER_ALREADY_EXISTS);
return userData;
}
UserData userData = MetaProjectManager.getManager().registerUser(userName, emailId, "");
user = MetaProjectManager.getManager().getMetaProject().getUser(userName);
user.setEmail(emailId);
user.setDigestedPassword(hashedPassword, salt);
String openIdPropBase = OpenIdConstants.OPENID_PROPERTY_PREFIX;
for (int index = 1;; index++) {
String opnId = user.getPropertyValue(openIdPropBase + index + OpenIdConstants.OPENID_PROPERTY_URL_SUFFIX);
if (opnId == null) {
user.addPropertyValue(openIdPropBase + index + OpenIdConstants.OPENID_PROPERTY_URL_SUFFIX, userOpenId);
user.addPropertyValue(openIdPropBase + index + OpenIdConstants.OPENID_PROPERTY_ID_SUFFIX, openIdAccName);
user.addPropertyValue(openIdPropBase + index + OpenIdConstants.OPENID_PROPERTY_PROVIDER_SUFFIX, openIdProvider);
break;
}
}
Log.getLogger().info("User " + userName + " created at: " + new Date() + " with OpenId: " + userOpenId);
session.setAttribute(OpenIdConstants.CREATED_USER_TO_ASSOC_OPEN_ID, userData);
session.setAttribute(OpenIdConstants.HTTPSESSION_OPENID_URL, null);
session.setAttribute(OpenIdConstants.HTTPSESSION_OPENID_ID, null);
session.setAttribute(OpenIdConstants.HTTPSESSION_OPENID_PROVIDER, null);
userData.setProperty(OpenIdUtil.REGISTRATION_RESULT_PROP, OpenIdConstants.REGISTER_USER_SUCCESS);
return userData;
}