diff --git a/config/module.config.php b/config/module.config.php index b8b9bc05c5d5a3407d585a8cd29dfe0e39124045..6f13081b89278d94a6f1d11114ffcdfa44609a14 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 0000000000000000000000000000000000000000..9d71ebc2098309ba4ed78a2cd4d643afe551dbc7 --- /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