From 8aef1cb697526af53810bee3b0cdab302d6774fe Mon Sep 17 00:00:00 2001 From: Bertrand Gauthier <bertrand.gauthier@unicaen.fr> Date: Thu, 25 Apr 2013 13:39:21 +0000 Subject: [PATCH] =?UTF-8?q?L'adapter=20d'authentification=20Db=20a=20?= =?UTF-8?q?=C3=A9t=C3=A9=20supprim=C3=A9=20=C3=A0=20tort,=20il=20est=20n?= =?UTF-8?q?=C3=A9cessaire=20car=20il=20emp=C3=AAche=20l'auth=20de=20plante?= =?UTF-8?q?r=20si=20aucune=20table=20"user"=20n'existe.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/module.config.php | 2 +- src/UnicaenAuth/Authentication/Adapter/Db.php | 83 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/UnicaenAuth/Authentication/Adapter/Db.php diff --git a/config/module.config.php b/config/module.config.php index b8b9bc0..6f13081 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -53,7 +53,7 @@ $zfcuserSettings = array( */ 'auth_adapters' => array( 300 => 'UnicaenAuth\Authentication\Adapter\Ldap', // notifié en 1er - 200 => 'ZfcUser\Authentication\Adapter\Db', // ensuite (si échec d'authentification Ldap) + 200 => 'UnicaenAuth\Authentication\Adapter\Db', // ensuite (si échec d'authentification Ldap) 100 => 'UnicaenAuth\Authentication\Adapter\Cas', // ensuite (si échec d'authentification Db) ), ); diff --git a/src/UnicaenAuth/Authentication/Adapter/Db.php b/src/UnicaenAuth/Authentication/Adapter/Db.php new file mode 100644 index 0000000..9d71ebc --- /dev/null +++ b/src/UnicaenAuth/Authentication/Adapter/Db.php @@ -0,0 +1,83 @@ +<?php +namespace UnicaenAuth\Authentication\Adapter; + +use PDOException; +use UnicaenAuth\Options\ModuleOptions; +use Zend\ServiceManager\ServiceManager; +use Zend\ServiceManager\ServiceManagerAwareInterface; +use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent; +use ZfcUser\Options\AuthenticationOptionsInterface; + +/** + * Db authentication adpater with sesame password check. + * + * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr> + */ +class Db extends \ZfcUser\Authentication\Adapter\Db implements ServiceManagerAwareInterface +{ + /** + * @var ServiceManager + */ + protected $serviceManager; + + /** + * Authentification. + * + * @param AuthEvent $e + * @return boolean + */ + public function authenticate(AuthEvent $e) + { + try { + $result = parent::authenticate($e); + } + catch (PDOException $e) { + return false; + } + + return $result; + } + + /** + * @param ModuleOptions $options + * @return self + */ + public function setOptions(AuthenticationOptionsInterface $options) + { + $this->options = $options; + return $this; + } + + /** + * @return ModuleOptions + */ + public function getOptions() + { + if (!$this->options instanceof ModuleOptions) { + $this->setOptions($this->getServiceManager()->get('unicaen-auth_module_options')); + } + return $this->options; + } + + /** + * Get service manager + * + * @return ServiceManager + */ + public function getServiceManager() + { + return $this->serviceManager; + } + + /** + * Set service manager + * + * @param ServiceManager $serviceManager + * @return self + */ + public function setServiceManager(ServiceManager $serviceManager) + { + $this->serviceManager = $serviceManager; + return $this; + } +} \ No newline at end of file -- GitLab