modify() public method

The $params argument is an array of actions and should be something like this: array('add' => array('attribute1' => array('val1', 'val2'), 'attribute2' => array('val1')), 'delete' => array('attribute1'), 'replace' => array('attribute1' => array('val1')), 'changes' => array('add' => ..., 'replace' => ..., 'delete' => array('attribute1', 'attribute2' => array('val1'))) The order of execution is as following: 1. adds from 'add' array 2. deletes from 'delete' array 3. replaces from 'replace' array 4. changes (add, replace, delete) in order of appearance The function calls the corresponding functions of an Horde_Ldap_Entry object. A detailed description of array structures can be found there. Unlike the modification methods provided by the Horde_Ldap_Entry object, this method will instantly carry out an update() after each operation, thus modifying "directly" on the server.
See also: Horde_Ldap_Entry::add()
See also: Horde_Ldap_Entry::delete()
See also: Horde_Ldap_Entry::replace()
public modify ( string | Horde_Ldap_Entry $entry, array $parms = [] )
$entry string | Horde_Ldap_Entry DN string or Horde_Ldap_Entry.
$parms array Array of changes
コード例 #1
0
ファイル: Ldap.php プロジェクト: raz0rsdge/horde
 /**
  * Reset a user's password. Used for example when the user does not
  * remember the existing password.
  *
  * @param string $userId  The user id for which to reset the password.
  *
  * @return string  The new password on success.
  * @throws Horde_Auth_Exception
  */
 public function resetPassword($userId)
 {
     if (!empty($this->_params['ad'])) {
         throw new Horde_Auth_Exception(__CLASS__ . ': Updating users is not supported for Active Directory.');
     }
     /* Search for the user's full DN. */
     try {
         $dn = $this->_ldap->findUserDN($userId);
     } catch (Horde_Exception_Ldap $e) {
         throw new Horde_Auth_Exception($e);
     }
     /* Get a new random password. */
     $password = Horde_Auth::genRandomPassword();
     /* Encrypt the new password */
     $entry = array('userpassword' => Horde_Auth::getCryptedPassword($password, '', $this->_params['encryption'], 'true'));
     /* Set the lastchange field */
     $shadow = $this->_lookupShadow($dn);
     if ($shadow['shadowlastchange']) {
         $entry['shadowlastchange'] = floor(time() / 86400);
     }
     /* Update user entry. */
     try {
         $this->_ldap->modify($dn, array('replace' => $entry));
     } catch (Horde_Ldap_Exception $e) {
         throw new Horde_Auth_Exception($e);
     }
     return $password;
 }
コード例 #2
0
ファイル: Ldap.php プロジェクト: raz0rsdge/horde
 /**
  * Stores user preferences in the backend.
  *
  * @param boolean $defaults  Whether to store the global defaults instead
  *                           of user options. Unused.
  *
  * @throws Sam_Exception
  */
 public function store($defaults = false)
 {
     $entry = array();
     foreach ($this->_options as $a => $v) {
         $sa = $this->_mapAttributeToOption($a);
         if (is_array($v)) {
             foreach ($v as $av) {
                 $entry[] = $sa . ' ' . $av;
             }
         } else {
             $entry[] = $sa . ' ' . $v;
         }
     }
     $userdn = sprintf('%s=%s,%s', $this->_params['uid'], $this->_user, $this->_params['basedn']);
     try {
         $this->_ldap->modify($userdn, array('replace' => array($this->_params['attribute'] => $entry)));
     } catch (Horde_Ldap_Exception $e) {
         throw new Sam_Exception($e);
     }
 }
コード例 #3
0
ファイル: LdapTest.php プロジェクト: raz0rsdge/horde
 /**
  * Test modify().
  */
 public function testModify()
 {
     $ldap = new Horde_Ldap(self::$ldapcfg['server']);
     // We need a test entry.
     $local_entry = Horde_Ldap_Entry::createFresh('ou=Horde_Ldap_Test_modify,' . self::$ldapcfg['server']['basedn'], array('objectClass' => array('top', 'organizationalUnit'), 'ou' => 'Horde_Ldap_Test_modify', 'street' => 'Beniroad', 'telephoneNumber' => array('1234', '5678'), 'postalcode' => '12345', 'postalAddress' => 'someAddress', 'st' => array('State 1', 'State 2')));
     $ldap->add($local_entry);
     $this->assertTrue($ldap->exists($local_entry->dn()));
     // Test invalid actions.
     try {
         $ldap->modify($local_entry, array('foo' => 'bar'));
         $this->fail('Expected exception when passing invalid actions to modify().');
     } catch (Horde_Ldap_Exception $e) {
     }
     // Prepare some changes.
     $changes = array('add' => array('businessCategory' => array('foocat', 'barcat'), 'description' => 'testval'), 'delete' => array('postalAddress'), 'replace' => array('telephoneNumber' => array('345', '567')), 'changes' => array('replace' => array('street' => 'Highway to Hell'), 'add' => array('l' => 'someLocality'), 'delete' => array('postalcode', 'st' => array('State 1'))));
     // Perform those changes.
     $ldap->modify($local_entry, $changes);
     // Verify correct attribute changes.
     $actual_entry = $ldap->getEntry($local_entry->dn(), array('objectClass', 'ou', 'postalAddress', 'street', 'telephoneNumber', 'postalcode', 'st', 'l', 'businessCategory', 'description'));
     $this->assertInstanceOf('Horde_Ldap_Entry', $actual_entry);
     $expected_attributes = array('objectClass' => array('top', 'organizationalUnit'), 'ou' => 'Horde_Ldap_Test_modify', 'street' => 'Highway to Hell', 'l' => 'someLocality', 'telephoneNumber' => array('345', '567'), 'businessCategory' => array('foocat', 'barcat'), 'description' => 'testval', 'st' => 'State 2');
     $local_attributes = $local_entry->getValues();
     $actual_attributes = $actual_entry->getValues();
     // To enable easy check, we need to sort the values of the remaining
     // multival attributes as well as the attribute names.
     ksort($expected_attributes);
     ksort($local_attributes);
     ksort($actual_attributes);
     sort($expected_attributes['businessCategory']);
     sort($local_attributes['businessCategory']);
     sort($actual_attributes['businessCategory']);
     // The attributes must match the expected values.  Both, the entry
     // inside the directory and our local copy must reflect the same
     // values.
     $this->assertEquals($expected_attributes, $actual_attributes, 'The directory entries attributes are not OK!');
     $this->assertEquals($expected_attributes, $local_attributes, 'The local entries attributes are not OK!');
 }