diff --git a/src/UnicaenAuth/Authentication/Adapter/Db.php b/src/UnicaenAuth/Authentication/Adapter/Db.php index f1e2bf5ec6bc112fc1faa64cfa4c7b57acab6499..a684aee55eaa44ce8e6c50fb11041e88f46fe085 100644 --- a/src/UnicaenAuth/Authentication/Adapter/Db.php +++ b/src/UnicaenAuth/Authentication/Adapter/Db.php @@ -6,6 +6,7 @@ use Interop\Container\ContainerInterface; use UnicaenApp\ServiceManager\ServiceLocatorAwareInterface; use UnicaenApp\ServiceManager\ServiceLocatorAwareTrait; use UnicaenAuth\Options\ModuleOptions; +use UnicaenAuth\Options\Traits\ModuleOptionsAwareTrait; use Zend\Authentication\Result as AuthenticationResult; use Zend\Crypt\Password\Bcrypt; use Zend\EventManager\EventInterface; @@ -24,6 +25,8 @@ use ZfcUser\Mapper\UserInterface as UserMapperInterface; */ class Db extends AbstractAdapter implements ServiceLocatorAwareInterface { + use ModuleOptionsAwareTrait; + const TYPE = 'db'; /** @@ -106,6 +109,10 @@ class Db extends AbstractAdapter implements ServiceLocatorAwareInterface return; } + if (! $this->isEnabled()) { + return; + } + $identity = $e->getRequest()->getPost()->get('identity'); $credential = $e->getRequest()->getPost()->get('credential'); $credential = $this->preProcessCredential($credential); @@ -169,6 +176,20 @@ class Db extends AbstractAdapter implements ServiceLocatorAwareInterface ->setMessages(array('Authentication successful.')); } + /** + * @return bool + */ + protected function isEnabled() + { + $config = $this->moduleOptions->getDb(); + + if (isset($config['enabled'])) { + return (bool) $config['enabled']; + } + + return false; + } + protected function updateUserPasswordHash(UserInterface $userObject, $password, Bcrypt $bcrypt) { $hash = explode('$', $userObject->getPassword()); diff --git a/src/UnicaenAuth/Authentication/Adapter/DbAdapterFactory.php b/src/UnicaenAuth/Authentication/Adapter/DbAdapterFactory.php index 63abde5271ac8535789094086c0c4022e740c656..214247e2ba4c871b999f21dc0d640268ac1da68a 100644 --- a/src/UnicaenAuth/Authentication/Adapter/DbAdapterFactory.php +++ b/src/UnicaenAuth/Authentication/Adapter/DbAdapterFactory.php @@ -23,6 +23,12 @@ class DbAdapterFactory $adapter = new Db(); $adapter->setStorage(new Session(Db::class)); + $options = array_merge( + $container->get('zfcuser_module_options')->toArray(), + $container->get('unicaen-auth_module_options')->toArray()); + $moduleOptions = new ModuleOptions($options); + $adapter->setModuleOptions($moduleOptions); + $substitut = $moduleOptions->getDb()['type'] ?? null; if ($substitut !== null) { $adapter->setType($substitut); diff --git a/src/UnicaenAuth/Authentication/Adapter/Ldap.php b/src/UnicaenAuth/Authentication/Adapter/Ldap.php index 934edb2cbab586d520ed288216e3b9a40bfc0425..a503625fc96a43067ca9581c3f926f59f048e143 100644 --- a/src/UnicaenAuth/Authentication/Adapter/Ldap.php +++ b/src/UnicaenAuth/Authentication/Adapter/Ldap.php @@ -114,6 +114,10 @@ class Ldap extends AbstractAdapter implements EventManagerAwareInterface return; } + if (! $this->isEnabled()) { + return; + } + $username = $e->getRequest()->getPost()->get('identity'); $credential = $e->getRequest()->getPost()->get('credential'); @@ -159,6 +163,20 @@ class Ldap extends AbstractAdapter implements EventManagerAwareInterface $this->userService->userAuthenticated($ldapPeople); } + /** + * @return bool + */ + protected function isEnabled() + { + $config = $this->moduleOptions->getLdap(); + + if (isset($config['enabled'])) { + return (bool) $config['enabled']; + } + + return false; + } + /** * Extrait le loginUsurpateur et le loginUsurpé si l'identifiant spécifé est de la forme * "loginUsurpateur=loginUsurpé".