Merge branch 'bugfix/document-and-rename-ldap-connection-class-8954'

fixes #8954
fixes #8955
This commit is contained in:
Johannes Meyer 2015-06-24 09:26:18 +02:00
commit 31064a0dc5
14 changed files with 572 additions and 329 deletions

View File

@ -7,7 +7,7 @@ use Exception;
use Icinga\Web\Form;
use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory;
use Icinga\Protocol\Ldap\Connection;
use Icinga\Protocol\Ldap\LdapConnection;
/**
* Form class for adding/modifying ldap resources
@ -27,7 +27,7 @@ class LdapResourceForm extends Form
*/
public function createElements(array $formData)
{
$defaultPort = ! array_key_exists('encryption', $formData) || $formData['encryption'] !== Connection::LDAPS
$defaultPort = ! array_key_exists('encryption', $formData) || $formData['encryption'] !== LdapConnection::LDAPS
? 389
: 636;
@ -75,9 +75,9 @@ class LdapResourceForm extends Form
. ' none for unencrypted communication'
),
'multiOptions' => array(
'none' => $this->translate('None', 'resource.ldap.encryption'),
Connection::STARTTLS => 'STARTTLS',
Connection::LDAPS => 'LDAPS'
'none' => $this->translate('None', 'resource.ldap.encryption'),
LdapConnection::STARTTLS => 'STARTTLS',
LdapConnection::LDAPS => 'LDAPS'
)
)
);
@ -156,13 +156,8 @@ class LdapResourceForm extends Form
{
try {
$resource = ResourceFactory::createResource(new ConfigObject($form->getValues()));
if (false === $resource->testCredentials(
$form->getElement('bind_dn')->getValue(),
$form->getElement('bind_pw')->getValue()
)
) {
throw new Exception(); // TODO: Get the exact error message
}
$resource->connect();
$resource->bind();
} catch (Exception $e) {
$msg = $form->translate('Connectivity validation failed, connection to the given resource not possible.');
if (($error = $e->getMessage())) {

View File

@ -8,7 +8,7 @@ use Icinga\Authentication\User\UserBackend;
use Icinga\Authentication\UserGroup\LdapUserGroupBackend;
use Icinga\Data\ConfigObject;
use Icinga\Data\ResourceFactory;
use Icinga\Protocol\Ldap\Connection;
use Icinga\Protocol\Ldap\LdapConnection;
use Icinga\Web\Form;
use Icinga\Web\Notification;
@ -286,11 +286,11 @@ class LdapUserGroupBackendForm extends Form
/**
* Return the names of all configured LDAP user backends
*
* @param Connection $resource
* @param LdapConnection $resource
*
* @return array
*/
protected function getLdapUserBackendNames(Connection $resource)
protected function getLdapUserBackendNames(LdapConnection $resource)
{
$names = array();
foreach (Config::app('authentication') as $name => $config) {

View File

@ -9,7 +9,7 @@ use Icinga\Exception\AuthenticationException;
use Icinga\Exception\ProgrammingError;
use Icinga\Repository\LdapRepository;
use Icinga\Repository\RepositoryQuery;
use Icinga\Protocol\Ldap\Exception as LdapException;
use Icinga\Protocol\Ldap\LdapException;
use Icinga\Protocol\Ldap\Expression;
use Icinga\User;
@ -325,7 +325,7 @@ class LdapUserBackend extends LdapRepository implements UserBackendInterface
throw new AuthenticationException('Connection not possible.', $e);
}
if ($result === null) {
if ($result === false) {
throw new AuthenticationException(
'No objects with objectClass "%s" in DN "%s" found. (Filter: %s)',
$this->userClass,

View File

@ -8,7 +8,7 @@ use Icinga\Util\ConfigAwareFactory;
use Icinga\Exception\ConfigurationError;
use Icinga\Data\Db\DbConnection;
use Icinga\Protocol\Livestatus\Connection as LivestatusConnection;
use Icinga\Protocol\Ldap\Connection as LdapConnection;
use Icinga\Protocol\Ldap\LdapConnection;
use Icinga\Protocol\File\FileReader;
/**

View File

@ -9,7 +9,7 @@ use Icinga\Protocol\Dns;
class Discovery {
/**
* @var Connection
* @var LdapConnection
*/
private $connection;
@ -21,9 +21,9 @@ class Discovery {
private $discovered = false;
/**
* @param Connection $conn The ldap connection to use for the discovery
* @param LdapConnection $conn The ldap connection to use for the discovery
*/
public function __construct(Connection $conn)
public function __construct(LdapConnection $conn)
{
$this->connection = $conn;
}
@ -147,7 +147,7 @@ class Discovery {
*/
public static function discover($host, $port)
{
$conn = new Connection(new ConfigObject(array(
$conn = new LdapConnection(new ConfigObject(array(
'hostname' => $host,
'port' => $port
)));

View File

@ -6,9 +6,9 @@ namespace Icinga\Protocol\Ldap;
use Icinga\Exception\IcingaException;
/**
* Class Exception
* Class LdapException
* @package Icinga\Protocol\Ldap
*/
class Exception extends IcingaException
class LdapException extends IcingaException
{
}

View File

@ -10,7 +10,7 @@ use Icinga\Exception\NotImplementedError;
/**
* LDAP query class
*/
class Query extends SimpleQuery
class LdapQuery extends SimpleQuery
{
/**
* This query's filters
@ -156,7 +156,7 @@ class Query extends SimpleQuery
{
$result = $this->fetchAll();
$sorted = array();
$quotedDn = preg_quote($this->ds->getDN(), '/');
$quotedDn = preg_quote($this->ds->getDn(), '/');
foreach ($result as $key => & $item) {
$new_key = LdapUtils::implodeDN(
array_reverse(
@ -186,7 +186,7 @@ class Query extends SimpleQuery
*
* @return string|false The distinguished name or false in case it's not possible to fetch a result
*
* @throws Exception In case the query returns multiple results
* @throws LdapException In case the query returns multiple results
* (i.e. it's not possible to fetch a unique DN)
*/
public function fetchDn()
@ -199,12 +199,12 @@ class Query extends SimpleQuery
*
* @return string
*
* @throws Exception In case the objectClass filter does not exist
* @throws LdapException In case the objectClass filter does not exist
*/
protected function renderFilter()
{
if (! isset($this->filters['objectClass'])) {
throw new Exception('Object class is mandatory');
throw new LdapException('Object class is mandatory');
}
$parts = array();

View File

@ -14,7 +14,7 @@ namespace Icinga\Protocol\Ldap;
class Node extends Root
{
/**
* @var Connection
* @var LdapConnection
*/
protected $connection;

View File

@ -22,7 +22,7 @@ class Root
protected $rdn;
/**
* @var Connection
* @var LdapConnection
*/
protected $connection;
@ -37,9 +37,9 @@ class Root
protected $props = array();
/**
* @param Connection $connection
* @param LdapConnection $connection
*/
protected function __construct(Connection $connection)
protected function __construct(LdapConnection $connection)
{
$this->connection = $connection;
}
@ -53,10 +53,10 @@ class Root
}
/**
* @param Connection $connection
* @param LdapConnection $connection
* @return Root
*/
public static function forConnection(Connection $connection)
public static function forConnection(LdapConnection $connection)
{
$root = new Root($connection);
return $root;
@ -177,17 +177,17 @@ class Root
}
/**
* @param Connection $connection
* @param LdapConnection $connection
* @return $this
*/
public function setConnection(Connection $connection)
public function setConnection(LdapConnection $connection)
{
$this->connection = $connection;
return $this;
}
/**
* @return Connection
* @return LdapConnection
*/
public function getConnection()
{
@ -215,7 +215,7 @@ class Root
*/
public function getDN()
{
return $this->connection->getDN();
return $this->connection->getDn();
}
/**

View File

@ -3,7 +3,7 @@
namespace Icinga\Repository;
use Icinga\Protocol\Ldap\Connection;
use Icinga\Protocol\Ldap\LdapConnection;
/**
* Abstract base class for concrete LDAP repository implementations
@ -18,7 +18,7 @@ abstract class LdapRepository extends Repository
/**
* The datasource being used
*
* @var Connection
* @var LdapConnection
*/
protected $ds;
@ -40,9 +40,9 @@ abstract class LdapRepository extends Repository
/**
* Create a new LDAP repository object
*
* @param Connection $ds The data source to use
* @param LdapConnection $ds The data source to use
*/
public function __construct(Connection $ds)
public function __construct(LdapConnection $ds)
{
parent::__construct($ds);
}

View File

@ -26,7 +26,7 @@ class LdapResourceFormTest extends BaseTestCase
public function testValidLdapResourceIsValid()
{
$this->setUpResourceFactoryMock(
Mockery::mock()->shouldReceive('testCredentials')->once()->andReturn(true)->getMock()
Mockery::mock()->shouldReceive('connect')->once()->shouldReceive('bind')->once()->getMock()
);
// Passing array(null) is required to make Mockery call the constructor...
@ -49,7 +49,7 @@ class LdapResourceFormTest extends BaseTestCase
public function testInvalidLdapResourceIsNotValid()
{
$this->setUpResourceFactoryMock(
Mockery::mock()->shouldReceive('testCredentials')->once()->andThrow('\Exception')->getMock()
Mockery::mock()->shouldReceive('connect')->once()->shouldReceive('bind')->andThrow('\Exception')->getMock()
);
// Passing array(null) is required to make Mockery call the constructor...

View File

@ -739,7 +739,6 @@ inkey' => 'blarg'
);
$rendered = $writer->render();
var_dump($rendered);
$this->assertEquals(
count(explode("\n", $rendered)),
4,

View File

@ -5,7 +5,7 @@ namespace Tests\Icinga\Protocol\Ldap;
use Icinga\Data\ConfigObject;
use Icinga\Test\BaseTestCase;
use Icinga\Protocol\Ldap\Connection;
use Icinga\Protocol\Ldap\LdapConnection;
class QueryTest extends BaseTestCase
{
@ -20,7 +20,7 @@ class QueryTest extends BaseTestCase
)
);
$connection = new Connection($config);
$connection = new LdapConnection($config);
return $connection->select();
}