fix LDAP install for systems without ldap extension (#846)

This commit is contained in:
Kevin Papst
2019-06-11 01:25:49 +02:00
committed by GitHub
parent 0c0e9c2f71
commit 833968a87d
23 changed files with 82 additions and 326 deletions

View File

@@ -9,6 +9,7 @@
namespace App\Ldap;
use App\Configuration\LdapConfiguration;
use Psr\Log\LoggerInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Zend\Ldap\Exception\LdapException;
@@ -22,20 +23,22 @@ class LdapDriver
/**
* @var Ldap
*/
private $driver;
protected $driver;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @param Ldap $driver Initialized Zend::Ldap Object
* @param LoggerInterface $logger optional logger for write debug messages
*/
public function __construct(Ldap $driver, LoggerInterface $logger = null)
public function __construct(LdapConfiguration $config, LoggerInterface $logger = null)
{
$this->driver = $driver;
if (!class_exists('Zend\Ldap\Ldap')) {
throw new \Exception(
'Zend\Ldap\Ldap is missing, install it with "composer require zendframework/zend-ldap" ' .
'or deactivate LDAP, see https://www.kimai.org/documentation/ldap.html'
);
}
$this->driver = new Ldap($config->getConnectionParameters());
$this->logger = $logger;
}
@@ -64,7 +67,7 @@ class LdapDriver
// searchEntries don't return 'count' key as specified by php native function ldap_get_entries()
$entries['count'] = count($entries);
} catch (LdapException $exception) {
$this->zendExceptionHandler($exception);
$this->ldapExceptionHandler($exception);
throw new LdapDriverException('An error occurred with the search operation.');
}
@@ -85,16 +88,13 @@ class LdapDriver
return $bind instanceof Ldap;
} catch (LdapException $exception) {
$this->zendExceptionHandler($exception, $password);
$this->ldapExceptionHandler($exception, $password);
}
return false;
}
/**
* Treat a Zend Ldap Exception.
*/
protected function zendExceptionHandler(LdapException $exception, string $password = null): void
protected function ldapExceptionHandler(LdapException $exception, string $password = null): void
{
$sanitizedException = null !== $password ? new SanitizingException($exception, $password) : $exception;