Horde_Auth_Ldap::updateUser PHP Method

updateUser() public method

Update a set of authentication credentials.
public updateUser ( string $oldID, string $newID, array $credentials, string $olddn = null, string $newdn = null )
$oldID string The old userId.
$newID string The new userId.
$credentials array The new credentials.
$olddn string The old user DN.
$newdn string The new user DN.
    public function updateUser($oldID, $newID, $credentials, $olddn = null, $newdn = null)
    {
        if (!empty($this->_params['ad'])) {
            throw new Horde_Auth_Exception(__CLASS__ . ': Updating users is not supported for Active Directory.');
        }
        if (is_null($olddn)) {
            /* Search for the user's full DN. */
            try {
                $dn = $this->_ldap->findUserDN($oldID);
            } catch (Horde_Exception_Ldap $e) {
                throw new Horde_Auth_Exception($e);
            }
            $olddn = $dn;
            $newdn = preg_replace('/uid=.*?,/', 'uid=' . $newID . ',', $dn, 1);
            $shadow = $this->_lookupShadow($dn);
            /* If shadowmin hasn't yet expired only change when we are
               administrator */
            if ($shadow['shadowlastchange'] && $shadow['shadowmin'] && $shadow['shadowlastchange'] + $shadow['shadowmin'] > time() / 86400) {
                throw new Horde_Auth_Exception('Minimum password age has not yet expired');
            }
            /* Set the lastchange field */
            if ($shadow['shadowlastchange']) {
                $entry['shadowlastchange'] = floor(time() / 86400);
            }
            /* Encrypt the new password */
            $entry['userpassword'] = Horde_Auth::getCryptedPassword($credentials['password'], '', $this->_params['encryption'], 'true');
        } else {
            $entry = $credentials;
            unset($entry['dn']);
        }
        try {
            if ($oldID != $newID) {
                $this->_ldap->move($olddn, $newdn);
                $this->_ldap->modify($newdn, array('replace' => $entry));
            } else {
                $this->_ldap->modify($olddn, array('replace' => $entry));
            }
        } catch (Horde_Ldap_Exception $e) {
            throw new Horde_Auth_Exception(sprintf(__CLASS__ . ': Unable to update user "%s"', $newID));
        }
    }

Usage Example

示例#1
0
文件: Ldap.php 项目: jubinpatel/horde
 /**
  * Update a set of authentication credentials.
  *
  * @param string $oldID       The old user ID.
  * @param string $newID       The new user ID.
  * @param array $credentials  The new credentials
  * @param string $olddn       NOT USED.
  * @param string $newdn       NOT USED.
  *
  * @throws Horde_Auth_Exception
  */
 public function updateUser($oldID, $newID, $credentials, $olddn = null, $newdn = null)
 {
     $auth = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create();
     list($oldID, $old_credentials) = $auth->runHook($oldID, $credentials, 'preauthenticate', 'admin');
     list($newID, $new_credentials) = $auth->runHook($newID, $credentials, 'preauthenticate', 'admin');
     $olddn = isset($old_credentials['dn']) ? $old_credentials['dn'] : null;
     $newdn = isset($new_credentials['dn']) ? $new_credentials['dn'] : null;
     parent::updateUser($oldID, $newID, $new_credentials, $olddn, $newdn);
 }