Loading config/module.config.php +5 −0 Original line number Diff line number Diff line <?php use UnicaenAuth\Authentication\Adapter\ShibSimulatorAdapter; use UnicaenAuth\Authentication\Storage\ShibSimulatorStorage; use UnicaenAuth\Controller\AuthControllerFactory; use UnicaenAuth\Service\ShibService; use UnicaenAuth\Service\ShibServiceFactory; use UnicaenAuth\Service\UserContextFactory; use UnicaenAuth\View\Helper\ShibConnectViewHelperFactory; use UnicaenAuth\View\Helper\UserUsurpationHelperFactory; $settings = [ /** Loading Loading @@ -373,6 +376,7 @@ return [ '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\Authentication\Storage\ShibSimulatorStorage' => ShibSimulatorStorage::class, 'UnicaenAuth\View\RedirectionStrategy' => 'UnicaenAuth\View\RedirectionStrategy', 'UnicaenAuth\Service\User' => 'UnicaenAuth\Service\User', 'UnicaenAuth\Service\CategoriePrivilege' => 'UnicaenAuth\Service\CategoriePrivilegeService', Loading Loading @@ -432,6 +436,7 @@ return [ 'userInfo' => 'UnicaenAuth\View\Helper\UserInfoFactory', 'userProfileSelect' => 'UnicaenAuth\View\Helper\UserProfileSelectFactory', 'userProfileSelectRadioItem' => 'UnicaenAuth\View\Helper\UserProfileSelectRadioItemFactory', 'userUsurpation' => UserUsurpationHelperFactory::class, 'shibConnect' => ShibConnectViewHelperFactory::class, ], 'invokables' => [ Loading src/UnicaenAuth/Authentication/Adapter/Cas.php +39 −2 Original line number Diff line number Diff line <?php namespace UnicaenAuth\Authentication\Adapter; use phpCAS; use UnicaenApp\Exception; use UnicaenApp\Mapper\Ldap\People as LdapPeopleMapper; use UnicaenAuth\Options\ModuleOptions; use UnicaenAuth\Service\User; use Zend\Authentication\Exception\UnexpectedValueException; use Zend\Authentication\Result as AuthenticationResult; use Zend\EventManager\EventManager; Loading Loading @@ -48,6 +50,11 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event */ protected $casClient; /** * @var LdapPeopleMapper */ protected $ldapPeopleMapper; /** * Réalise l'authentification. * Loading Loading @@ -94,7 +101,12 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event $e->setCode(AuthenticationResult::SUCCESS) ->setMessages(['Authentication successful.']); $this->getEventManager()->trigger('userAuthenticated', $e); // recherche de l'individu dans l'annuaire LDAP (il existe forcément puisque l'auth CAS a réussi) $ldapPeople = $this->getLdapPeopleMapper()->findOneByUsername($identity); /* @var $userService User */ $userService = $this->getServiceManager()->get('unicaen-auth_user_service'); $userService->userAuthenticated($ldapPeople); } /** Loading Loading @@ -186,6 +198,31 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event return $this->options; } /** * get ldap people mapper * * @return LdapPeopleMapper */ public function getLdapPeopleMapper() { if (null === $this->ldapPeopleMapper) { $this->ldapPeopleMapper = $this->getServiceManager()->get('ldap_people_mapper'); } return $this->ldapPeopleMapper; } /** * set ldap people mapper * * @param LdapPeopleMapper $mapper * @return self */ public function setLdapPeopleMapper(LdapPeopleMapper $mapper) { $this->ldapPeopleMapper = $mapper; return $this; } /** * Get service manager * Loading src/UnicaenAuth/Authentication/Storage/ChainServiceFactory.php +9 −2 Original line number Diff line number Diff line Loading @@ -12,11 +12,15 @@ use Zend\ServiceManager\ServiceLocatorInterface; */ class ChainServiceFactory implements FactoryInterface { protected $storages = [ private $mandatoryStorages = [ 200 => 'UnicaenAuth\Authentication\Storage\Ldap', 100 => 'UnicaenAuth\Authentication\Storage\Db', 76 => 'UnicaenAuth\Authentication\Storage\ShibSimulatorStorage', 75 => 'UnicaenAuth\Authentication\Storage\Shib', ]; protected $storages = []; /** * Create service * Loading @@ -27,7 +31,10 @@ class ChainServiceFactory implements FactoryInterface { $chain = new Chain(); foreach ($this->storages as $priority => $name) { $storages = $this->mandatoryStorages + $this->storages; krsort($storages); foreach ($storages as $priority => $name) { $storage = $serviceLocator->get($name); $chain->getEventManager()->attach('read', [$storage, 'read'], $priority); $chain->getEventManager()->attach('write', [$storage, 'write'], $priority); Loading src/UnicaenAuth/Authentication/Storage/Shib.php +18 −9 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ namespace UnicaenAuth\Authentication\Storage; use UnicaenAuth\Entity\Shibboleth\ShibUser; use UnicaenAuth\Options\ModuleOptions; use UnicaenAuth\Service\ShibService; use Zend\Authentication\Storage\Session; use Zend\Authentication\Storage\StorageInterface; Loading @@ -25,11 +24,6 @@ class Shib implements ChainableStorage, ServiceLocatorAwareInterface */ protected $storage; /** * @var ModuleOptions */ protected $options; /** * @var ShibUser */ Loading @@ -51,15 +45,30 @@ class Shib implements ChainableStorage, ServiceLocatorAwareInterface */ public function read(ChainEvent $e) { /** @var ShibService $shib */ $shib = $this->getServiceLocator()->get(ShibService::class); $shibUser = $shib->getAuthenticatedUser(); $shibUser = $this->getAuthenticatedUser(); $e->addContents('shib', $shibUser); return $shibUser; } /** * @return null|ShibUser */ private function getAuthenticatedUser() { if (null !== $this->resolvedIdentity) { return $this->resolvedIdentity; } /** @var ShibService $shib */ $shib = $this->getServiceLocator()->get(ShibService::class); $this->resolvedIdentity = $shib->getAuthenticatedUser(); return $this->resolvedIdentity; } /** * Writes $contents to storage * Loading src/UnicaenAuth/Authentication/Storage/ShibSimulatorStorage.php 0 → 100644 +70 −0 Original line number Diff line number Diff line <?php namespace UnicaenAuth\Authentication\Storage; use UnicaenAuth\Service\ShibService; use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorAwareTrait; /** * Storage permettant de simuler un utilisateur authentifié via Shibboleth. * * @author Unicaen */ class ShibSimulatorStorage implements ChainableStorage, ServiceLocatorAwareInterface { use ServiceLocatorAwareTrait; /** * @var ShibService */ protected $shibService; /** * @var array */ protected $shibbolethOptions; /** * {@inheritdoc} */ public function read(ChainEvent $e) { if (! $this->getShibService()->isShibbolethEnabled()) { return; } if (! $this->getShibService()->isSimulationActive()) { return; } $this->getShibService()->handleSimulation(); } /** * {@inheritdoc} */ public function write(ChainEvent $e) { // nop } /** * {@inheritdoc} */ public function clear(ChainEvent $e) { // nop } /** * @return ShibService */ private function getShibService() { if ($this->shibService === null) { $this->shibService = $this->serviceLocator->get(ShibService::class); } return $this->shibService; } } No newline at end of file Loading
config/module.config.php +5 −0 Original line number Diff line number Diff line <?php use UnicaenAuth\Authentication\Adapter\ShibSimulatorAdapter; use UnicaenAuth\Authentication\Storage\ShibSimulatorStorage; use UnicaenAuth\Controller\AuthControllerFactory; use UnicaenAuth\Service\ShibService; use UnicaenAuth\Service\ShibServiceFactory; use UnicaenAuth\Service\UserContextFactory; use UnicaenAuth\View\Helper\ShibConnectViewHelperFactory; use UnicaenAuth\View\Helper\UserUsurpationHelperFactory; $settings = [ /** Loading Loading @@ -373,6 +376,7 @@ return [ '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\Authentication\Storage\ShibSimulatorStorage' => ShibSimulatorStorage::class, 'UnicaenAuth\View\RedirectionStrategy' => 'UnicaenAuth\View\RedirectionStrategy', 'UnicaenAuth\Service\User' => 'UnicaenAuth\Service\User', 'UnicaenAuth\Service\CategoriePrivilege' => 'UnicaenAuth\Service\CategoriePrivilegeService', Loading Loading @@ -432,6 +436,7 @@ return [ 'userInfo' => 'UnicaenAuth\View\Helper\UserInfoFactory', 'userProfileSelect' => 'UnicaenAuth\View\Helper\UserProfileSelectFactory', 'userProfileSelectRadioItem' => 'UnicaenAuth\View\Helper\UserProfileSelectRadioItemFactory', 'userUsurpation' => UserUsurpationHelperFactory::class, 'shibConnect' => ShibConnectViewHelperFactory::class, ], 'invokables' => [ Loading
src/UnicaenAuth/Authentication/Adapter/Cas.php +39 −2 Original line number Diff line number Diff line <?php namespace UnicaenAuth\Authentication\Adapter; use phpCAS; use UnicaenApp\Exception; use UnicaenApp\Mapper\Ldap\People as LdapPeopleMapper; use UnicaenAuth\Options\ModuleOptions; use UnicaenAuth\Service\User; use Zend\Authentication\Exception\UnexpectedValueException; use Zend\Authentication\Result as AuthenticationResult; use Zend\EventManager\EventManager; Loading Loading @@ -48,6 +50,11 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event */ protected $casClient; /** * @var LdapPeopleMapper */ protected $ldapPeopleMapper; /** * Réalise l'authentification. * Loading Loading @@ -94,7 +101,12 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event $e->setCode(AuthenticationResult::SUCCESS) ->setMessages(['Authentication successful.']); $this->getEventManager()->trigger('userAuthenticated', $e); // recherche de l'individu dans l'annuaire LDAP (il existe forcément puisque l'auth CAS a réussi) $ldapPeople = $this->getLdapPeopleMapper()->findOneByUsername($identity); /* @var $userService User */ $userService = $this->getServiceManager()->get('unicaen-auth_user_service'); $userService->userAuthenticated($ldapPeople); } /** Loading Loading @@ -186,6 +198,31 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event return $this->options; } /** * get ldap people mapper * * @return LdapPeopleMapper */ public function getLdapPeopleMapper() { if (null === $this->ldapPeopleMapper) { $this->ldapPeopleMapper = $this->getServiceManager()->get('ldap_people_mapper'); } return $this->ldapPeopleMapper; } /** * set ldap people mapper * * @param LdapPeopleMapper $mapper * @return self */ public function setLdapPeopleMapper(LdapPeopleMapper $mapper) { $this->ldapPeopleMapper = $mapper; return $this; } /** * Get service manager * Loading
src/UnicaenAuth/Authentication/Storage/ChainServiceFactory.php +9 −2 Original line number Diff line number Diff line Loading @@ -12,11 +12,15 @@ use Zend\ServiceManager\ServiceLocatorInterface; */ class ChainServiceFactory implements FactoryInterface { protected $storages = [ private $mandatoryStorages = [ 200 => 'UnicaenAuth\Authentication\Storage\Ldap', 100 => 'UnicaenAuth\Authentication\Storage\Db', 76 => 'UnicaenAuth\Authentication\Storage\ShibSimulatorStorage', 75 => 'UnicaenAuth\Authentication\Storage\Shib', ]; protected $storages = []; /** * Create service * Loading @@ -27,7 +31,10 @@ class ChainServiceFactory implements FactoryInterface { $chain = new Chain(); foreach ($this->storages as $priority => $name) { $storages = $this->mandatoryStorages + $this->storages; krsort($storages); foreach ($storages as $priority => $name) { $storage = $serviceLocator->get($name); $chain->getEventManager()->attach('read', [$storage, 'read'], $priority); $chain->getEventManager()->attach('write', [$storage, 'write'], $priority); Loading
src/UnicaenAuth/Authentication/Storage/Shib.php +18 −9 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ namespace UnicaenAuth\Authentication\Storage; use UnicaenAuth\Entity\Shibboleth\ShibUser; use UnicaenAuth\Options\ModuleOptions; use UnicaenAuth\Service\ShibService; use Zend\Authentication\Storage\Session; use Zend\Authentication\Storage\StorageInterface; Loading @@ -25,11 +24,6 @@ class Shib implements ChainableStorage, ServiceLocatorAwareInterface */ protected $storage; /** * @var ModuleOptions */ protected $options; /** * @var ShibUser */ Loading @@ -51,15 +45,30 @@ class Shib implements ChainableStorage, ServiceLocatorAwareInterface */ public function read(ChainEvent $e) { /** @var ShibService $shib */ $shib = $this->getServiceLocator()->get(ShibService::class); $shibUser = $shib->getAuthenticatedUser(); $shibUser = $this->getAuthenticatedUser(); $e->addContents('shib', $shibUser); return $shibUser; } /** * @return null|ShibUser */ private function getAuthenticatedUser() { if (null !== $this->resolvedIdentity) { return $this->resolvedIdentity; } /** @var ShibService $shib */ $shib = $this->getServiceLocator()->get(ShibService::class); $this->resolvedIdentity = $shib->getAuthenticatedUser(); return $this->resolvedIdentity; } /** * Writes $contents to storage * Loading
src/UnicaenAuth/Authentication/Storage/ShibSimulatorStorage.php 0 → 100644 +70 −0 Original line number Diff line number Diff line <?php namespace UnicaenAuth\Authentication\Storage; use UnicaenAuth\Service\ShibService; use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceLocatorAwareTrait; /** * Storage permettant de simuler un utilisateur authentifié via Shibboleth. * * @author Unicaen */ class ShibSimulatorStorage implements ChainableStorage, ServiceLocatorAwareInterface { use ServiceLocatorAwareTrait; /** * @var ShibService */ protected $shibService; /** * @var array */ protected $shibbolethOptions; /** * {@inheritdoc} */ public function read(ChainEvent $e) { if (! $this->getShibService()->isShibbolethEnabled()) { return; } if (! $this->getShibService()->isSimulationActive()) { return; } $this->getShibService()->handleSimulation(); } /** * {@inheritdoc} */ public function write(ChainEvent $e) { // nop } /** * {@inheritdoc} */ public function clear(ChainEvent $e) { // nop } /** * @return ShibService */ private function getShibService() { if ($this->shibService === null) { $this->shibService = $this->serviceLocator->get(ShibService::class); } return $this->shibService; } } No newline at end of file