Horde_Ldap::errorName PHP Метод

errorName() публичный статический Метод

Made to be able to make better errorhandling. Function based on DB::errorMessage(). Hint: The best description of the errorcodes is found here: http://www.directory-info.com/Ldap/LDAPErrorCodes.html
public static errorName ( integer $errorcode ) : string
$errorcode integer An error code.
Результат string The description for the error.
    public static function errorName($errorcode)
    {
        $errorMessages = array(0x0 => 'LDAP_SUCCESS', 0x1 => 'LDAP_OPERATIONS_ERROR', 0x2 => 'LDAP_PROTOCOL_ERROR', 0x3 => 'LDAP_TIMELIMIT_EXCEEDED', 0x4 => 'LDAP_SIZELIMIT_EXCEEDED', 0x5 => 'LDAP_COMPARE_FALSE', 0x6 => 'LDAP_COMPARE_TRUE', 0x7 => 'LDAP_AUTH_METHOD_NOT_SUPPORTED', 0x8 => 'LDAP_STRONG_AUTH_REQUIRED', 0x9 => 'LDAP_PARTIAL_RESULTS', 0xa => 'LDAP_REFERRAL', 0xb => 'LDAP_ADMINLIMIT_EXCEEDED', 0xc => 'LDAP_UNAVAILABLE_CRITICAL_EXTENSION', 0xd => 'LDAP_CONFIDENTIALITY_REQUIRED', 0xe => 'LDAP_SASL_BIND_INPROGRESS', 0x10 => 'LDAP_NO_SUCH_ATTRIBUTE', 0x11 => 'LDAP_UNDEFINED_TYPE', 0x12 => 'LDAP_INAPPROPRIATE_MATCHING', 0x13 => 'LDAP_CONSTRAINT_VIOLATION', 0x14 => 'LDAP_TYPE_OR_VALUE_EXISTS', 0x15 => 'LDAP_INVALID_SYNTAX', 0x20 => 'LDAP_NO_SUCH_OBJECT', 0x21 => 'LDAP_ALIAS_PROBLEM', 0x22 => 'LDAP_INVALID_DN_SYNTAX', 0x23 => 'LDAP_IS_LEAF', 0x24 => 'LDAP_ALIAS_DEREF_PROBLEM', 0x30 => 'LDAP_INAPPROPRIATE_AUTH', 0x31 => 'LDAP_INVALID_CREDENTIALS', 0x32 => 'LDAP_INSUFFICIENT_ACCESS', 0x33 => 'LDAP_BUSY', 0x34 => 'LDAP_UNAVAILABLE', 0x35 => 'LDAP_UNWILLING_TO_PERFORM', 0x36 => 'LDAP_LOOP_DETECT', 0x3c => 'LDAP_SORT_CONTROL_MISSING', 0x3d => 'LDAP_INDEX_RANGE_ERROR', 0x40 => 'LDAP_NAMING_VIOLATION', 0x41 => 'LDAP_OBJECT_CLASS_VIOLATION', 0x42 => 'LDAP_NOT_ALLOWED_ON_NONLEAF', 0x43 => 'LDAP_NOT_ALLOWED_ON_RDN', 0x44 => 'LDAP_ALREADY_EXISTS', 0x45 => 'LDAP_NO_OBJECT_CLASS_MODS', 0x46 => 'LDAP_RESULTS_TOO_LARGE', 0x47 => 'LDAP_AFFECTS_MULTIPLE_DSAS', 0x50 => 'LDAP_OTHER', 0x51 => 'LDAP_SERVER_DOWN', 0x52 => 'LDAP_LOCAL_ERROR', 0x53 => 'LDAP_ENCODING_ERROR', 0x54 => 'LDAP_DECODING_ERROR', 0x55 => 'LDAP_TIMEOUT', 0x56 => 'LDAP_AUTH_UNKNOWN', 0x57 => 'LDAP_FILTER_ERROR', 0x58 => 'LDAP_USER_CANCELLED', 0x59 => 'LDAP_PARAM_ERROR', 0x5a => 'LDAP_NO_MEMORY', 0x5b => 'LDAP_CONNECT_ERROR', 0x5c => 'LDAP_NOT_SUPPORTED', 0x5d => 'LDAP_CONTROL_NOT_FOUND', 0x5e => 'LDAP_NO_RESULTS_RETURNED', 0x5f => 'LDAP_MORE_RESULTS_TO_RETURN', 0x60 => 'LDAP_CLIENT_LOOP', 0x61 => 'LDAP_REFERRAL_LIMIT_EXCEEDED', 1000 => 'Unknown Error');
        return isset($errorMessages[$errorcode]) ? $errorMessages[$errorcode] : 'Unknown Error (' . $errorcode . ')';
    }

Usage Example

Пример #1
0
 /**
  * Find out if the given set of login credentials are valid.
  *
  * @param string $userId       The userId to check.
  * @param array  $credentials  An array of login credentials.
  *
  * @throws Horde_Auth_Exception
  */
 protected function _authenticate($userId, $credentials)
 {
     if (!strlen($credentials['password'])) {
         throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
     }
     /* Search for the user's full DN. */
     $this->_ldap->bind();
     try {
         $dn = $this->_ldap->findUserDN($userId);
     } catch (Horde_Exception_NotFound $e) {
         throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
     } catch (Horde_Exception_Ldap $e) {
         throw new Horde_Auth_Exception($e->getMessage(), Horde_Auth::REASON_MESSAGE);
     }
     /* Attempt to bind to the LDAP server as the user. */
     try {
         $this->_ldap->bind($dn, $credentials['password']);
         // Be sure we rebind as the configured user.
         $this->_ldap->bind();
     } catch (Horde_Ldap_Exception $e) {
         // Be sure we rebind as the configured user.
         $this->_ldap->bind();
         if (Horde_Ldap::errorName($e->getCode() == 'LDAP_INVALID_CREDENTIALS')) {
             throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
         }
         throw new Horde_Auth_Exception($e->getMessage(), Horde_Auth::REASON_MESSAGE);
     }
     if ($this->_params['password_expiration'] == 'yes') {
         $shadow = $this->_lookupShadow($dn);
         if ($shadow['shadowmax'] && $shadow['shadowlastchange'] && $shadow['shadowwarning']) {
             $today = floor(time() / 86400);
             $toexpire = $shadow['shadowlastchange'] + $shadow['shadowmax'] - $today;
             $warnday = $shadow['shadowlastchange'] + $shadow['shadowmax'] - $shadow['shadowwarning'];
             if ($today >= $warnday) {
                 $this->setCredential('expire', $toexpire);
             }
             if ($toexpire == 0) {
                 $this->setCredential('change', true);
             } elseif ($toexpire < 0) {
                 throw new Horde_Auth_Exception('', Horde_Auth::REASON_EXPIRED);
             }
         }
     }
 }
All Usage Examples Of Horde_Ldap::errorName