}
}
// Pr�fen, ob user bereits vorhanden ist
Users u = null;
try{
u= Usermanagement.getInstance().getUserByLogin(user);
}catch(Exception e){
log.error("Error retrieving Userdata : " + e.getMessage());
}
// User not existant in local database -> take over data for referential integrity
if(u == null){
log.debug("user doesnt exist local -> create new");
// Attributes to retrieve from ldap
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
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);
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);
try{
//Create User with LdapData
Long userid;
if (ldap_sync_passwd_to_om != null && ldap_sync_passwd_to_om.equals("no")){
Random r = new Random();
String token = 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);
}
// Update Session
Boolean bool = Sessionmanagement.getInstance().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
Users u2 = Usermanagement.getInstance().getUserById(userid);
if(u2 == null)
return new Long(-1);
u2.setExternalUserType(EXTERNAL_USER_TYPE_LDAP); //TIBO
//initialize lazy collection
Usermanagement.getInstance().refreshUserObject(u2);
log.debug("getUserbyId : " + userid + " : " + u2.getLogin());
return u2;
}catch(Exception e){
log.error("Error on Working Userdata : " , e);