Loading .gitlab-ci.yml +2 −7 Original line number Diff line number Diff line image: registre.unicaen.fr:5000/unicaen-dev-php7.3-apache stages: - publish cache: key: ${CI_COMMIT_REF_SLUG} paths: - vendor/ update-satis: stage: publish image: python:3.9 script: - apt-get update && apt-get -y upgrade && apt-get -y install curl - curl https://gest.unicaen.fr/packagist/update Module.php +40 −7 Original line number Diff line number Diff line Loading @@ -4,16 +4,35 @@ namespace UnicaenAuthentification; use Laminas\EventManager\EventInterface; use Laminas\ModuleManager\Feature\AutoloaderProviderInterface; use Laminas\ModuleManager\Feature\BootstrapListenerInterface; use Laminas\ModuleManager\Feature\ConfigProviderInterface; use Laminas\ModuleManager\Feature\ServiceProviderInterface; use Laminas\Mvc\MvcEvent; use UnicaenAuthentification\Event\Listener\LdapAuthenticationFailureLoggerListener; use UnicaenAuthentification\Options\ModuleOptions; /** * Point d'entrée du module d'authentification Unicaen. * * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr> */ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, ServiceProviderInterface class Module implements AutoloaderProviderInterface, ConfigProviderInterface, ServiceProviderInterface, BootstrapListenerInterface { /** * @var \UnicaenAuthentification\Options\ModuleOptions */ private $moduleOptions; /** * @var \Laminas\EventManager\EventManagerInterface */ private $eventManager; /** * @var \Laminas\ServiceManager\ServiceManager */ private $serviceManager; /** * @return array * @see ConfigProviderInterface Loading @@ -39,16 +58,30 @@ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, Se } /** * This method is called once the MVC bootstrapping is complete, * after the "loadModule.post" event, once $application->bootstrap() is called. * * @param EventInterface $e * * @see BootstrapListenerInterface * @inheritDoc */ public function onBootstrap(EventInterface $e) { if ($e instanceof MvcEvent) { /** @var \Laminas\Mvc\Application $application */ $application = $e->getApplication(); $this->serviceManager = $application->getServiceManager(); $this->eventManager = $application->getEventManager(); $this->moduleOptions = $this->serviceManager->get(ModuleOptions::class); $this->attachEventListeners(); } } protected function attachEventListeners() { // log éventuel des erreurs d'authentification LDAP $logLdapAuthenticationFailure = $this->moduleOptions->getLdap()['log_failures'] ?? false; if ($logLdapAuthenticationFailure) { /** @var LdapAuthenticationFailureLoggerListener $listener */ $listener = $this->serviceManager->get(LdapAuthenticationFailureLoggerListener::class); $listener->attach($this->eventManager); } } /** Loading config/module.config.php +7 −4 Original line number Diff line number Diff line <?php use Laminas\Authentication\AuthenticationService; use Laminas\ServiceManager\Proxy\LazyServiceFactory; use UnicaenAuthentification\Authentication\Adapter\AdapterChainServiceFactory; use UnicaenAuthentification\Authentication\Adapter\Cas; use UnicaenAuthentification\Authentication\Adapter\CasAdapterFactory; Loading @@ -24,6 +26,8 @@ use UnicaenAuthentification\Controller\AuthControllerFactory; use UnicaenAuthentification\Controller\UtilisateurControllerFactory; use UnicaenAuthentification\Event\EventManager; use UnicaenAuthentification\Event\EventManagerFactory; use UnicaenAuthentification\Event\Listener\LdapAuthenticationFailureLoggerListener; use UnicaenAuthentification\Event\Listener\LdapAuthenticationFailureLoggerListenerFactory; use UnicaenAuthentification\Form\CasLoginForm; use UnicaenAuthentification\Form\CasLoginFormFactory; use UnicaenAuthentification\Form\LoginForm; Loading Loading @@ -60,8 +64,6 @@ use UnicaenPrivilege\Guard\PrivilegeControllerFactory; use UnicaenPrivilege\Guard\PrivilegeRoute; use UnicaenPrivilege\Guard\PrivilegeRouteFactory; use UnicaenPrivilege\Provider\Rule\PrivilegeRuleProviderFactory; use Laminas\Authentication\AuthenticationService; use Laminas\ServiceManager\Proxy\LazyServiceFactory; $settings = [ /** Loading Loading @@ -152,6 +154,7 @@ $settings = [ 'enabled' => false, 'adapter' => Ldap::class, 'form' => LoginForm::class, 'log_failures' => false, /** @see \UnicaenAuthentification\Event\Listener\LdapAuthenticationFailureLoggerListener */ ], ], Loading Loading @@ -505,8 +508,7 @@ return [ 'options' => [ 'route' => '/utilisateur', 'defaults' => [ '__NAMESPACE__' => 'UnicaenAuthentification\Controller', 'controller' => 'Utilisateur', 'controller' => 'UnicaenAuthentification\Controller\Utilisateur', 'action' => 'index', ], ], Loading Loading @@ -612,6 +614,7 @@ return [ PrivilegeRoute::class => PrivilegeRouteFactory::class, 'UnicaenAuthentification\Provider\Rule\PrivilegeRuleProvider' => PrivilegeRuleProviderFactory::class, LdapAuthenticationFailureLoggerListener::class => LdapAuthenticationFailureLoggerListenerFactory::class, ], 'lazy_services' => [ // Mapping services to their class names is required since the ServiceManager is not a declarative DIC. Loading config/unicaen-authentification.local.php.dist +5 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,11 @@ return [ */ 'ldap' => [ 'enabled' => true, /** * Activation ou non des logs (via `error_log` par défaut) à propos des échecs d'authentification LDAP. */ 'log_failures' => false, /** @see \UnicaenAuthentification\Event\Listener\LdapAuthenticationFailureLoggerListener */ ], ], Loading src/UnicaenAuthentification/Authentication/Adapter/Ldap.php +12 −14 Original line number Diff line number Diff line Loading @@ -207,23 +207,21 @@ class Ldap extends AbstractAdapter implements EventManagerAwareInterface // LDAP auth $result = $this->getLdapAuthAdapter()->setUsername($username)->setPassword($credential)->authenticate(); $success = $result->isValid(); // Déclenchement d'un événement contenant le nécessaire pour réagir à l'échec d'authentification (log, etc.) if (!$success) { $errorEvent = new Event(self::LDAP_AUTHENTIFICATION_FAIL, $this, [ 'result' => $result, 'username' => $username, // Envoi des erreurs LDAP dans un événement if (!$result->isValid()) { $messages = "LDAP ERROR : "; $errorMessages = $result->getMessages(); if (count($errorMessages) > 0) { // Clé conservée pour compatibilité : 'messages' => implode(PHP_EOL, array_slice($result->getMessages(), 0, 2)), // On ne prend que les 2 premières lignes d'erreur (les suivantes contiennent souvent // les mots de passe de l'utilisateur, et les mot de passe dans les logs... bof bof). for ($i = 0; $i < 2 && count($errorMessages) >= $i; $i++) { $messages .= $errorMessages[$i] . " "; } // les mots de passe de l'utilisateur, et les mots de passe dans les logs... bof bof). ]); $this->eventManager->triggerEvent($errorEvent); } $errorEvent = new Event(self::LDAP_AUTHENTIFICATION_FAIL, null, ['messages' => $messages]); $this->getEventManager()->triggerEvent($errorEvent); } $success = $result->isValid(); // verif existence du login usurpé if ($this->usernameUsurpe) { Loading Loading
.gitlab-ci.yml +2 −7 Original line number Diff line number Diff line image: registre.unicaen.fr:5000/unicaen-dev-php7.3-apache stages: - publish cache: key: ${CI_COMMIT_REF_SLUG} paths: - vendor/ update-satis: stage: publish image: python:3.9 script: - apt-get update && apt-get -y upgrade && apt-get -y install curl - curl https://gest.unicaen.fr/packagist/update
Module.php +40 −7 Original line number Diff line number Diff line Loading @@ -4,16 +4,35 @@ namespace UnicaenAuthentification; use Laminas\EventManager\EventInterface; use Laminas\ModuleManager\Feature\AutoloaderProviderInterface; use Laminas\ModuleManager\Feature\BootstrapListenerInterface; use Laminas\ModuleManager\Feature\ConfigProviderInterface; use Laminas\ModuleManager\Feature\ServiceProviderInterface; use Laminas\Mvc\MvcEvent; use UnicaenAuthentification\Event\Listener\LdapAuthenticationFailureLoggerListener; use UnicaenAuthentification\Options\ModuleOptions; /** * Point d'entrée du module d'authentification Unicaen. * * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr> */ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, ServiceProviderInterface class Module implements AutoloaderProviderInterface, ConfigProviderInterface, ServiceProviderInterface, BootstrapListenerInterface { /** * @var \UnicaenAuthentification\Options\ModuleOptions */ private $moduleOptions; /** * @var \Laminas\EventManager\EventManagerInterface */ private $eventManager; /** * @var \Laminas\ServiceManager\ServiceManager */ private $serviceManager; /** * @return array * @see ConfigProviderInterface Loading @@ -39,16 +58,30 @@ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, Se } /** * This method is called once the MVC bootstrapping is complete, * after the "loadModule.post" event, once $application->bootstrap() is called. * * @param EventInterface $e * * @see BootstrapListenerInterface * @inheritDoc */ public function onBootstrap(EventInterface $e) { if ($e instanceof MvcEvent) { /** @var \Laminas\Mvc\Application $application */ $application = $e->getApplication(); $this->serviceManager = $application->getServiceManager(); $this->eventManager = $application->getEventManager(); $this->moduleOptions = $this->serviceManager->get(ModuleOptions::class); $this->attachEventListeners(); } } protected function attachEventListeners() { // log éventuel des erreurs d'authentification LDAP $logLdapAuthenticationFailure = $this->moduleOptions->getLdap()['log_failures'] ?? false; if ($logLdapAuthenticationFailure) { /** @var LdapAuthenticationFailureLoggerListener $listener */ $listener = $this->serviceManager->get(LdapAuthenticationFailureLoggerListener::class); $listener->attach($this->eventManager); } } /** Loading
config/module.config.php +7 −4 Original line number Diff line number Diff line <?php use Laminas\Authentication\AuthenticationService; use Laminas\ServiceManager\Proxy\LazyServiceFactory; use UnicaenAuthentification\Authentication\Adapter\AdapterChainServiceFactory; use UnicaenAuthentification\Authentication\Adapter\Cas; use UnicaenAuthentification\Authentication\Adapter\CasAdapterFactory; Loading @@ -24,6 +26,8 @@ use UnicaenAuthentification\Controller\AuthControllerFactory; use UnicaenAuthentification\Controller\UtilisateurControllerFactory; use UnicaenAuthentification\Event\EventManager; use UnicaenAuthentification\Event\EventManagerFactory; use UnicaenAuthentification\Event\Listener\LdapAuthenticationFailureLoggerListener; use UnicaenAuthentification\Event\Listener\LdapAuthenticationFailureLoggerListenerFactory; use UnicaenAuthentification\Form\CasLoginForm; use UnicaenAuthentification\Form\CasLoginFormFactory; use UnicaenAuthentification\Form\LoginForm; Loading Loading @@ -60,8 +64,6 @@ use UnicaenPrivilege\Guard\PrivilegeControllerFactory; use UnicaenPrivilege\Guard\PrivilegeRoute; use UnicaenPrivilege\Guard\PrivilegeRouteFactory; use UnicaenPrivilege\Provider\Rule\PrivilegeRuleProviderFactory; use Laminas\Authentication\AuthenticationService; use Laminas\ServiceManager\Proxy\LazyServiceFactory; $settings = [ /** Loading Loading @@ -152,6 +154,7 @@ $settings = [ 'enabled' => false, 'adapter' => Ldap::class, 'form' => LoginForm::class, 'log_failures' => false, /** @see \UnicaenAuthentification\Event\Listener\LdapAuthenticationFailureLoggerListener */ ], ], Loading Loading @@ -505,8 +508,7 @@ return [ 'options' => [ 'route' => '/utilisateur', 'defaults' => [ '__NAMESPACE__' => 'UnicaenAuthentification\Controller', 'controller' => 'Utilisateur', 'controller' => 'UnicaenAuthentification\Controller\Utilisateur', 'action' => 'index', ], ], Loading Loading @@ -612,6 +614,7 @@ return [ PrivilegeRoute::class => PrivilegeRouteFactory::class, 'UnicaenAuthentification\Provider\Rule\PrivilegeRuleProvider' => PrivilegeRuleProviderFactory::class, LdapAuthenticationFailureLoggerListener::class => LdapAuthenticationFailureLoggerListenerFactory::class, ], 'lazy_services' => [ // Mapping services to their class names is required since the ServiceManager is not a declarative DIC. Loading
config/unicaen-authentification.local.php.dist +5 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,11 @@ return [ */ 'ldap' => [ 'enabled' => true, /** * Activation ou non des logs (via `error_log` par défaut) à propos des échecs d'authentification LDAP. */ 'log_failures' => false, /** @see \UnicaenAuthentification\Event\Listener\LdapAuthenticationFailureLoggerListener */ ], ], Loading
src/UnicaenAuthentification/Authentication/Adapter/Ldap.php +12 −14 Original line number Diff line number Diff line Loading @@ -207,23 +207,21 @@ class Ldap extends AbstractAdapter implements EventManagerAwareInterface // LDAP auth $result = $this->getLdapAuthAdapter()->setUsername($username)->setPassword($credential)->authenticate(); $success = $result->isValid(); // Déclenchement d'un événement contenant le nécessaire pour réagir à l'échec d'authentification (log, etc.) if (!$success) { $errorEvent = new Event(self::LDAP_AUTHENTIFICATION_FAIL, $this, [ 'result' => $result, 'username' => $username, // Envoi des erreurs LDAP dans un événement if (!$result->isValid()) { $messages = "LDAP ERROR : "; $errorMessages = $result->getMessages(); if (count($errorMessages) > 0) { // Clé conservée pour compatibilité : 'messages' => implode(PHP_EOL, array_slice($result->getMessages(), 0, 2)), // On ne prend que les 2 premières lignes d'erreur (les suivantes contiennent souvent // les mots de passe de l'utilisateur, et les mot de passe dans les logs... bof bof). for ($i = 0; $i < 2 && count($errorMessages) >= $i; $i++) { $messages .= $errorMessages[$i] . " "; } // les mots de passe de l'utilisateur, et les mots de passe dans les logs... bof bof). ]); $this->eventManager->triggerEvent($errorEvent); } $errorEvent = new Event(self::LDAP_AUTHENTIFICATION_FAIL, null, ['messages' => $messages]); $this->getEventManager()->triggerEvent($errorEvent); } $success = $result->isValid(); // verif existence du login usurpé if ($this->usernameUsurpe) { Loading