Scénarios d'utilisation
Scénarios d'authentification
OpenLDAP
ActiveDirectory
Opérations CRUD basiques
Récupérer des données depuis LDAP
Récupérer une entrée grâce à son DN
bind();
$hm = $ldap->getEntry('cn=Hugo Müller,ou=People,dc=my,dc=local');
/*
$hm est un tableau à la structure suivante:
array(
'dn' => 'cn=Hugo Müller,ou=People,dc=my,dc=local',
'cn' => array('Hugo Müller'),
'sn' => array('Müller'),
'objectclass' => array('inetOrgPerson', 'top'),
...
)
*/
]]>
Vérifier l'existence d'un DN donné
bind();
$isThere = $ldap->exists('cn=Hugo Müller,ou=People,dc=my,dc=local');
]]>
Compter les enfants d'un DN donné
bind();
$childrenCount = $ldap->countChildren(
'cn=Hugo Müller,ou=People,dc=my,dc=local');
]]>
Chercher dans l'arbre LDAP
bind();
$result = $ldap->search('(objectclass=*)',
'ou=People,dc=my,dc=local',
Zend_Ldap_Ext::SEARCH_SCOPE_ONE);
foreach ($result as $item) {
echo $item["dn"] . ': ' . $item['cn'][0] . PHP_EOL;
}
]]>
Ajouter des données à LDAP
Ajouter une nouvelle entrée à LDAP
bind();
$entry = array();
Zend_Ldap_Attribute::setAttribute($entry, 'cn', 'Hans Meier');
Zend_Ldap_Attribute::setAttribute($entry, 'sn', 'Meier');
Zend_Ldap_Attribute::setAttribute($entry, 'objectClass', 'inetOrgPerson');
$ldap->add('cn=Hans Meier,ou=People,dc=my,dc=local', $entry);
]]>
Supprimer de LDAP
Supprimer une entrée existante de LDAP
bind();
$ldap->delete('cn=Hans Meier,ou=People,dc=my,dc=local');
]]>
Mettre à jour LDAP
Mettre à jour une entrée existante dans LDAP
bind();
$hm = $ldap->getEntry('cn=Hugo Müller,ou=People,dc=my,dc=local');
Zend_Ldap_Attribute::setAttribute($hm, 'mail', 'mueller@my.local');
Zend_Ldap_Attribute::setPassword($hm,
'newPa$$w0rd',
Zend_Ldap_Attribute::PASSWORD_HASH_SHA1);
$ldap->update('cn=Hugo Müller,ou=People,dc=my,dc=local', $hm);
]]>
Opérations avancées
Copier et déplacer des entrées LDAP
Copier une entrée LDAP récursivement avec tous ses descendants
bind();
$ldap->copy('cn=Hugo Müller,ou=People,dc=my,dc=local',
'cn=Hans Meier,ou=People,dc=my,dc=local',
true);
]]>
Déplacer une entrée LDAP récursivement vers un sous-arbre différent
bind();
$ldap->moveToSubtree('cn=Hugo Müller,ou=People,dc=my,dc=local',
'ou=Dismissed,dc=my,dc=local',
true);
]]>