UserBackend: Add missing and fix existing method documentation

refs #8826
This commit is contained in:
Johannes Meyer 2015-04-21 13:59:35 +02:00
parent 319ca3625c
commit 97caeb27f7
2 changed files with 30 additions and 21 deletions

View File

@ -9,19 +9,22 @@ use Icinga\Data\ResourceFactory;
use Icinga\Exception\ConfigurationError;
use Icinga\User;
/**
* Base class for concrete user backends
*/
abstract class UserBackend implements Countable
{
/**
* Name of the backend
* The name of this backend
*
* @var string
*/
protected $name;
/**
* Setter for the backend's name
* Set this backend's name
*
* @param string $name
* @param string $name
*
* @return $this
*/
@ -32,20 +35,31 @@ abstract class UserBackend implements Countable
}
/**
* Getter for the backend's name
* Return this backend's name
*
* @return string
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Create and return a UserBackend with the given name and given configuration applied to it
*
* @param string $name
* @param ConfigObject $backendConfig
*
* @return UserBackend
*
* @throws ConfigurationError
*/
public static function create($name, ConfigObject $backendConfig)
{
if ($backendConfig->name !== null) {
$name = $backendConfig->name;
}
if (isset($backendConfig->class)) {
// Use a custom backend class, this is only useful for testing
if (!class_exists($backendConfig->class)) {
@ -58,32 +72,27 @@ abstract class UserBackend implements Countable
}
return new $backendConfig->class($backendConfig);
}
if (($backendType = $backendConfig->backend) === null) {
if (! ($backendType = strtolower($backendConfig->backend))) {
throw new ConfigurationError(
'Authentication configuration for backend "%s" is missing the backend directive',
$name
);
}
$backendType = strtolower($backendType);
if ($backendType === 'external') {
$backend = new ExternalBackend($backendConfig);
$backend->setName($name);
return $backend;
}
if ($backendConfig->resource === null) {
throw new ConfigurationError(
'Authentication configuration for backend "%s" is missing the resource directive',
$name
);
}
try {
$resourceConfig = ResourceFactory::getResourceConfig($backendConfig->resource);
} catch (ProgrammingError $e) {
throw new ConfigurationError(
'Resources not set up. Please contact your Icinga Web administrator'
);
}
$resource = ResourceFactory::createResource($resourceConfig);
$resource = ResourceFactory::createResource(ResourceFactory::getResourceConfig($backendConfig->resource));
switch ($backendType) {
case 'db':
$backend = new DbUserBackend($resource);
@ -140,12 +149,13 @@ abstract class UserBackend implements Countable
$backendType
);
}
$backend->setName($name);
return $backend;
}
/**
* Authenticate
* Authenticate the given user
*
* @param User $user
* @param string $password

View File

@ -4,7 +4,6 @@
namespace Icinga\Data;
use Icinga\Application\Config;
use Icinga\Exception\ProgrammingError;
use Icinga\Util\ConfigAwareFactory;
use Icinga\Exception\ConfigurationError;
use Icinga\Data\Db\DbConnection;
@ -70,13 +69,13 @@ class ResourceFactory implements ConfigAwareFactory
/**
* Check if the existing resources are set. If not, throw an error.
*
* @throws ProgrammingError
* @throws ConfigurationError
*/
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'
if (self::$resources === null) {
throw new ConfigurationError(
'Resources not set up. Please contact your Icinga Web administrator'
);
}
}