Loading Module.php +1 −1 Original line number Diff line number Diff line Loading @@ -90,7 +90,7 @@ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, Se */ private function reconfigureRoutesForAuth(ServiceLocatorInterface $sl) { /* @var $router \Zend\Mvc\Router\Http\TreeRouteStack */ /* @var $router \Zend\Router\Http\TreeRouteStack */ $router = $sl->get('router'); // si l'auth CAS est activée, modif de la route de connexion pour zapper le formulaire d'auth maison. Loading config/module.config.php +20 −7 Original line number Diff line number Diff line <?php use UnicaenAuth\Authentication\Storage\DbFactory; use UnicaenAuth\Authentication\Storage\LdapFactory; use UnicaenAuth\Authentication\Storage\ShibFactory; use UnicaenAuth\Controller\AuthControllerFactory; use UnicaenAuth\Controller\DroitsControllerFactory; use UnicaenAuth\Controller\UtilisateurControllerFactory; use UnicaenAuth\Form\Droits\RoleFormFactory; use UnicaenAuth\Guard\PrivilegeControllerFactory; use UnicaenAuth\Guard\PrivilegeRouteFactory; use UnicaenAuth\Service\ShibService; use UnicaenAuth\Service\ShibServiceFactory; use UnicaenAuth\Service\UserContextFactory; use UnicaenAuth\Service\UserFactory; use UnicaenAuth\Service\UserMapperFactory; use UnicaenAuth\View\Helper\LdapConnectViewHelperFactory; use UnicaenAuth\View\Helper\LocalConnectViewHelperFactory; Loading Loading @@ -420,11 +429,7 @@ return [ 'authUserContext' => 'UnicaenAuth\Service\UserContext', // pour la compatibilité ], 'invokables' => [ 'UnicaenAuth\Authentication\Storage\Db' => 'UnicaenAuth\Authentication\Storage\Db', 'UnicaenAuth\Authentication\Storage\Ldap' => 'UnicaenAuth\Authentication\Storage\Ldap', 'UnicaenAuth\Authentication\Storage\Shib' => 'UnicaenAuth\Authentication\Storage\Shib', 'UnicaenAuth\View\RedirectionStrategy' => 'UnicaenAuth\View\RedirectionStrategy', 'UnicaenAuth\Service\User' => 'UnicaenAuth\Service\User', 'UnicaenAuth\Service\CategoriePrivilege' => 'UnicaenAuth\Service\CategoriePrivilegeService', ], 'abstract_factories' => [ Loading @@ -449,6 +454,12 @@ return [ 'UnicaenAuth\Service\UserContext' => UserContextFactory::class, 'zfcuser_user_mapper' => UserMapperFactory::class, 'MouchardCompleterAuth' => 'UnicaenAuth\Mouchard\MouchardCompleterAuthFactory', 'UnicaenAuth\Authentication\Storage\Db' => DbFactory::class, 'UnicaenAuth\Authentication\Storage\Ldap' => LdapFactory::class, 'UnicaenAuth\Authentication\Storage\Shib' => ShibFactory::class, 'UnicaenAuth\Service\User' => UserFactory::class, 'UnicaenAuth\Guard\PrivilegeController' => PrivilegeControllerFactory::class, 'UnicaenAuth\Guard\PrivilegeRoute' => PrivilegeRouteFactory::class, ], 'shared' => [ 'MouchardCompleterAuth' => false, Loading @@ -460,17 +471,19 @@ return [ 'controllers' => [ 'invokables' => [ 'UnicaenAuth\Controller\Utilisateur' => 'UnicaenAuth\Controller\UtilisateurController', 'UnicaenAuth\Controller\Droits' => 'UnicaenAuth\Controller\DroitsController', ], 'factories' => [ 'UnicaenAuth\Controller\Auth' => AuthControllerFactory::class, 'UnicaenAuth\Controller\Utilisateur' => UtilisateurControllerFactory::class, 'UnicaenAuth\Controller\Droits' => DroitsControllerFactory::class, ], ], 'form_elements' => [ 'invokables' => [ 'UnicaenAuth\Form\Droits\Role' => 'UnicaenAuth\Form\Droits\RoleForm', ], 'factories' => [ 'UnicaenAuth\Form\Droits\Role' => RoleFormFactory::class, ], ], Loading src/UnicaenAuth/Assertion/AbstractAssertion.php +36 −18 Original line number Diff line number Diff line Loading @@ -3,16 +3,15 @@ namespace UnicaenAuth\Assertion; use BjyAuthorize\Service\Authorize; use UnicaenApp\ServiceManager\ServiceLocatorAwareInterface; use UnicaenApp\ServiceManager\ServiceLocatorAwareTrait; use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait; use Zend\Mvc\Application; use Zend\Mvc\Controller\Plugin\FlashMessenger; use Zend\Mvc\MvcEvent; use Zend\Mvc\Plugin\FlashMessenger\FlashMessenger; use Zend\Permissions\Acl\Acl; use Zend\Permissions\Acl\Assertion\AssertionInterface; use Zend\Permissions\Acl\Resource\ResourceInterface; use Zend\Permissions\Acl\Role\RoleInterface; use UnicaenApp\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorAwareTrait; /** * Description of AbstractAssertion Loading Loading @@ -296,44 +295,63 @@ abstract class AbstractAssertion implements AssertionInterface, ServiceLocatorAw return true; } /** * @var MvcEvent */ private $mvcEvent; /** * @param MvcEvent $mvcEvent */ public function setMvcEvent(MvcEvent $mvcEvent) { $this->mvcEvent = $mvcEvent; } /** * @return MvcEvent */ protected function getMvcEvent() { $application = $this->getServiceLocator()->get('Application'); /* @var $application Application */ return $application->getMvcEvent(); return $this->mvcEvent; } /** * @var Authorize */ private $serviceAuthorize; /** * @param Authorize $serviceAuthorize */ public function setServiceAuthorize(Authorize $serviceAuthorize) { $this->serviceAuthorize = $serviceAuthorize; } /** * @return Authorize */ private function getServiceAuthorize() { $serviceAuthorize = $this->getServiceLocator()->get('BjyAuthorize\Service\Authorize'); /* @var $serviceAuthorize Authorize */ return $serviceAuthorize; return $this->serviceAuthorize; } /** * @param FlashMessenger $fm * @deprecated Merci d'abandonner cette méthode : SoC violation ! */ public function setFlashMessenger(FlashMessenger $fm) { $this->fm = $fm; } /** * @return FlashMessenger * @deprecated Merci d'abandonner cette méthode : SoC violation ! */ protected function flashMessenger() { if (!$this->fm){ $this->fm = $this->getServiceLocator()->get('controllerpluginmanager')->get('flashmessenger'); } return $this->fm; } } No newline at end of file src/UnicaenAuth/Authentication/Adapter/AbstractFactory.php +73 −19 Original line number Diff line number Diff line Loading @@ -2,11 +2,16 @@ namespace UnicaenAuth\Authentication\Adapter; use Interop\Container\ContainerInterface; use UnicaenApp\Exception\LogicException; use UnicaenAuth\Options\ModuleOptions; use UnicaenAuth\Service\User; use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerAwareInterface; use Zend\Router\Http\TreeRouteStack; use Zend\ServiceManager\AbstractFactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; use UnicaenApp\Mapper\Ldap\People as LdapPeopleMapper; /** * Description of AbstractFactory Loading @@ -15,28 +20,22 @@ use Zend\ServiceManager\ServiceLocatorInterface; */ class AbstractFactory implements AbstractFactoryInterface { /** * Determine if we can create a service with name * * @param ServiceLocatorInterface $serviceLocator * @param $name * @param $requestedName * @return bool */ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { return strpos($requestedName, __NAMESPACE__) === 0 && class_exists($requestedName); return $this->canCreate($serviceLocator, $requestedName); } /** * Create service with name * * @param ServiceLocatorInterface $serviceLocator * @param $name * @param $requestedName * @return \ZfcUser\Authentication\Adapter\AbstractAdapter */ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { return $this->__invoke($serviceLocator, $requestedName); } public function canCreate(ContainerInterface $container, $requestedName) { return strpos($requestedName, __NAMESPACE__) === 0 && class_exists($requestedName); } public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { switch ($requestedName) { case __NAMESPACE__ . '\Ldap': Loading @@ -59,14 +58,69 @@ class AbstractFactory implements AbstractFactoryInterface break; } $this->injectDependencies($adapter, $container); if ($adapter instanceof EventManagerAwareInterface) { /** @var EventManager $eventManager */ $eventManager = $serviceLocator->get('event_manager'); $eventManager = $container->get('EventManager'); $adapter->setEventManager($eventManager); $userService = $serviceLocator->get('unicaen-auth_user_service'); /* @var $userService \UnicaenAuth\Service\User */ $userService = $container->get('unicaen-auth_user_service'); /* @var $userService \UnicaenAuth\Service\User */ $eventManager->attach('userAuthenticated', [$userService, 'userAuthenticated'], 100); } return $adapter; } /** * @param Ldap|Db|Cas $adapter * @param ContainerInterface $container */ private function injectDependencies($adapter, ContainerInterface $container) { switch (true) { case $adapter instanceof Ldap: /** @var User $userService */ $userService = $container->get('unicaen-auth_user_service'); $adapter->setUserService($userService); /** @var LdapPeopleMapper $ldapPeopleMapper */ $ldapPeopleMapper = $container->get('ldap_people_mapper'); $adapter->setLdapPeopleMapper($ldapPeopleMapper); $options = array_merge( $container->get('zfcuser_module_options')->toArray(), $container->get('unicaen-auth_module_options')->toArray()); $adapter->setOptions(new ModuleOptions($options)); /** @var \UnicaenApp\Options\ModuleOptions $appModuleOptions */ $appModuleOptions = $container->get('unicaen-app_module_options'); $adapter->setAppModuleOptions($appModuleOptions); break; case $adapter instanceof Cas: /** @var User $userService */ $userService = $container->get('unicaen-auth_user_service'); $adapter->setUserService($userService); /** @var TreeRouteStack $router */ $router = $container->get('router'); $adapter->setRouter($router); $options = array_merge( $container->get('zfcuser_module_options')->toArray(), $container->get('unicaen-auth_module_options')->toArray()); $adapter->setOptions(new ModuleOptions($options)); /** @var LdapPeopleMapper $ldapPeopleMapper */ $ldapPeopleMapper = $container->get('ldap_people_mapper'); $adapter->setLdapPeopleMapper($ldapPeopleMapper); break; default: break; } } } No newline at end of file src/UnicaenAuth/Authentication/Adapter/Cas.php +39 −22 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ namespace UnicaenAuth\Authentication\Adapter; use phpCAS; use UnicaenApp\Mapper\Ldap\People as LdapPeopleMapper; use UnicaenApp\ServiceManager\ServiceLocatorAwareInterface; use UnicaenAuth\Options\ModuleOptions; use UnicaenAuth\Service\User; use Zend\Authentication\Exception\UnexpectedValueException; Loading @@ -12,8 +11,7 @@ use Zend\Authentication\Result as AuthenticationResult; use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\EventManagerInterface; use Zend\Mvc\Router\Http\TreeRouteStack; use Zend\ServiceManager\ServiceLocatorAwareTrait; use Zend\Router\Http\TreeRouteStack; use ZfcUser\Authentication\Adapter\AbstractAdapter; use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent; use ZfcUser\Authentication\Adapter\ChainableAdapter; Loading @@ -23,10 +21,8 @@ use ZfcUser\Authentication\Adapter\ChainableAdapter; * * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr> */ class Cas extends AbstractAdapter implements EventManagerAwareInterface, ServiceLocatorAwareInterface class Cas extends AbstractAdapter implements EventManagerAwareInterface { use ServiceLocatorAwareTrait; /** * @var EventManager */ Loading @@ -52,15 +48,40 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface, Service */ protected $ldapPeopleMapper; /** * @var User */ private $userService; /** * @param User $userService */ public function setUserService(User $userService) { $this->userService = $userService; } /** * @var TreeRouteStack */ private $router; /** * @param TreeRouteStack $router */ public function setRouter(TreeRouteStack $router) { $this->router = $router; } /** * Réalise l'authentification. * * @param AuthEvent $e * @return boolean * @param \Zend\EventManager\Event|AuthEvent $e * @throws UnexpectedValueException * @see ChainableAdapter */ public function authenticate(AuthEvent $e) public function authenticate(\Zend\EventManager\Event $e) { // if ($e->getIdentity()) { // return; Loading Loading @@ -102,8 +123,7 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface, Service $ldapPeople = $this->getLdapPeopleMapper()->findOneByUsername($identity); /* @var $userService User */ $userService = $this->serviceLocator->get('unicaen-auth_user_service'); $userService->userAuthenticated($ldapPeople); $this->userService->userAuthenticated($ldapPeople); } /** Loading @@ -117,8 +137,7 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface, Service return; // NB: l'authentification CAS est désactivée ssi le tableau des options est vide } $router = $this->serviceLocator->get('router'); /* @var $router TreeRouteStack */ $returnUrl = $router->getRequestUri()->setPath($router->getBaseUrl())->toString(); $returnUrl = $this->router->getRequestUri()->setPath($this->router->getBaseUrl())->toString(); $this->getCasClient()->logoutWithRedirectService($returnUrl); } Loading Loading @@ -186,12 +205,12 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface, Service */ public function getOptions() { if (!$this->options instanceof ModuleOptions) { $options = array_merge( $this->serviceLocator->get('zfcuser_module_options')->toArray(), $this->serviceLocator->get('unicaen-auth_module_options')->toArray()); $this->setOptions(new ModuleOptions($options)); } // if (!$this->options instanceof ModuleOptions) { // $options = array_merge( // $this->serviceLocator->get('zfcuser_module_options')->toArray(), // $this->serviceLocator->get('unicaen-auth_module_options')->toArray()); // $this->setOptions(new ModuleOptions($options)); // } return $this->options; } Loading @@ -202,9 +221,6 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface, Service */ public function getLdapPeopleMapper() { if (null === $this->ldapPeopleMapper) { $this->ldapPeopleMapper = $this->serviceLocator->get('ldap_people_mapper'); } return $this->ldapPeopleMapper; } Loading @@ -217,6 +233,7 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface, Service public function setLdapPeopleMapper(LdapPeopleMapper $mapper) { $this->ldapPeopleMapper = $mapper; return $this; } Loading Loading
Module.php +1 −1 Original line number Diff line number Diff line Loading @@ -90,7 +90,7 @@ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, Se */ private function reconfigureRoutesForAuth(ServiceLocatorInterface $sl) { /* @var $router \Zend\Mvc\Router\Http\TreeRouteStack */ /* @var $router \Zend\Router\Http\TreeRouteStack */ $router = $sl->get('router'); // si l'auth CAS est activée, modif de la route de connexion pour zapper le formulaire d'auth maison. Loading
config/module.config.php +20 −7 Original line number Diff line number Diff line <?php use UnicaenAuth\Authentication\Storage\DbFactory; use UnicaenAuth\Authentication\Storage\LdapFactory; use UnicaenAuth\Authentication\Storage\ShibFactory; use UnicaenAuth\Controller\AuthControllerFactory; use UnicaenAuth\Controller\DroitsControllerFactory; use UnicaenAuth\Controller\UtilisateurControllerFactory; use UnicaenAuth\Form\Droits\RoleFormFactory; use UnicaenAuth\Guard\PrivilegeControllerFactory; use UnicaenAuth\Guard\PrivilegeRouteFactory; use UnicaenAuth\Service\ShibService; use UnicaenAuth\Service\ShibServiceFactory; use UnicaenAuth\Service\UserContextFactory; use UnicaenAuth\Service\UserFactory; use UnicaenAuth\Service\UserMapperFactory; use UnicaenAuth\View\Helper\LdapConnectViewHelperFactory; use UnicaenAuth\View\Helper\LocalConnectViewHelperFactory; Loading Loading @@ -420,11 +429,7 @@ return [ 'authUserContext' => 'UnicaenAuth\Service\UserContext', // pour la compatibilité ], 'invokables' => [ 'UnicaenAuth\Authentication\Storage\Db' => 'UnicaenAuth\Authentication\Storage\Db', 'UnicaenAuth\Authentication\Storage\Ldap' => 'UnicaenAuth\Authentication\Storage\Ldap', 'UnicaenAuth\Authentication\Storage\Shib' => 'UnicaenAuth\Authentication\Storage\Shib', 'UnicaenAuth\View\RedirectionStrategy' => 'UnicaenAuth\View\RedirectionStrategy', 'UnicaenAuth\Service\User' => 'UnicaenAuth\Service\User', 'UnicaenAuth\Service\CategoriePrivilege' => 'UnicaenAuth\Service\CategoriePrivilegeService', ], 'abstract_factories' => [ Loading @@ -449,6 +454,12 @@ return [ 'UnicaenAuth\Service\UserContext' => UserContextFactory::class, 'zfcuser_user_mapper' => UserMapperFactory::class, 'MouchardCompleterAuth' => 'UnicaenAuth\Mouchard\MouchardCompleterAuthFactory', 'UnicaenAuth\Authentication\Storage\Db' => DbFactory::class, 'UnicaenAuth\Authentication\Storage\Ldap' => LdapFactory::class, 'UnicaenAuth\Authentication\Storage\Shib' => ShibFactory::class, 'UnicaenAuth\Service\User' => UserFactory::class, 'UnicaenAuth\Guard\PrivilegeController' => PrivilegeControllerFactory::class, 'UnicaenAuth\Guard\PrivilegeRoute' => PrivilegeRouteFactory::class, ], 'shared' => [ 'MouchardCompleterAuth' => false, Loading @@ -460,17 +471,19 @@ return [ 'controllers' => [ 'invokables' => [ 'UnicaenAuth\Controller\Utilisateur' => 'UnicaenAuth\Controller\UtilisateurController', 'UnicaenAuth\Controller\Droits' => 'UnicaenAuth\Controller\DroitsController', ], 'factories' => [ 'UnicaenAuth\Controller\Auth' => AuthControllerFactory::class, 'UnicaenAuth\Controller\Utilisateur' => UtilisateurControllerFactory::class, 'UnicaenAuth\Controller\Droits' => DroitsControllerFactory::class, ], ], 'form_elements' => [ 'invokables' => [ 'UnicaenAuth\Form\Droits\Role' => 'UnicaenAuth\Form\Droits\RoleForm', ], 'factories' => [ 'UnicaenAuth\Form\Droits\Role' => RoleFormFactory::class, ], ], Loading
src/UnicaenAuth/Assertion/AbstractAssertion.php +36 −18 Original line number Diff line number Diff line Loading @@ -3,16 +3,15 @@ namespace UnicaenAuth\Assertion; use BjyAuthorize\Service\Authorize; use UnicaenApp\ServiceManager\ServiceLocatorAwareInterface; use UnicaenApp\ServiceManager\ServiceLocatorAwareTrait; use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait; use Zend\Mvc\Application; use Zend\Mvc\Controller\Plugin\FlashMessenger; use Zend\Mvc\MvcEvent; use Zend\Mvc\Plugin\FlashMessenger\FlashMessenger; use Zend\Permissions\Acl\Acl; use Zend\Permissions\Acl\Assertion\AssertionInterface; use Zend\Permissions\Acl\Resource\ResourceInterface; use Zend\Permissions\Acl\Role\RoleInterface; use UnicaenApp\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorAwareTrait; /** * Description of AbstractAssertion Loading Loading @@ -296,44 +295,63 @@ abstract class AbstractAssertion implements AssertionInterface, ServiceLocatorAw return true; } /** * @var MvcEvent */ private $mvcEvent; /** * @param MvcEvent $mvcEvent */ public function setMvcEvent(MvcEvent $mvcEvent) { $this->mvcEvent = $mvcEvent; } /** * @return MvcEvent */ protected function getMvcEvent() { $application = $this->getServiceLocator()->get('Application'); /* @var $application Application */ return $application->getMvcEvent(); return $this->mvcEvent; } /** * @var Authorize */ private $serviceAuthorize; /** * @param Authorize $serviceAuthorize */ public function setServiceAuthorize(Authorize $serviceAuthorize) { $this->serviceAuthorize = $serviceAuthorize; } /** * @return Authorize */ private function getServiceAuthorize() { $serviceAuthorize = $this->getServiceLocator()->get('BjyAuthorize\Service\Authorize'); /* @var $serviceAuthorize Authorize */ return $serviceAuthorize; return $this->serviceAuthorize; } /** * @param FlashMessenger $fm * @deprecated Merci d'abandonner cette méthode : SoC violation ! */ public function setFlashMessenger(FlashMessenger $fm) { $this->fm = $fm; } /** * @return FlashMessenger * @deprecated Merci d'abandonner cette méthode : SoC violation ! */ protected function flashMessenger() { if (!$this->fm){ $this->fm = $this->getServiceLocator()->get('controllerpluginmanager')->get('flashmessenger'); } return $this->fm; } } No newline at end of file
src/UnicaenAuth/Authentication/Adapter/AbstractFactory.php +73 −19 Original line number Diff line number Diff line Loading @@ -2,11 +2,16 @@ namespace UnicaenAuth\Authentication\Adapter; use Interop\Container\ContainerInterface; use UnicaenApp\Exception\LogicException; use UnicaenAuth\Options\ModuleOptions; use UnicaenAuth\Service\User; use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerAwareInterface; use Zend\Router\Http\TreeRouteStack; use Zend\ServiceManager\AbstractFactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; use UnicaenApp\Mapper\Ldap\People as LdapPeopleMapper; /** * Description of AbstractFactory Loading @@ -15,28 +20,22 @@ use Zend\ServiceManager\ServiceLocatorInterface; */ class AbstractFactory implements AbstractFactoryInterface { /** * Determine if we can create a service with name * * @param ServiceLocatorInterface $serviceLocator * @param $name * @param $requestedName * @return bool */ public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { return strpos($requestedName, __NAMESPACE__) === 0 && class_exists($requestedName); return $this->canCreate($serviceLocator, $requestedName); } /** * Create service with name * * @param ServiceLocatorInterface $serviceLocator * @param $name * @param $requestedName * @return \ZfcUser\Authentication\Adapter\AbstractAdapter */ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { return $this->__invoke($serviceLocator, $requestedName); } public function canCreate(ContainerInterface $container, $requestedName) { return strpos($requestedName, __NAMESPACE__) === 0 && class_exists($requestedName); } public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { switch ($requestedName) { case __NAMESPACE__ . '\Ldap': Loading @@ -59,14 +58,69 @@ class AbstractFactory implements AbstractFactoryInterface break; } $this->injectDependencies($adapter, $container); if ($adapter instanceof EventManagerAwareInterface) { /** @var EventManager $eventManager */ $eventManager = $serviceLocator->get('event_manager'); $eventManager = $container->get('EventManager'); $adapter->setEventManager($eventManager); $userService = $serviceLocator->get('unicaen-auth_user_service'); /* @var $userService \UnicaenAuth\Service\User */ $userService = $container->get('unicaen-auth_user_service'); /* @var $userService \UnicaenAuth\Service\User */ $eventManager->attach('userAuthenticated', [$userService, 'userAuthenticated'], 100); } return $adapter; } /** * @param Ldap|Db|Cas $adapter * @param ContainerInterface $container */ private function injectDependencies($adapter, ContainerInterface $container) { switch (true) { case $adapter instanceof Ldap: /** @var User $userService */ $userService = $container->get('unicaen-auth_user_service'); $adapter->setUserService($userService); /** @var LdapPeopleMapper $ldapPeopleMapper */ $ldapPeopleMapper = $container->get('ldap_people_mapper'); $adapter->setLdapPeopleMapper($ldapPeopleMapper); $options = array_merge( $container->get('zfcuser_module_options')->toArray(), $container->get('unicaen-auth_module_options')->toArray()); $adapter->setOptions(new ModuleOptions($options)); /** @var \UnicaenApp\Options\ModuleOptions $appModuleOptions */ $appModuleOptions = $container->get('unicaen-app_module_options'); $adapter->setAppModuleOptions($appModuleOptions); break; case $adapter instanceof Cas: /** @var User $userService */ $userService = $container->get('unicaen-auth_user_service'); $adapter->setUserService($userService); /** @var TreeRouteStack $router */ $router = $container->get('router'); $adapter->setRouter($router); $options = array_merge( $container->get('zfcuser_module_options')->toArray(), $container->get('unicaen-auth_module_options')->toArray()); $adapter->setOptions(new ModuleOptions($options)); /** @var LdapPeopleMapper $ldapPeopleMapper */ $ldapPeopleMapper = $container->get('ldap_people_mapper'); $adapter->setLdapPeopleMapper($ldapPeopleMapper); break; default: break; } } } No newline at end of file
src/UnicaenAuth/Authentication/Adapter/Cas.php +39 −22 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ namespace UnicaenAuth\Authentication\Adapter; use phpCAS; use UnicaenApp\Mapper\Ldap\People as LdapPeopleMapper; use UnicaenApp\ServiceManager\ServiceLocatorAwareInterface; use UnicaenAuth\Options\ModuleOptions; use UnicaenAuth\Service\User; use Zend\Authentication\Exception\UnexpectedValueException; Loading @@ -12,8 +11,7 @@ use Zend\Authentication\Result as AuthenticationResult; use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\EventManagerInterface; use Zend\Mvc\Router\Http\TreeRouteStack; use Zend\ServiceManager\ServiceLocatorAwareTrait; use Zend\Router\Http\TreeRouteStack; use ZfcUser\Authentication\Adapter\AbstractAdapter; use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent; use ZfcUser\Authentication\Adapter\ChainableAdapter; Loading @@ -23,10 +21,8 @@ use ZfcUser\Authentication\Adapter\ChainableAdapter; * * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr> */ class Cas extends AbstractAdapter implements EventManagerAwareInterface, ServiceLocatorAwareInterface class Cas extends AbstractAdapter implements EventManagerAwareInterface { use ServiceLocatorAwareTrait; /** * @var EventManager */ Loading @@ -52,15 +48,40 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface, Service */ protected $ldapPeopleMapper; /** * @var User */ private $userService; /** * @param User $userService */ public function setUserService(User $userService) { $this->userService = $userService; } /** * @var TreeRouteStack */ private $router; /** * @param TreeRouteStack $router */ public function setRouter(TreeRouteStack $router) { $this->router = $router; } /** * Réalise l'authentification. * * @param AuthEvent $e * @return boolean * @param \Zend\EventManager\Event|AuthEvent $e * @throws UnexpectedValueException * @see ChainableAdapter */ public function authenticate(AuthEvent $e) public function authenticate(\Zend\EventManager\Event $e) { // if ($e->getIdentity()) { // return; Loading Loading @@ -102,8 +123,7 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface, Service $ldapPeople = $this->getLdapPeopleMapper()->findOneByUsername($identity); /* @var $userService User */ $userService = $this->serviceLocator->get('unicaen-auth_user_service'); $userService->userAuthenticated($ldapPeople); $this->userService->userAuthenticated($ldapPeople); } /** Loading @@ -117,8 +137,7 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface, Service return; // NB: l'authentification CAS est désactivée ssi le tableau des options est vide } $router = $this->serviceLocator->get('router'); /* @var $router TreeRouteStack */ $returnUrl = $router->getRequestUri()->setPath($router->getBaseUrl())->toString(); $returnUrl = $this->router->getRequestUri()->setPath($this->router->getBaseUrl())->toString(); $this->getCasClient()->logoutWithRedirectService($returnUrl); } Loading Loading @@ -186,12 +205,12 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface, Service */ public function getOptions() { if (!$this->options instanceof ModuleOptions) { $options = array_merge( $this->serviceLocator->get('zfcuser_module_options')->toArray(), $this->serviceLocator->get('unicaen-auth_module_options')->toArray()); $this->setOptions(new ModuleOptions($options)); } // if (!$this->options instanceof ModuleOptions) { // $options = array_merge( // $this->serviceLocator->get('zfcuser_module_options')->toArray(), // $this->serviceLocator->get('unicaen-auth_module_options')->toArray()); // $this->setOptions(new ModuleOptions($options)); // } return $this->options; } Loading @@ -202,9 +221,6 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface, Service */ public function getLdapPeopleMapper() { if (null === $this->ldapPeopleMapper) { $this->ldapPeopleMapper = $this->serviceLocator->get('ldap_people_mapper'); } return $this->ldapPeopleMapper; } Loading @@ -217,6 +233,7 @@ class Cas extends AbstractAdapter implements EventManagerAwareInterface, Service public function setLdapPeopleMapper(LdapPeopleMapper $mapper) { $this->ldapPeopleMapper = $mapper; return $this; } Loading