parent
22bcc790ef
commit
13edbf901d
|
@ -7,6 +7,7 @@ use ErrorException;
|
||||||
use Exception;
|
use Exception;
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use Icinga\Application\Modules\Manager as ModuleManager;
|
use Icinga\Application\Modules\Manager as ModuleManager;
|
||||||
|
use Icinga\Authentication\User\UserBackend;
|
||||||
use Icinga\Data\ConfigObject;
|
use Icinga\Data\ConfigObject;
|
||||||
use Icinga\Data\ResourceFactory;
|
use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
|
@ -544,6 +545,24 @@ abstract class ApplicationBootstrap
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the user backend factory
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
protected function setupUserBackendFactory()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
UserBackend::setConfig(Config::app('authentication'));
|
||||||
|
} catch (NotReadableError $e) {
|
||||||
|
Logger::error(
|
||||||
|
new IcingaException('Cannot load user backend configuration. An exception was thrown:', $e)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect the timezone
|
* Detect the timezone
|
||||||
*
|
*
|
||||||
|
|
|
@ -43,6 +43,7 @@ class Cli extends ApplicationBootstrap
|
||||||
->setupLogger()
|
->setupLogger()
|
||||||
->setupResourceFactory()
|
->setupResourceFactory()
|
||||||
->setupModuleManager()
|
->setupModuleManager()
|
||||||
|
->setupUserBackendFactory()
|
||||||
->loadSetupModuleIfNecessary();
|
->loadSetupModuleIfNecessary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,7 @@ class Web extends ApplicationBootstrap
|
||||||
->setupZendMvc()
|
->setupZendMvc()
|
||||||
->setupFormNamespace()
|
->setupFormNamespace()
|
||||||
->setupModuleManager()
|
->setupModuleManager()
|
||||||
|
->setupUserBackendFactory()
|
||||||
->loadSetupModuleIfNecessary()
|
->loadSetupModuleIfNecessary()
|
||||||
->loadEnabledModules()
|
->loadEnabledModules()
|
||||||
->setupRoute()
|
->setupRoute()
|
||||||
|
|
|
@ -9,11 +9,12 @@ use Icinga\Application\Icinga;
|
||||||
use Icinga\Data\ConfigObject;
|
use Icinga\Data\ConfigObject;
|
||||||
use Icinga\Data\ResourceFactory;
|
use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
|
use Icinga\Util\ConfigAwareFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory for user backends
|
* Factory for user backends
|
||||||
*/
|
*/
|
||||||
class UserBackend
|
class UserBackend implements ConfigAwareFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The default user backend types provided by Icinga Web 2
|
* The default user backend types provided by Icinga Web 2
|
||||||
|
@ -34,6 +35,48 @@ class UserBackend
|
||||||
*/
|
*/
|
||||||
protected static $customBackends;
|
protected static $customBackends;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User backend configuration
|
||||||
|
*
|
||||||
|
* @var Config
|
||||||
|
*/
|
||||||
|
private static $backends;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set user backend configuration
|
||||||
|
*
|
||||||
|
* @param Config $config
|
||||||
|
*/
|
||||||
|
public static function setConfig($config)
|
||||||
|
{
|
||||||
|
self::$backends = $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the configuration of all existing user backends
|
||||||
|
*
|
||||||
|
* @return Config
|
||||||
|
*/
|
||||||
|
public static function getBackendConfigs()
|
||||||
|
{
|
||||||
|
self::assertBackendsExist();
|
||||||
|
return self::$backends;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if any user backends exist. If not, throw an error.
|
||||||
|
*
|
||||||
|
* @throws ConfigurationError
|
||||||
|
*/
|
||||||
|
private static function assertBackendsExist()
|
||||||
|
{
|
||||||
|
if (self::$backends === null) {
|
||||||
|
throw new ConfigurationError(
|
||||||
|
'User backends not set up. Please contact your Icinga Web administrator'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register all custom user backends from all loaded modules
|
* Register all custom user backends from all loaded modules
|
||||||
*/
|
*/
|
||||||
|
@ -110,9 +153,9 @@ class UserBackend
|
||||||
public static function create($name, ConfigObject $backendConfig = null)
|
public static function create($name, ConfigObject $backendConfig = null)
|
||||||
{
|
{
|
||||||
if ($backendConfig === null) {
|
if ($backendConfig === null) {
|
||||||
$authConfig = Config::app('authentication');
|
self::assertBackendsExist();
|
||||||
if ($authConfig->hasSection($name)) {
|
if (self::$backends->hasSection($name)) {
|
||||||
$backendConfig = $authConfig->getSection($name);
|
$backendConfig = self::$backends->getSection($name);
|
||||||
} else {
|
} else {
|
||||||
throw new ConfigurationError('User backend "%s" does not exist', $name);
|
throw new ConfigurationError('User backend "%s" does not exist', $name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue