icingaweb2/library/Icinga/Authentication/AuthChain.php
Eric Lippmann 39c80dccaf Decouple authentication backend creation from Icinga\Authentication\Manager
Add authentication backend type msldap with default values for user_class
and user_name_attribute. Backend type ldap now logs an error when user_class
and user_name_attribute ist not configured. Rename membership.ini to
memberships.ini since all our INI configuration files are in the plurar
where it makes sense. The AuthenticationController now handles
authentication

refs #5685
refs #5638
fixes #5218
2014-03-03 17:21:17 +01:00

66 lines
1.4 KiB
PHP

<?php
namespace Icinga\Authentication;
use Iterator;
use Zend_Config;
use Icinga\Application\Logger;
use Icinga\Exception\ConfigurationError;
class AuthChain implements Iterator
{
private $config;
private $currentBackend;
public function __construct(Zend_Config $config)
{
$this->config = $config;
}
public function rewind()
{
$this->config->rewind();
}
public function current()
{
return $this->currentBackend;
}
public function key()
{
return $this->config->key();
}
public function next()
{
$this->config->next();
}
public function valid()
{
if (!$this->config->valid()) {
return false;
}
$backendConfig = $this->config->current();
if ((bool) $backendConfig->get('disabled', false) === true) {
$this->next();
return $this->valid();
}
try {
$name = $this->key();
$backend = UserBackend::create($name, $backendConfig);
} catch (ConfigurationError $e) {
Logger::exception(
new ConfigurationError(
'Cannot create authentication backend "' . $name . '". An exception was thrown:', 0, $e
)
);
$this->next();
return $this->valid();
}
$this->currentBackend = $backend;
return true;
}
}