Merge pull request #692 from atm-maxime/develop

LDAP sync improvements
This commit is contained in:
Laurent Destailleur 2013-02-25 03:36:37 -08:00
commit 00e8f78b77
3 changed files with 58 additions and 27 deletions

View File

@ -874,9 +874,10 @@ class Ldap
* @param string $useridentifier Name of key field (Ex: uid)
* @param array $attributeArray Array of fields required. Note this array must also contains field $useridentifier (Ex: sn,userPassword)
* @param int $activefilter 1=use field this->filter as filter instead of parameter $search
* @param array $attributeAsArray Array of fields wanted as an array not a string
* @return array Array of [id_record][ldap_field]=value
*/
function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter=0)
function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter=0, $attributeAsArray=array())
{
$fulllist=array();
@ -955,7 +956,15 @@ class Ldap
}
else
{
$fulllist[$recordid][$attributeArray[$j]] = $this->convToOutputCharset($info[$i][$keyattributelower][0],$this->ldapcharset);
if(in_array($attributeArray[$j], $attributeAsArray) && is_array($info[$i][$keyattributelower])) {
$valueTab = array();
foreach($info[$i][$keyattributelower] as $key => $value) {
$valueTab[$key] = $this->convToOutputCharset($value,$this->ldapcharset);
}
$fulllist[$recordid][$attributeArray[$j]] = $valueTab;
} else {
$fulllist[$recordid][$attributeArray[$j]] = $this->convToOutputCharset($info[$i][$keyattributelower][0],$this->ldapcharset);
}
}
}
}

View File

@ -110,7 +110,7 @@ class InterfaceLdapsynchro
if ($action == 'USER_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
@ -129,7 +129,7 @@ class InterfaceLdapsynchro
elseif ($action == 'USER_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
@ -166,7 +166,7 @@ class InterfaceLdapsynchro
elseif ($action == 'USER_NEW_PASSWORD')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
@ -207,7 +207,7 @@ class InterfaceLdapsynchro
elseif ($action == 'USER_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
@ -226,7 +226,7 @@ class InterfaceLdapsynchro
elseif ($action == 'USER_SETINGROUP')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
@ -264,7 +264,7 @@ class InterfaceLdapsynchro
elseif ($action == 'USER_REMOVEFROMGROUP')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
@ -304,7 +304,7 @@ class InterfaceLdapsynchro
elseif ($action == 'GROUP_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
@ -327,7 +327,7 @@ class InterfaceLdapsynchro
elseif ($action == 'GROUP_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();
@ -364,7 +364,7 @@ class InterfaceLdapsynchro
elseif ($action == 'GROUP_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
if (! empty($conf->ldap->enabled) && ! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
{
$ldap=new Ldap();
$ldap->connect_bind();

View File

@ -178,6 +178,8 @@ if ($result >= 0)
foreach ($ldaprecords as $key => $ldapuser)
{
$fuser = new User($db);
$fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné
// Propriete membre
$fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
@ -210,6 +212,7 @@ if ($result >= 0)
$fuser->fk_member=0;
$fuser->statut=1;
// TODO : revoir la gestion du status
/*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
{
$fuser->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
@ -219,25 +222,44 @@ if ($result >= 0)
//if ($fuser->statut > 1) $fuser->statut=1;
//print_r($ldapuser);
// Group of user
// We should use here $groupid
// Creation member
print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
$fuser_id=$fuser->create($user);
if ($fuser_id > 0)
{
print ' --> Created member id='.$fuser_id.' login='.$fuser->login;
}
else
{
$error++;
print ' --> '.$fuser_id.' '.$fuser->error;
if($fuser->id > 0) { // User update
print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
$res=$fuser->update($user);
if ($res < 0)
{
$error++;
print ' --> '.$res.' '.$fuser->error;
}
else
{
print ' --> Updated user id='.$fuser->id.' login='.$fuser->login;
}
} else { // User creation
print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
$res=$fuser->create($user);
if ($res > 0)
{
print ' --> Created user id='.$fuser->id.' login='.$fuser->login;
}
else
{
$error++;
print ' --> '.$res.' '.$fuser->error;
}
}
print "\n";
//print_r($fuser);
// Gestion des groupes
// TODO : revoir la gestion des groupes (ou script de sync groupes)
/*if(!$error) {
foreach ($ldapuser[$conf->global->LDAP_FIELD_USERGROUPS] as $groupdn) {
$groupdn;
}
}*/
}
if (! $error || $forcecommit)