mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 08:44:10 +02:00
Fix Authentication workflow
Fix ldap backends to use Credentials to work with. Fix some tests to use include right files. refs #4340
This commit is contained in:
parent
8192c19424
commit
a1327a384c
@ -6,6 +6,9 @@ namespace Icinga\Authentication;
|
|||||||
|
|
||||||
class Backend
|
class Backend
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var UserBackend
|
||||||
|
*/
|
||||||
protected $userBackend;
|
protected $userBackend;
|
||||||
|
|
||||||
public function __construct($config)
|
public function __construct($config)
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
namespace Icinga\Authentication\Backend;
|
namespace Icinga\Authentication\Backend;
|
||||||
|
|
||||||
use Icinga\Authentication\User as User;
|
use Icinga\Authentication\User as User;
|
||||||
|
use Icinga\Authentication\UserBackend;
|
||||||
|
use Icinga\Authentication\Credentials;
|
||||||
use Icinga\Protocol\Ldap;
|
use Icinga\Protocol\Ldap;
|
||||||
|
|
||||||
class LdapUserBackend implements UserBackend
|
class LdapUserBackend implements UserBackend
|
||||||
@ -16,14 +18,11 @@ class LdapUserBackend implements UserBackend
|
|||||||
$this->connection = new Ldap\Connection($config);
|
$this->connection = new Ldap\Connection($config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasUsername($username)
|
public function hasUsername(Credentials $credential)
|
||||||
{
|
{
|
||||||
if (!$username) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return $this->connection->fetchOne(
|
return $this->connection->fetchOne(
|
||||||
$this->selectUsername($username)
|
$this->selectUsername($credential->getUsername())
|
||||||
) === $username;
|
) === $credential->getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function stripAsterisks($string)
|
protected function stripAsterisks($string)
|
||||||
@ -38,19 +37,15 @@ class LdapUserBackend implements UserBackend
|
|||||||
->where('sAMAccountName', $this->stripAsterisks($username));
|
->where('sAMAccountName', $this->stripAsterisks($username));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function authenticate($username, $password = null)
|
public function authenticate(Credentials $credentials)
|
||||||
{
|
{
|
||||||
if (empty($username) || empty($password)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->connection->testCredentials(
|
if (!$this->connection->testCredentials(
|
||||||
$this->connection->fetchDN($this->selectUsername($username)),
|
$this->connection->fetchDN($this->selectUsername($credentials->getUsername())),
|
||||||
$password
|
$credentials->getPassword()
|
||||||
) ) {
|
) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$user = new User($username);
|
$user = new User($credentials->getUsername());
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,28 @@
|
|||||||
<?php
|
<?php
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
// {{{ICINGA_LICENSE_HEADER}}// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}}
|
// {{{ICINGA_LICENSE_HEADER}}}}
|
||||||
|
|
||||||
namespace Icinga\Authentication;
|
namespace Icinga\Authentication;
|
||||||
|
|
||||||
interface UserBackend
|
interface UserBackend
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Creates a new object
|
||||||
|
* @param $config
|
||||||
|
*/
|
||||||
public function __construct($config);
|
public function __construct($config);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if the username exists
|
||||||
|
* @param Credentials $credentials
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public function hasUsername(Credentials $credentials);
|
public function hasUsername(Credentials $credentials);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authenticate
|
||||||
|
* @param Credentials $credentials
|
||||||
|
* @return User
|
||||||
|
*/
|
||||||
public function authenticate(Credentials $credentials);
|
public function authenticate(Credentials $credentials);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ namespace Tests\Icinga\Authentication;
|
|||||||
require_once("../../library/Icinga/Authentication/Session.php");
|
require_once("../../library/Icinga/Authentication/Session.php");
|
||||||
require_once("../../library/Icinga/Authentication/PhpSession.php");
|
require_once("../../library/Icinga/Authentication/PhpSession.php");
|
||||||
require_once("../../library/Icinga/Application/Logger.php");
|
require_once("../../library/Icinga/Application/Logger.php");
|
||||||
|
require_once("../../library/Icinga/Exception/ConfigurationError.php");
|
||||||
require_once("Zend/Log.php");
|
require_once("Zend/Log.php");
|
||||||
|
|
||||||
use Icinga\Authentication\PhpSession as PhpSession;
|
use Icinga\Authentication\PhpSession as PhpSession;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user