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\Exception\ConfigurationError;
use Icinga\User; use Icinga\User;
/**
* Base class for concrete user backends
*/
abstract class UserBackend implements Countable abstract class UserBackend implements Countable
{ {
/** /**
* Name of the backend * The name of this backend
* *
* @var string * @var string
*/ */
protected $name; protected $name;
/** /**
* Setter for the backend's name * Set this backend's name
* *
* @param string $name * @param string $name
* *
* @return $this * @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() public function getName()
{ {
return $this->name; 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) public static function create($name, ConfigObject $backendConfig)
{ {
if ($backendConfig->name !== null) { if ($backendConfig->name !== null) {
$name = $backendConfig->name; $name = $backendConfig->name;
} }
if (isset($backendConfig->class)) { if (isset($backendConfig->class)) {
// Use a custom backend class, this is only useful for testing // Use a custom backend class, this is only useful for testing
if (!class_exists($backendConfig->class)) { if (!class_exists($backendConfig->class)) {
@ -58,32 +72,27 @@ abstract class UserBackend implements Countable
} }
return new $backendConfig->class($backendConfig); return new $backendConfig->class($backendConfig);
} }
if (($backendType = $backendConfig->backend) === null) {
if (! ($backendType = strtolower($backendConfig->backend))) {
throw new ConfigurationError( throw new ConfigurationError(
'Authentication configuration for backend "%s" is missing the backend directive', 'Authentication configuration for backend "%s" is missing the backend directive',
$name $name
); );
} }
$backendType = strtolower($backendType);
if ($backendType === 'external') { if ($backendType === 'external') {
$backend = new ExternalBackend($backendConfig); $backend = new ExternalBackend($backendConfig);
$backend->setName($name); $backend->setName($name);
return $backend; return $backend;
} }
if ($backendConfig->resource === null) { if ($backendConfig->resource === null) {
throw new ConfigurationError( throw new ConfigurationError(
'Authentication configuration for backend "%s" is missing the resource directive', 'Authentication configuration for backend "%s" is missing the resource directive',
$name $name
); );
} }
try { $resource = ResourceFactory::createResource(ResourceFactory::getResourceConfig($backendConfig->resource));
$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);
switch ($backendType) { switch ($backendType) {
case 'db': case 'db':
$backend = new DbUserBackend($resource); $backend = new DbUserBackend($resource);
@ -140,12 +149,13 @@ abstract class UserBackend implements Countable
$backendType $backendType
); );
} }
$backend->setName($name); $backend->setName($name);
return $backend; return $backend;
} }
/** /**
* Authenticate * Authenticate the given user
* *
* @param User $user * @param User $user
* @param string $password * @param string $password

View File

@ -4,7 +4,6 @@
namespace Icinga\Data; namespace Icinga\Data;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Exception\ProgrammingError;
use Icinga\Util\ConfigAwareFactory; use Icinga\Util\ConfigAwareFactory;
use Icinga\Exception\ConfigurationError; use Icinga\Exception\ConfigurationError;
use Icinga\Data\Db\DbConnection; 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. * Check if the existing resources are set. If not, throw an error.
* *
* @throws ProgrammingError * @throws ConfigurationError
*/ */
private static function assertResourcesExist() private static function assertResourcesExist()
{ {
if (!isset(self::$resources)) { if (self::$resources === null) {
throw new ProgrammingError( throw new ConfigurationError(
'The ResourceFactory must be initialised by setting a config, before it can be used' 'Resources not set up. Please contact your Icinga Web administrator'
); );
} }
} }