SimpleSAML_Auth_LDAP::validate PHP Method

validate() public method

TODO: Documentation; only cleared up exception/log messages
public validate ( $config, $username, $password = null )
    public function validate($config, $username, $password = null)
    {
        /* Escape any characters with a special meaning in LDAP. The following
         * characters have a special meaning (according to RFC 2253):
         * ',', '+', '"', '\', '<', '>', ';', '*'
         * These characters are escaped by prefixing them with '\'.
         */
        $username = addcslashes($username, ',+"\\<>;*');
        if (isset($config['priv_user_dn'])) {
            $this->bind($config['priv_user_dn'], $config['priv_user_pw']);
        }
        if (isset($config['dnpattern'])) {
            $dn = str_replace('%username%', $username, $config['dnpattern']);
        } else {
            $dn = $this->searchfordn($config['searchbase'], $config['searchattributes'], $username);
        }
        if ($password !== null) {
            // checking users credentials ... assuming below that she may read her own attributes ...
            // escape characters with a special meaning, also in the password
            $password = addcslashes($password, ',+"\\<>;*');
            if (!$this->bind($dn, $password)) {
                SimpleSAML\Logger::info('Library - LDAP validate(): Failed to authenticate \'' . $username . '\' using DN \'' . $dn . '\'');
                return false;
            }
        }
        /*
         * Retrieve attributes from LDAP
         */
        $attributes = $this->getAttributes($dn, $config['attributes']);
        return $attributes;
    }

Usage Example

示例#1
0
                }
                $casusername = $success->item(0)->textContent;
                return array($casusername, $attributes);
            }
        } else {
            throw new Exception("validate or serviceValidate not specified");
        }
        /**
         * First request, will redirect the user to the CAS server for authentication.
         */
    } else {
        SimpleSAML_Logger::info("AUTH - cas-ldap: redirecting to {$cas['login']}");
        SimpleSAML_Utilities::redirectTrustedURL($cas['login'], array('service' => $service));
    }
}
try {
    list($username, $casattributes) = casValidate($casconfig);
    SimpleSAML_Logger::info('AUTH - cas-ldap: ' . $username . ' authenticated by ' . $casconfig['validate']);
    $ldapattributes = array();
    if ($ldapconfig['servers']) {
        $ldap = new SimpleSAML_Auth_LDAP($ldapconfig['servers'], $ldapconfig['enable_tls']);
        $ldapattributes = $ldap->validate($ldapconfig, $username);
    }
    $attributes = array_merge_recursive($casattributes, $ldapattributes);
    $session->doLogin('login-cas-ldap');
    $session->setAttributes($attributes);
    $session->setNameID(array('value' => SimpleSAML_Utilities::generateID(), 'Format' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient'));
    SimpleSAML_Utilities::redirectUntrustedURL($_REQUEST['RelayState']);
} catch (Exception $exception) {
    throw new SimpleSAML_Error_Error('CASERROR', $exception);
}
All Usage Examples Of SimpleSAML_Auth_LDAP::validate