利用シナリオ 認証シナリオ OpenLDAP ActiveDirectory 基本的なCRUD操作 LDAPからデータを取得 そのDNで項目を取得 bind(); $hm = $ldap->getEntry('cn=Hugo Müller,ou=People,dc=my,dc=local'); /* $hm は下記の構造の配列 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'), ... ) */ ]]> 与えられたDNが存在するかチェック bind(); $isThere = $ldap->exists('cn=Hugo Müller,ou=People,dc=my,dc=local'); ]]> 与えられたDNの子供を数える bind(); $childrenCount = $ldap->countChildren( 'cn=Hugo Müller,ou=People,dc=my,dc=local'); ]]> 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; } ]]> LDAPにデータを追加 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); ]]> LDAPからデータを削除 LDAPから存在する項目を削除 bind(); $ldap->delete('cn=Hans Meier,ou=People,dc=my,dc=local'); ]]> LDAPを更新 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); ]]> 拡張された操作 LDAPで項目をコピーまたは移動 LDAP項目をその全ての派生物と共に再帰的にコピー bind(); $ldap->copy('cn=Hugo Müller,ou=People,dc=my,dc=local', 'cn=Hans Meier,ou=People,dc=my,dc=local', true); ]]> LDAP項目をその全ての派生物と共に再帰的に異なるサブツリーに移動 bind(); $ldap->moveToSubtree('cn=Hugo Müller,ou=People,dc=my,dc=local', 'ou=Dismissed,dc=my,dc=local', true); ]]>