mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-09-26 03:09:10 +02:00
Fix remaining references to DbUserBackend and refresh the documentation.
refs #4786
This commit is contained in:
parent
ea5daf964b
commit
59d4baff0b
@ -31,7 +31,7 @@ namespace Icinga\Form\Config\Authentication;
|
|||||||
|
|
||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
use \Icinga\Web\Form\Decorator\HelpText;
|
use \Icinga\Web\Form\Decorator\HelpText;
|
||||||
use \Icinga\Application\DbAdapterFactory;
|
use \Icinga\Data\ResourceFactory;
|
||||||
use \Icinga\Web\Form;
|
use \Icinga\Web\Form;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,7 +121,7 @@ abstract class BaseBackendForm extends Form
|
|||||||
public function getResources()
|
public function getResources()
|
||||||
{
|
{
|
||||||
if ($this->resources === null) {
|
if ($this->resources === null) {
|
||||||
return DbAdapterFactory::getResources();
|
return ResourceFactory::getResourceConfigs()->toArray();
|
||||||
} else {
|
} else {
|
||||||
return $this->resources;
|
return $this->resources;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
namespace Icinga\Form\Config\Authentication;
|
namespace Icinga\Form\Config\Authentication;
|
||||||
|
|
||||||
use \Icinga\Authentication\Backend\DbUserBackend;
|
use \Icinga\Authentication\Backend\DbUserBackend;
|
||||||
use \Icinga\Application\DbAdapterFactory;
|
|
||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,10 +29,11 @@
|
|||||||
|
|
||||||
namespace Icinga\Form\Config\Authentication;
|
namespace Icinga\Form\Config\Authentication;
|
||||||
|
|
||||||
use \Icinga\Authentication\Backend\LdapUserBackend;
|
|
||||||
use \Exception;
|
use \Exception;
|
||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
use \Icinga\Web\Form;
|
use \Icinga\Web\Form;
|
||||||
|
use \Icinga\Authentication\Backend\LdapUserBackend;
|
||||||
|
use \Icinga\Protocol\Ldap\Connection as LdapConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form for adding or modifying LDAP authentication backends
|
* Form for adding or modifying LDAP authentication backends
|
||||||
@ -182,8 +183,9 @@ class LdapBackendForm extends BaseBackendForm
|
|||||||
try {
|
try {
|
||||||
$cfg = $this->getConfig();
|
$cfg = $this->getConfig();
|
||||||
$backendName = 'backend_' . $this->filterName($this->getBackendName()) . '_name';
|
$backendName = 'backend_' . $this->filterName($this->getBackendName()) . '_name';
|
||||||
|
$backendConfig = new Zend_Config($cfg[$this->getValue($backendName)]);
|
||||||
$testConn = new LdapUserBackend(
|
$testConn = new LdapUserBackend(
|
||||||
new Zend_Config($cfg[$this->getValue($backendName)])
|
new LdapConnection($backendConfig), $backendConfig
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($testConn->getUserCount() === 0) {
|
if ($testConn->getUserCount() === 0) {
|
||||||
|
@ -35,7 +35,7 @@ use \Zend_Form_Element_Text;
|
|||||||
use \Zend_Form_Element_Select;
|
use \Zend_Form_Element_Select;
|
||||||
use \Zend_View_Helper_DateFormat;
|
use \Zend_View_Helper_DateFormat;
|
||||||
use \Icinga\Application\Config as IcingaConfig;
|
use \Icinga\Application\Config as IcingaConfig;
|
||||||
use \Icinga\Application\DbAdapterFactory;
|
use \Icinga\Data\ResourceFactory;
|
||||||
use \Icinga\Web\Form;
|
use \Icinga\Web\Form;
|
||||||
use \Icinga\Web\Form\Validator\WritablePathValidator;
|
use \Icinga\Web\Form\Validator\WritablePathValidator;
|
||||||
use \Icinga\Web\Form\Validator\TimeFormatValidator;
|
use \Icinga\Web\Form\Validator\TimeFormatValidator;
|
||||||
@ -132,7 +132,7 @@ class GeneralForm extends Form
|
|||||||
public function getResources()
|
public function getResources()
|
||||||
{
|
{
|
||||||
if ($this->resources === null) {
|
if ($this->resources === null) {
|
||||||
return DbAdapterFactory::getResources();
|
return ResourceFactory::getResourceConfigs()->toArray();
|
||||||
} else {
|
} else {
|
||||||
return $this->resources;
|
return $this->resources;
|
||||||
}
|
}
|
||||||
|
106
doc/resources.md
106
doc/resources.md
@ -9,13 +9,49 @@ place, avoiding the need to edit several different files, when the connection in
|
|||||||
Each section represents a resource, with the section name being the identifier used to
|
Each section represents a resource, with the section name being the identifier used to
|
||||||
reference this certain section. Depending on the resource type, each section contains different properties.
|
reference this certain section. Depending on the resource type, each section contains different properties.
|
||||||
The property *type* defines the resource type and thus how the properties are going to be interpreted.
|
The property *type* defines the resource type and thus how the properties are going to be interpreted.
|
||||||
Currently only the resource type *db* is available.
|
The available resource types are 'db', 'statusdat', 'livestatus' and 'ldap' and are
|
||||||
|
described in detail in the following sections:
|
||||||
|
|
||||||
### db
|
### db
|
||||||
|
|
||||||
This resource type describes a SQL database. The property *db* defines the used database vendor, which
|
This resource type describes a SQL database on an SQL server. Databases can contain users and groups
|
||||||
could be a value like *mysql* or *pgsql*. The other properties like *host*, *password*, *username* and
|
to handle authentication and permissions, or monitoring data using IDO.
|
||||||
*dbname* are the connection information for the resource.
|
|
||||||
|
- *db*: defines the used database vendor, which could be a value like *mysql* or *pgsql*.
|
||||||
|
- *host*: The hostname that is used to connect to the database.
|
||||||
|
- *port*: The port that is used to connect to the database.
|
||||||
|
- *username*: The user name that is used to authenticate.
|
||||||
|
- *password*: The password of the user given in *username*.
|
||||||
|
- *dbname*: The name of the database that contains the resources data.
|
||||||
|
|
||||||
|
### ldap
|
||||||
|
|
||||||
|
The resource is a tree in a ldap domain. This resource type is usually used to fetch users and groups
|
||||||
|
to handle authentication and permissions.
|
||||||
|
|
||||||
|
- *hostname*: The hostname that is used to connect to the ldap server.
|
||||||
|
- *port*: The port that is used to connect to the ldap server.
|
||||||
|
- *root_dn*: The root object of the tree. This is usually an organizational unit like
|
||||||
|
"ou=people, dc=icinga, dc=org".
|
||||||
|
- *bind_dn*: The user on the LDAP server that will be used to access it. Usually something
|
||||||
|
like "cn=admin, cn=config".
|
||||||
|
- *bind_pw*: The password of the user given in *bind_dn*.
|
||||||
|
|
||||||
|
|
||||||
|
### livestatus
|
||||||
|
|
||||||
|
A resource that points to a livestatus socket. This resource type contains monitoring data.
|
||||||
|
|
||||||
|
- *socket*: The livestatus socket. Can be either be a path to a domain socket (like
|
||||||
|
"/usr/local/icinga-mysql/var/rw/live") or to a TCP socket like
|
||||||
|
(tcp://<domain>:<port>)
|
||||||
|
|
||||||
|
### statusdat
|
||||||
|
|
||||||
|
A resource that points to statusdat files. This resource type contains monitoring data.
|
||||||
|
|
||||||
|
- *status_file*: The path to the *status.dat* file, like "/usr/local/icinga-mysql/var/status.dat"
|
||||||
|
- *object_file*: The path to *objects.cache*, like "/usr/local/icinga-mysql/var/objects.cache"
|
||||||
|
|
||||||
|
|
||||||
## Factory Implementations
|
## Factory Implementations
|
||||||
@ -26,53 +62,35 @@ factory class, that can be used to comfortably create instances of classes that
|
|||||||
to the data of the resources.
|
to the data of the resources.
|
||||||
|
|
||||||
|
|
||||||
### DbAdapterFactory
|
### ResourceFactory
|
||||||
|
|
||||||
The DbAdapterFactory can be used to retrieve instances of Zend_Db_Adapter_Abstract for accessing
|
The ResourceFactory can be used to retrieve objects to access resources. Lets assume
|
||||||
the data of the SQL database.
|
for the following examples, that we have an *resources.ini* that looks like this:
|
||||||
|
|
||||||
Lets assume for the following examples, that we have an *resources.ini* that looks like this:
|
[statusdat]
|
||||||
|
type = statusdat
|
||||||
|
status_file = /usr/local/icinga-mysql/var/status.dat
|
||||||
|
object_file = /usr/local/icinga-mysql/var/objects.cache
|
||||||
|
|
||||||
[resource1]
|
[ldap_authentication]
|
||||||
type = "db"
|
type = "ldap"
|
||||||
db = "mysql"
|
hostname = "localhost"
|
||||||
dbname = "resource1"
|
port = "389"
|
||||||
host = "host"
|
root_dn = "ou=people, dc=icinga, dc=org"
|
||||||
username = "username1"
|
bind_dn = "cn=admin, cn=config"
|
||||||
password = "password1"
|
bind_pw = "admin"
|
||||||
|
|
||||||
[resource2]
|
|
||||||
type = "db"
|
|
||||||
db = "pgsql"
|
|
||||||
dbname = "resource2"
|
|
||||||
host = "host"
|
|
||||||
username = "username2"
|
|
||||||
password = "password2"
|
|
||||||
|
|
||||||
[resource3]
|
|
||||||
type = "other"
|
|
||||||
foo = "foo"
|
|
||||||
bar = "bar"
|
|
||||||
|
|
||||||
|
|
||||||
In the most simple use-case you can create an adapter by calling the
|
Here is an example of how to retrieve the resource 'statusdat' from the factory.
|
||||||
*getDbAdapter* function. The created adapter will be an instance of
|
|
||||||
Zend_Db_Adapter_Pdo_Mysql
|
|
||||||
|
|
||||||
$adapter = DbAdapterFactory::getDbAdapter('resource1');
|
|
||||||
|
|
||||||
|
$resource = ResourceFactory::createResource(
|
||||||
|
ResourceFactory::getResourceConfig('statusdat')
|
||||||
|
);
|
||||||
|
|
||||||
If you specify a resource that does not exist or has the wrong type,
|
If you specify a resource that does not exist or has the wrong type,
|
||||||
the factory will throw an ConfigurationException. You can make sure
|
the factory will throw an ConfigurationException.
|
||||||
a resource exists and has the right type, by calling the function *resourceExists*:
|
|
||||||
|
|
||||||
if (DbAdapterFactory::resourceExists('resource3')) {
|
|
||||||
$adapter = DbAdapterFactory::getDbAdapter('resource3');
|
|
||||||
} else {
|
|
||||||
// This returned false, because resource3 has a different type than "db"
|
|
||||||
echo 'resource does not exist, adapter could not be created...'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
You can retrieve a list of all available resources by calling *getResources*. You will
|
You can also retrieve a list of all available resources by calling *getResourceConfigs*.
|
||||||
get an array of all resources that have the type 'db'.
|
|
||||||
|
$resourceConfigs = ResourceFactory::getResourceConfigs();
|
||||||
|
@ -50,19 +50,60 @@ class ResourceFactory implements ConfigAwareFactory
|
|||||||
self::$resources = $config;
|
self::$resources = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the configuration for a specific resource
|
||||||
|
*
|
||||||
|
* @param $resourceName String The resources name
|
||||||
|
*
|
||||||
|
* @return Zend_Config The configuration of the resource
|
||||||
|
* @throws \Icinga\Exception\ConfigurationError
|
||||||
|
*/
|
||||||
public static function getResourceConfig($resourceName)
|
public static function getResourceConfig($resourceName)
|
||||||
{
|
{
|
||||||
if (!isset(self::$resources)) {
|
self::assertResourcesExist();
|
||||||
throw new ProgrammingError(
|
|
||||||
"The ResourceFactory must be initialised by setting a config, before it can be used"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (($resourceConfig = self::$resources->get($resourceName)) === null) {
|
if (($resourceConfig = self::$resources->get($resourceName)) === null) {
|
||||||
throw new ConfigurationError('Resource "' . $resourceName . '" couldn\'t be retrieved');
|
throw new ConfigurationError('Resource "' . $resourceName . '" couldn\'t be retrieved');
|
||||||
}
|
}
|
||||||
return $resourceConfig;
|
return $resourceConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the configuration of all existing resources.
|
||||||
|
*
|
||||||
|
* @return Zend_Config The configuration containing all resources
|
||||||
|
*/
|
||||||
|
public static function getResourceConfigs()
|
||||||
|
{
|
||||||
|
self::assertResourcesExist();
|
||||||
|
return self::$resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the existing resources are set. If not, throw an error.
|
||||||
|
*
|
||||||
|
* @throws \Icinga\Exception\ProgrammingError
|
||||||
|
*/
|
||||||
|
private static function assertResourcesExist()
|
||||||
|
{
|
||||||
|
if (!isset(self::$resources)) {
|
||||||
|
throw new ProgrammingError(
|
||||||
|
"The ResourceFactory must be initialised by setting a config, before it can be used"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a single resource from the given configuration.
|
||||||
|
*
|
||||||
|
* NOTE: The factory does not test if the given configuration is valid and the resource is accessible, this
|
||||||
|
* depends entirely on the implementation of the returned resource.
|
||||||
|
*
|
||||||
|
* @param Zend_Config $config The configuration for the created resource.
|
||||||
|
*
|
||||||
|
* @return DbConnection|LdapConnection|LivestatusConnection|StatusdatReader An objects that can be used to access
|
||||||
|
* the given resource. The returned class depends on the configuration property 'type'.
|
||||||
|
* @throws \Icinga\Exception\ConfigurationError When an unsupported type is given
|
||||||
|
*/
|
||||||
public static function createResource(Zend_Config $config)
|
public static function createResource(Zend_Config $config)
|
||||||
{
|
{
|
||||||
switch (strtolower($config->type)) {
|
switch (strtolower($config->type)) {
|
||||||
@ -80,7 +121,6 @@ class ResourceFactory implements ConfigAwareFactory
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ConfigurationError('Unsupported resource type "' . $config->type . '"');
|
throw new ConfigurationError('Unsupported resource type "' . $config->type . '"');
|
||||||
|
|
||||||
}
|
}
|
||||||
return $resource;
|
return $resource;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,6 @@ namespace Icinga\Test {
|
|||||||
use Zend_Db_Adapter_Pdo_Mysql;
|
use Zend_Db_Adapter_Pdo_Mysql;
|
||||||
use Zend_Db_Adapter_Pdo_Pgsql;
|
use Zend_Db_Adapter_Pdo_Pgsql;
|
||||||
use Zend_Db_Adapter_Pdo_Oci;
|
use Zend_Db_Adapter_Pdo_Oci;
|
||||||
use Icinga\Application\DbAdapterFactory;
|
|
||||||
use Icinga\Data\ResourceFactory;
|
use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\User\Preferences;
|
use Icinga\User\Preferences;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
@ -113,7 +112,7 @@ namespace Icinga\Test {
|
|||||||
public static $moduleDir;
|
public static $moduleDir;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DbAdapterFactory configuration for different database types
|
* Resource configuration for different database types
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -210,7 +209,6 @@ namespace Icinga\Test {
|
|||||||
$this->requireDbLibraries();
|
$this->requireDbLibraries();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//$adapter = DbAdapterFactory::createDbAdapter($this->createDbConfigFor($name));
|
|
||||||
$adapter = ResourceFactory::createResource($this->createDbConfigFor($name))->getConnection();
|
$adapter = ResourceFactory::createResource($this->createDbConfigFor($name))->getConnection();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$adapter = $e->getMessage();
|
$adapter = $e->getMessage();
|
||||||
|
@ -32,7 +32,7 @@ namespace Icinga\User\Preferences;
|
|||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
use \Icinga\User;
|
use \Icinga\User;
|
||||||
use \Icinga\Exception\ProgrammingError;
|
use \Icinga\Exception\ProgrammingError;
|
||||||
use \Icinga\Application\DbAdapterFactory;
|
use \Icinga\Data\ResourceFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create preference stores from zend config
|
* Create preference stores from zend config
|
||||||
@ -75,7 +75,7 @@ final class StoreFactory
|
|||||||
$items = $config->toArray();
|
$items = $config->toArray();
|
||||||
|
|
||||||
if ($items['type'] == 'db') {
|
if ($items['type'] == 'db') {
|
||||||
$items['dbAdapter'] = DbAdapterFactory::getDbAdapter($items['resource']);
|
$items['dbAdapter'] = ResourceFactory::createResource($items['resource']);
|
||||||
}
|
}
|
||||||
unset($items['type']);
|
unset($items['type']);
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ namespace Icinga\Module\Monitoring\Form\Config\Backend;
|
|||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
use \Icinga\Web\Form;
|
use \Icinga\Web\Form;
|
||||||
use \Icinga\Application\Icinga;
|
use \Icinga\Application\Icinga;
|
||||||
use \Icinga\Application\DbAdapterFactory;
|
use Icinga\Data\ResourceFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form for modifying a monitoring backend
|
* Form for modifying a monitoring backend
|
||||||
@ -40,7 +40,7 @@ use \Icinga\Application\DbAdapterFactory;
|
|||||||
class EditBackendForm extends Form
|
class EditBackendForm extends Form
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Database resources to use instead of the one's from DBAdapterFactory (used for testing)
|
* Database resources to use instead of the one's from ResourceFactory (used for testing)
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -82,7 +82,7 @@ class EditBackendForm extends Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a custom array of resources to be used in this form instead of the ones from DbAdapterFactory
|
* Set a custom array of resources to be used in this form instead of the ones from ResourceFactory
|
||||||
* (used for testing)
|
* (used for testing)
|
||||||
*/
|
*/
|
||||||
public function setResources($resources)
|
public function setResources($resources)
|
||||||
@ -98,7 +98,7 @@ class EditBackendForm extends Form
|
|||||||
public function getResources()
|
public function getResources()
|
||||||
{
|
{
|
||||||
if ($this->resources === null) {
|
if ($this->resources === null) {
|
||||||
return DbAdapterFactory::getResources();
|
return ResourceFactory::getResourceConfigs()->toArray();
|
||||||
} else {
|
} else {
|
||||||
return $this->resources;
|
return $this->resources;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ use \Zend_Config;
|
|||||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||||
use \Icinga\Protocol\Statusdat\Reader;
|
use \Icinga\Protocol\Statusdat\Reader;
|
||||||
use \Icinga\Web\Controller\ActionController;
|
use \Icinga\Web\Controller\ActionController;
|
||||||
use \Icinga\Application\DbAdapterFactory;
|
|
||||||
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
||||||
use \Test\Monitoring\Testlib\DataSource\DataSourceTestSetup;
|
use \Test\Monitoring\Testlib\DataSource\DataSourceTestSetup;
|
||||||
use Icinga\Module\Monitoring\Backend;
|
use Icinga\Module\Monitoring\Backend;
|
||||||
|
@ -56,7 +56,6 @@ use \PDO;
|
|||||||
use \Zend_Db_Adapter_Pdo_Abstract;
|
use \Zend_Db_Adapter_Pdo_Abstract;
|
||||||
use \Zend_Config;
|
use \Zend_Config;
|
||||||
use \Icinga\Authentication\Backend\DbUserBackend;
|
use \Icinga\Authentication\Backend\DbUserBackend;
|
||||||
use \Icinga\Application\DbAdapterFactory;
|
|
||||||
use \Icinga\Authentication\Credential;
|
use \Icinga\Authentication\Credential;
|
||||||
use \Icinga\User;
|
use \Icinga\User;
|
||||||
use \Icinga\Application\Config;
|
use \Icinga\Application\Config;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user