mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-30 05:08:59 +02:00
Fix ldap backends to use Credentials to work with. Fix some tests to use include right files. refs #4340
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
namespace Icinga\Authentication\Backend;
|
|
|
|
use Icinga\Authentication\User as User;
|
|
use Icinga\Authentication\UserBackend;
|
|
use Icinga\Authentication\Credentials;
|
|
use Icinga\Protocol\Ldap;
|
|
|
|
class LdapUserBackend implements UserBackend
|
|
{
|
|
protected $connection;
|
|
|
|
public function __construct($config)
|
|
{
|
|
$this->connection = new Ldap\Connection($config);
|
|
}
|
|
|
|
public function hasUsername(Credentials $credential)
|
|
{
|
|
return $this->connection->fetchOne(
|
|
$this->selectUsername($credential->getUsername())
|
|
) === $credential->getUsername();
|
|
}
|
|
|
|
protected function stripAsterisks($string)
|
|
{
|
|
return str_replace('*', '', $string);
|
|
}
|
|
|
|
protected function selectUsername($username)
|
|
{
|
|
return $this->connection->select()
|
|
->from('user', array('sAMAccountName'))
|
|
->where('sAMAccountName', $this->stripAsterisks($username));
|
|
}
|
|
|
|
public function authenticate(Credentials $credentials)
|
|
{
|
|
if (!$this->connection->testCredentials(
|
|
$this->connection->fetchDN($this->selectUsername($credentials->getUsername())),
|
|
$credentials->getPassword()
|
|
) ) {
|
|
return false;
|
|
}
|
|
$user = new User($credentials->getUsername());
|
|
|
|
return $user;
|
|
}
|
|
}
|