/** * Returns entries sorted as objects. * * This returns a array with sorted Horde_Ldap_Entry objects. The sorting * is actually done with {@link sortedAsArray()}. * * Please note that attribute names are case sensitive! * * Also note that it is (depending on server capabilities) possible to let * the server sort your results. This happens through search controls and * is described in detail at {@link http://www.ietf.org/rfc/rfc2891.txt} * * Usage example: * <code> * // To sort entries first by location, then by surname, but descending: * $entries = $search->sorted(array('locality', 'sn'), SORT_DESC); * </code> * * @todo Entry object construction could be faster. Maybe we could use one * of the factories instead of fetching the entry again. * * @param array $attrs Attribute names as sort criteria. * @param integer $order Ordering direction, either constant SORT_ASC or * SORT_DESC * * @return array Sorted entries. * @throws Horde_Ldap_Exception */ public function sorted($attrs = array('cn'), $order = SORT_ASC) { $return = array(); $sorted = $this->sortedAsArray($attrs, $order); foreach ($sorted as $row) { $entry = $this->_ldap->getEntry($row['dn'], $this->searchedAttributes()); $return[] = $entry; } return $return; }
/** * Removes a user from a group. * * @param mixed $gid A group ID. * @param string $user A user name. * * @throws Horde_Group_Exception * @throws Horde_Exception_NotFound */ public function removeUser($gid, $user) { if ($this->readOnly()) { throw new Horde_Group_Exception('This group backend is read-only.'); } $attr = $this->_params['memberuid']; try { if (!empty($this->_params['attrisdn'])) { $user = $this->_ldap->findUserDN($user); } $entry = $this->_ldap->getEntry($gid, array($attr)); $entry->delete(array($attr => $user)); $this->_rebind(true); $entry->update(); $this->_rebind(false); } catch (Horde_Ldap_Exception $e) { throw new Horde_Group_Exception($e); } }
/** */ public function remove($scope = null, $pref = null) { if (is_null($scope)) { // Clear all scopes. $scopes = $this->listScopes(); } else { $scopes = array($scope); } foreach ($scopes as $s) { // getEntry() converts attribute indexes to lowercase. $field = Horde_String::lower($s . 'Prefs'); try { $prefs = $this->_ldap->getEntry($this->_prefsDN, array($field)); } catch (Horde_Ldap_Exception $e) { throw new Horde_Prefs_Exception($e); } if (is_null($pref)) { // Clear entire scope. $prefs->delete(array($field)); } elseif ($prefs->exists($field)) { // Find preference to clear. foreach ($prefs->getValue($field, 'all') as $prefstr) { // Split the string into its name:value components. list($name, $val) = explode(':', $prefstr, 2); if ($name == $pref) { $prefs->delete(array($field => $prefstr)); } } } try { $prefs->update(); } catch (Horde_Ldap_Exception $e) { throw new Horde_Prefs_Exception($e); } } }
/** * Test move(). */ public function testMove() { $ldap = new Horde_Ldap(self::$ldapcfg['server']); // For Moving tests, we need some little tree again. $base = self::$ldapcfg['server']['basedn']; $testdn = 'ou=Horde_Ldap_Test_move,' . $base; $ou = Horde_Ldap_Entry::createFresh($testdn, array('objectClass' => array('top', 'organizationalUnit'), 'ou' => 'Horde_Ldap_Test_move')); $ou_1 = Horde_Ldap_Entry::createFresh('ou=source,' . $testdn, array('objectClass' => array('top', 'organizationalUnit'), 'ou' => 'source')); $ou_1_l1 = Horde_Ldap_Entry::createFresh('l=moveitem,ou=source,' . $testdn, array('objectClass' => array('top', 'locality'), 'l' => 'moveitem', 'description' => 'movetest')); $ou_2 = Horde_Ldap_Entry::createFresh('ou=target,' . $testdn, array('objectClass' => array('top', 'organizationalUnit'), 'ou' => 'target')); $ou_3 = Horde_Ldap_Entry::createFresh('ou=target_otherdir,' . $testdn, array('objectClass' => array('top', 'organizationalUnit'), 'ou' => 'target_otherdir')); $ldap->add($ou); $ldap->add($ou_1); $ldap->add($ou_1_l1); $ldap->add($ou_2); $ldap->add($ou_3); $this->assertTrue($ldap->exists($ou->dn())); $this->assertTrue($ldap->exists($ou_1->dn())); $this->assertTrue($ldap->exists($ou_1_l1->dn())); $this->assertTrue($ldap->exists($ou_2->dn())); $this->assertTrue($ldap->exists($ou_3->dn())); // Tree established. // Local rename. $olddn = $ou_1_l1->currentDN(); $ldap->move($ou_1_l1, str_replace('moveitem', 'move_item', $ou_1_l1->dn())); $this->assertTrue($ldap->exists($ou_1_l1->dn())); $this->assertFalse($ldap->exists($olddn)); // Local move. $olddn = $ou_1_l1->currentDN(); $ldap->move($ou_1_l1, 'l=move_item,' . $ou_2->dn()); $this->assertTrue($ldap->exists($ou_1_l1->dn())); $this->assertFalse($ldap->exists($olddn)); // Local move backward, with rename. Here we use the DN of the object, // to test DN conversion. // Note that this will outdate the object since it does not has // knowledge about the move. $olddn = $ou_1_l1->currentDN(); $newdn = 'l=moveditem,' . $ou_2->dn(); $ldap->move($olddn, $newdn); $this->assertTrue($ldap->exists($newdn)); $this->assertFalse($ldap->exists($olddn)); // Refetch since the object's DN was outdated. $ou_1_l1 = $ldap->getEntry($newdn); // Fake-cross directory move using two separate links to the same // directory. This other directory is represented by // ou=target_otherdir. $ldap2 = new Horde_Ldap(self::$ldapcfg['server']); $olddn = $ou_1_l1->currentDN(); $ldap->move($ou_1_l1, 'l=movedcrossdir,' . $ou_3->dn(), $ldap2); $this->assertFalse($ldap->exists($olddn)); $this->assertTrue($ldap2->exists($ou_1_l1->dn())); // Try to move over an existing entry. try { $ldap->move($ou_2, $ou_3->dn(), $ldap2); $this->fail('Horde_Ldap_Exception expected.'); } catch (Horde_Ldap_Exception $e) { } // Try cross directory move without providing an valid entry but a DN. try { $ldap->move($ou_1_l1->dn(), 'l=movedcrossdir2,' . $ou_2->dn(), $ldap2); $this->fail('Horde_Ldap_Exception expected.'); } catch (Horde_Ldap_Exception $e) { } // Try passing an invalid entry object. try { $ldap->move($ldap, 'l=move_item,' . $ou_2->dn()); $this->fail('Horde_Ldap_Exception expected.'); } catch (Horde_Ldap_Exception $e) { } // Try passing an invalid LDAP object. try { $ldap->move($ou_1_l1, 'l=move_item,' . $ou_2->dn(), $ou_1); $this->fail('Horde_Ldap_Exception expected.'); } catch (Horde_Ldap_Exception $e) { } }