}
}
// check if user already exists
User u = null;
try {
u = userManager.getUserByLogin(user);
} catch (Exception e) {
log.error("Error retrieving Userdata : " + e.getMessage());
}
// Attributes to retrieve from ldap to either create or update the user
List<String> attributes = new ArrayList<String>();
attributes.add(ldap_user_attr_lastname); // Lastname
attributes.add(ldap_user_attr_firstname); // Firstname
attributes.add(ldap_user_attr_mail);// mail
attributes.add(ldap_user_attr_street); // Street
attributes.add(ldap_user_attr_additional_name); // Additional name
attributes.add(ldap_user_attr_fax); // Fax
attributes.add(ldap_user_attr_zip); // ZIP
attributes.add(ldap_user_attr_country); // Country
attributes.add(ldap_user_attr_town); // Town
attributes.add(ldap_user_attr_phone); // Phone
attributes.add(ldap_user_attr_timezone); // timezone
if (ldap_user_picture_uri != null) {
attributes.add(ldap_user_picture_uri); //picture uri
}
HashMap<String, String> ldapAttrs = new HashMap<String, String>();
ldapAttrs.put("lastnameAttr", ldap_user_attr_lastname);
ldapAttrs.put("firstnameAttr", ldap_user_attr_firstname);
ldapAttrs.put("mailAttr", ldap_user_attr_mail);
ldapAttrs.put("streetAttr", ldap_user_attr_street);
ldapAttrs.put("additionalNameAttr", ldap_user_attr_additional_name);
ldapAttrs.put("faxAttr", ldap_user_attr_fax);
ldapAttrs.put("zipAttr", ldap_user_attr_zip);
ldapAttrs.put("countryAttr", ldap_user_attr_country);
ldapAttrs.put("townAttr", ldap_user_attr_town);
ldapAttrs.put("phoneAttr", ldap_user_attr_phone);
ldapAttrs.put("timezoneAttr", ldap_user_attr_timezone);
if (ldap_user_picture_uri != null) {
ldapAttrs.put("pictureUri", ldap_user_picture_uri);
}
Vector<HashMap<String, String>> result = lAuth.getData(
ldap_search_scope, ldap_search_filter, attributes);
if (result == null || result.size() < 1) {
log.error("Error on Ldap request - no result for user " + user);
return new Long(-10);
}
if (result.size() > 1) {
log.error("Error on Ldap request - more than one result for user " + user);
return null;
}
HashMap<String, String> userData = result.get(0);
// User not existant in local database -> take over data for referential
// integrity
if (u == null) {
log.debug("user doesnt exist local -> create new");
try {
// Create User with LdapData
Long userid;
if (ldap_sync_passwd_to_om) {
Random r = new Random();
String token = UUID.randomUUID().toString() + Long.toString(Math.abs(r.nextLong()), 36);
log.debug("Synching Ldap user to OM DB with RANDOM password: " + token);
userid = createUserFromLdapData(userData, token, user, ldapAttrs);
} else {
log.debug("Synching Ldap user to OM DB with password");
userid = createUserFromLdapData(userData, passwd, user, ldapAttrs);
}
log.debug("New User ID : " + userid);
// If invoked via SOAP this is NULL
if (currentClient != null) {
currentClient.setUser_id(userid);
SessionVariablesUtil.setUserId(client, userid);
}
// Update Session
Boolean bool = sessiondataDao.updateUser(SID, userid);
if (bool == null) {
// Exception
log.error("Error on Updating Session");
return new Long(-1);
} else if (!bool) {
// invalid Session-Object
log.error("Invalid Session Object");
return new Long(-35);
}
// Return UserObject
User u2 = userManager.getUserById(userid);
if (u2 == null) {
return new Long(-1);
}
u2.setType(Type.ldap);
// initialize lazy collection
userManager.refreshUserObject(u2);
log.debug("getUserbyId : " + userid + " : " + u2.getLogin());
return u2;
} catch (Exception e) {
log.error("Error on Working Userdata : ", e);
return new Long(-1);