From 319ca3625c8f6b78fe0f82d67d66b85291c75914 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 21 Apr 2015 13:15:40 +0200 Subject: [PATCH] LdapUserBackend: Drop redundant method hasUser refs #8826 --- .../Authentication/User/LdapUserBackend.php | 28 +++---------------- library/Icinga/Protocol/Ldap/Connection.php | 2 +- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/library/Icinga/Authentication/User/LdapUserBackend.php b/library/Icinga/Authentication/User/LdapUserBackend.php index 86dd247fc..8bc8f0222 100644 --- a/library/Icinga/Authentication/User/LdapUserBackend.php +++ b/library/Icinga/Authentication/User/LdapUserBackend.php @@ -185,25 +185,6 @@ class LdapUserBackend extends UserBackend return $groups; } - /** - * Return whether the given user exists - * - * @param User $user - * - * @return bool - */ - public function hasUser(User $user) - { - $username = $user->getUsername(); - $entry = $this->selectUser($username)->fetchOne(); - - if (is_array($entry)) { - return in_array(strtolower($username), array_map('strtolower', $entry)); - } - - return strtolower($entry) === strtolower($username); - } - /** * Return whether the given user credentials are valid * @@ -229,17 +210,16 @@ class LdapUserBackend extends UserBackend } } - if (! $this->hasUser($user)) { - return false; - } - try { $userDn = $this->conn->fetchDN($this->selectUser($user->getUsername())); + if ($userDn === null) { + return false; + } + $authenticated = $this->conn->testCredentials( $userDn, $password ); - if ($authenticated) { $groups = $this->getGroups($userDn); if ($groups !== null) { diff --git a/library/Icinga/Protocol/Ldap/Connection.php b/library/Icinga/Protocol/Ldap/Connection.php index 687f30e62..992a2f553 100644 --- a/library/Icinga/Protocol/Ldap/Connection.php +++ b/library/Icinga/Protocol/Ldap/Connection.php @@ -201,7 +201,7 @@ class Connection public function fetchDN(Query $query, $fields = array()) { $rows = $this->fetchAll($query, $fields); - if (count($rows) !== 1) { + if (count($rows) > 1) { throw new LdapException( 'Cannot fetch single DN for %s', $query->create()