AnsweredAssumed Answered

Problem adding new user in LDAP by logic Hook

Question asked by jlabuelo on Dec 16, 2014
Hi there

I am trying to integrate two systems between Joomla3 and SugarCRM CE 6.5. User password management is done by LDAP so both users in Joomla3 and SugarCRM will use this authentication system.

However what we need to is to get SugarCRM to be the system where the users are created, as I dont want the person in charge of creating new accounts to work with LDAP.


We are creating a logic_hook before save function under the Users module, so when a new user is created in SugarCRM

1) Checks that it does not exists in LDAP - DONE
2) If it does not exists we launch this before_save function to create it - FAILING

This is the function we are calling (it receives the user bean that is being saved), and I dont know why it is failing at line ldap_add... however do not why, or even do not know how to debug the error, as only the "FALSE" value is returned.

Any ideas please??




function Add_LDAP ($user)
{
   $ldap_host = 'localhost';
        $base_dn = 'CN='.$user->user_name.',DC=regiac,DC=org';
        $GLOBALS['log']->fatal($base_dn);
        //Preparamos el usuario para crearlo
        $info["givenName"]=$user->first_name;
        $info["sn"]=$user->last_name;
        $info["uid"]=$user->user_name;
        $info["homeDirectory"]="/home/";
        $info["mail"]=$user->email1;
        $info["displayName"]= $user->first_name." ".$user->last_name;
        $info["departmentNumber"]=$user->id;
        $info["cn"] =$user->user_name;
        $info["userPassword"]=$user->user_hash;
        $info["objectclass"][0] = "top";
        $info["objectclass"][1] = "person";
        $info["objectclass"][2] = "inetOrgPerson";
        $info["objectclass"][3] = "organizationalPerson";



        $ldap_user  = "CN=admin,DC=regiac,DC=org";
        $ldap_pass = "passw";

        //First: Connect to  LDAP Server
        $connect = ldap_connect( $ldap_host, $ldap_port)
         or $GLOBALS['log']->fatal(">>Could not connect to LDAP server to add user<<");
        ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
        ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
       
//Login to LDAP
        $bind = ldap_bind($connect, $ldap_user, $ldap_pass)
           or $GLOBALS['log']->fatal(">>Could not bind to $ldap_host to add user<<");
       
// Adding new user - Here it is where it fails

    $add = ldap_add($connect, $base_dn, $info)
      or $GLOBALS['log']->fatal(">>Not able to load user <<");
       
// Close connection
       ldap_close($connect);
   
   // Return value of operation

        return $add;


 

}

Outcomes