mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
parent
159d765f14
commit
bca166c644
@ -94,16 +94,18 @@ class LdapUserBackend extends UserBackend
|
|||||||
* @param User $user
|
* @param User $user
|
||||||
* @param string $password
|
* @param string $password
|
||||||
*
|
*
|
||||||
* @return bool|null
|
* @return bool True when the authentication was successful, false when the username or password was invalid
|
||||||
* @throws AuthenticationException
|
* @throws AuthenticationException When an error occurred during authentication
|
||||||
*/
|
*/
|
||||||
public function authenticate(User $user, $password)
|
public function authenticate(User $user, $password)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->conn->testCredentials(
|
$userDn = $this->conn->fetchDN($this->createQuery($user->getUsername()));
|
||||||
$this->conn->fetchDN($this->createQuery($user->getUsername())),
|
if (!$userDn) {
|
||||||
$password
|
// User does not exist
|
||||||
);
|
return false;
|
||||||
|
}
|
||||||
|
return $this->conn->testCredentials($userDn, $password);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw new AuthenticationException(
|
throw new AuthenticationException(
|
||||||
sprintf(
|
sprintf(
|
||||||
|
@ -207,16 +207,19 @@ class Connection
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the distinguished name of the first result of the given query
|
||||||
|
*
|
||||||
|
* @param $query
|
||||||
|
* @param array $fields
|
||||||
|
*
|
||||||
|
* @return bool|String Returns the distinguished name, or false when the given query yields no results
|
||||||
|
*/
|
||||||
public function fetchDN($query, $fields = array())
|
public function fetchDN($query, $fields = array())
|
||||||
{
|
{
|
||||||
$rows = $this->fetchAll($query, $fields);
|
$rows = $this->fetchAll($query, $fields);
|
||||||
if (count($rows) !== 1) {
|
if (count($rows) !== 1) {
|
||||||
throw new \Exception(
|
return false;
|
||||||
sprintf(
|
|
||||||
'Cannot fetch single DN for %s',
|
|
||||||
$query
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return key($rows);
|
return key($rows);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user