}
public void persistUserInfo(User user, IdentitySession session, boolean isNew) {
orgService.flush();
AttributesManager am = session.getAttributesManager();
ArrayList attributes = new ArrayList();
if (user.getCreatedDate() != null) {
attributes.add(new SimpleAttribute(USER_CREATED_DATE, "" + user.getCreatedDate().getTime()));
}
if (user.getLastLoginTime() != null) {
attributes.add(new SimpleAttribute(USER_LAST_LOGIN_TIME, "" + user.getLastLoginTime().getTime()));
}
if (user.getEmail() != null) {
attributes.add(new SimpleAttribute(USER_EMAIL, user.getEmail()));
}
if (user.getFirstName() != null) {
attributes.add(new SimpleAttribute(USER_FIRST_NAME, user.getFirstName()));
}
if (user.getLastName() != null) {
attributes.add(new SimpleAttribute(USER_LAST_NAME, user.getLastName()));
}
// TODO: GTNPORTAL-2358 Change once displayName will be available as part of Organization API
if (user instanceof UserImpl) {
UserImpl userImpl = (UserImpl) user;
if (userImpl.getDisplayName() != null) {
attributes.add(new SimpleAttribute(USER_DISPLAY_NAME, ((UserImpl) user).getDisplayName()));
} else {
removeDisplayNameIfNeeded(am, user);
}
if (isNew) {
attributes.add(new SimpleAttribute(USER_ENABLED, Boolean.TRUE.toString()));
}
} else {
log.warn("User is of class " + user.getClass() + " which is not instanceof " + UserImpl.class);
}
if (user.getOrganizationId() != null) {
attributes.add(new SimpleAttribute(USER_ORGANIZATION_ID, user.getOrganizationId()));
}
if (user.getPassword() != null) {
if (orgService.getConfiguration().isPasswordAsAttribute()) {
attributes.add(new SimpleAttribute(USER_PASSWORD, user.getPassword()));
} else {
try {
am.updatePassword(session.getPersistenceManager().findUser(user.getUserName()), user.getPassword());
} catch (Exception e) {
handleException("Cannot update password: " + user.getUserName() + "; ", e);
}
}
}
Attribute[] attrs = new Attribute[attributes.size()];
attrs = (Attribute[]) attributes.toArray(attrs);
try {
am.updateAttributes(user.getUserName(), attrs);
} catch (Exception e) {
handleException("Cannot update attributes for user: " + user.getUserName() + "; ", e);
}