/** * Authenticate the given user * * @param User $user * @param string $password * * @return bool True on success, false on failure * * @throws AuthenticationException In case authentication is not possible due to an error */ public function authenticate(User $user, $password) { try { $userDn = $this->select()->where('user_name', str_replace('*', '', $user->getUsername()))->getQuery()->setUsePagedResults(false)->fetchDn(); if ($userDn === null) { return false; } $testCredentialsResult = $this->ds->testCredentials($userDn, $password); if ($testCredentialsResult) { $user->setAdditional('ldap_dn', $userDn); } return $testCredentialsResult; } catch (LdapException $e) { throw new AuthenticationException('Failed to authenticate user "%s" against backend "%s". An exception was thrown:', $user->getUsername(), $this->getName(), $e); } }