API Übersicht

Szenarien der Verwendung

Szenarien der Authentifizierung

OpenLDAP

ActiveDirectory

Grundsätzliche CRUD Operationen

Daten von LDAP empfangen

Example #1 Einen Eintrag durch seinen DN erhalten

  1. $options = array(/* ... */);
  2. $ldap = new Zend_Ldap($options);
  3. $ldap->bind();
  4. $hm = $ldap->getEntry('cn=Hugo Müller,ou=People,dc=my,dc=local');
  5. /*
  6. $hm is an array of the following structure
  7. array(
  8.     'dn'          => 'cn=Hugo Müller,ou=People,dc=my,dc=local',
  9.     'cn'          => array('Hugo Müller'),
  10.     'sn'          => array('Müller'),
  11.     'objectclass' => array('inetOrgPerson', 'top'),
  12.     ...
  13. )
  14. */

Example #2 Die Existenz eines angegebenen DN prüfen

  1. $options = array(/* ... */);
  2. $ldap = new Zend_Ldap($options);
  3. $ldap->bind();
  4. $isThere = $ldap->exists('cn=Hugo Müller,ou=People,dc=my,dc=local');

Example #3 Kinder eines angegebenen DN zählen

  1. $options = array(/* ... */);
  2. $ldap = new Zend_Ldap($options);
  3. $ldap->bind();
  4. $childrenCount = $ldap->countChildren(
  5.                             'cn=Hugo Müller,ou=People,dc=my,dc=local');

Example #4 Im LDAP Baum suchen

  1. $options = array(/* ... */);
  2. $ldap = new Zend_Ldap($options);
  3. $ldap->bind();
  4. $result = $ldap->search('(objectclass=*)',
  5.                         'ou=People,dc=my,dc=local',
  6.                         Zend_Ldap_Ext::SEARCH_SCOPE_ONE);
  7. foreach ($result as $item) {
  8.     echo $item["dn"] . ': ' . $item['cn'][0] . PHP_EOL;
  9. }

Daten zu LDAP hinzufügen

Example #5 Einen neuen Eintrag zu LDAP hinzufügen

  1. $options = array(/* ... */);
  2. $ldap = new Zend_Ldap($options);
  3. $ldap->bind();
  4. $entry = array();
  5. Zend_Ldap_Attribute::setAttribute($entry, 'cn', 'Hans Meier');
  6. Zend_Ldap_Attribute::setAttribute($entry, 'sn', 'Meier');
  7. Zend_Ldap_Attribute::setAttribute($entry, 'objectClass', 'inetOrgPerson');
  8. $ldap->add('cn=Hans Meier,ou=People,dc=my,dc=local', $entry);

In LDAP löschen

Example #6 Einen existierenden Eintrag von LDAP löschen

  1. $options = array(/* ... */);
  2. $ldap = new Zend_Ldap($options);
  3. $ldap->bind();
  4. $ldap->delete('cn=Hans Meier,ou=People,dc=my,dc=local');

LDAP aktualisieren

Example #7 Einen existierenden Eintrag in LDAP aktualisieren

  1. $options = array(/* ... */);
  2. $ldap = new Zend_Ldap($options);
  3. $ldap->bind();
  4. $hm = $ldap->getEntry('cn=Hugo Müller,ou=People,dc=my,dc=local');
  5. Zend_Ldap_Attribute::setAttribute($hm, 'mail', 'mueller@my.local');
  6. Zend_Ldap_Attribute::setPassword($hm,
  7.                                  'newPa$$w0rd',
  8.                                  Zend_Ldap_Attribute::PASSWORD_HASH_SHA1);
  9. $ldap->update('cn=Hugo Müller,ou=People,dc=my,dc=local', $hm);

Erweiterte Operationen

Kopieren und Verschieben von Einträgen in LDAP

Example #8 Einen LDAP Eintrag mit allen seinen Abhängigkeiten rekursiv kopieren

  1. $options = array(/* ... */);
  2. $ldap = new Zend_Ldap($options);
  3. $ldap->bind();
  4. $ldap->copy('cn=Hugo Müller,ou=People,dc=my,dc=local',
  5.             'cn=Hans Meier,ou=People,dc=my,dc=local',
  6.             true);

Example #9 Einen LDAP Eintrag rekursiv in einen anderen Unterbaum verschieben mit allen seinen Abhängigkeiten

  1. $options = array(/* ... */);
  2. $ldap = new Zend_Ldap($options);
  3. $ldap->bind();
  4. $ldap->moveToSubtree('cn=Hugo Müller,ou=People,dc=my,dc=local',
  5.                      'ou=Dismissed,dc=my,dc=local',
  6.                      true);

API Übersicht