Loading config/module.config.php +2 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ 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 @@ -432,6 +433,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/Storage/Shib.php +45 −3 Original line number Diff line number Diff line Loading @@ -51,15 +51,57 @@ 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 (! $this->isShibbolethEnabled()) { return null; } if (null !== $this->resolvedIdentity) { return $this->resolvedIdentity; } /** @var ShibService $shib */ $shib = $this->getServiceLocator()->get(ShibService::class); $this->resolvedIdentity = $shib->getAuthenticatedUser(); return $this->resolvedIdentity; } /** * @return bool */ private function isShibbolethEnabled() { $options = $this->getModuleOptions(); $shibboleth = $options->getShibboleth(); return isset($shibboleth['enable']) && (bool) $shibboleth['enable']; } /** * @return ModuleOptions */ private function getModuleOptions() { if (null === $this->options) { $this->options = $this->getServiceLocator()->get('unicaen-auth_module_options'); } return $this->options; } /** * Writes $contents to storage * Loading src/UnicaenAuth/Controller/AuthController.php +17 −6 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace UnicaenAuth\Controller; use UnicaenApp\Exception\RuntimeException; use UnicaenAuth\Service\ShibService; use UnicaenAuth\Service\Traits\ShibServiceAwareTrait; use UnicaenAuth\Service\Traits\UserServiceAwareTrait; use Zend\Authentication\AuthenticationService; Loading @@ -23,6 +24,16 @@ class AuthController extends AbstractActionController use UserServiceAwareTrait; /** * Cette action n'est exécutée qu'une fois l'authentification Shibboleth réalisée avec succès. * * Lorsque l'authentification Shibboleth est activée (unicaen-auth.shibboleth.enable === true), * et que la config Apache est correcte, une requête à l'adresse correspondant à cette action * (suite au clic sur le bouton "Authentification Shibboleth, typiquement) * est détournée pour réaliser l'authentification. * Ce n'est qu'une fois l'authentification réalisée avec succès que cette action entre en jeu. * * @see ShibService::apacheConfigSnippet() * * @return Response|array */ public function shibbolethAction() Loading @@ -36,9 +47,14 @@ class AuthController extends AbstractActionController $this->zfcUserAuthentication()->getAuthService()->clearIdentity(); // déconnexion Shibboleth le cas échéant if ($this->shibService->isShibbolethEnable()) { if ($this->shibService->isShibbolethEnabled()) { // désactivation de l'usurpation d'identité éventuelle $this->shibService->deactivateUsurpation(); // URL par défaut vers laquelle on redirige après déconnexion : accueil $homeUrl = $this->url()->fromRoute('home', [], ['force_canonical' => true]); $returnAbsoluteUrl = $this->params()->fromQuery('return', $homeUrl); return $this->redirect()->toUrl($this->shibService->getLogoutUrl($returnAbsoluteUrl)); } else { return []; // une page d'aide s'affichera Loading @@ -65,9 +81,4 @@ class AuthController extends AbstractActionController return $this->redirect()->toUrl($redirectUrl); } public function shibboleth() { } } No newline at end of file src/UnicaenAuth/Controller/UtilisateurController.php +0 −2 Original line number Diff line number Diff line Loading @@ -6,8 +6,6 @@ use Zend\Http\Request; use Zend\Mvc\Controller\AbstractActionController; /** * * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ class UtilisateurController extends AbstractActionController Loading src/UnicaenAuth/Entity/Shibboleth/ShibUser.php +10 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,16 @@ class ShibUser implements UserInterface return $this->getUsername(); } /** * Set eduPersoPrincipalName (EPPN). * * @param string $eppn eduPersoPrincipalName (EPPN), ex: 'gauthierb@unicaen.fr' */ public function setEppn($eppn) { $this->setUsername($eppn); } /** * Get id. * Loading Loading
config/module.config.php +2 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ 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 @@ -432,6 +433,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/Storage/Shib.php +45 −3 Original line number Diff line number Diff line Loading @@ -51,15 +51,57 @@ 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 (! $this->isShibbolethEnabled()) { return null; } if (null !== $this->resolvedIdentity) { return $this->resolvedIdentity; } /** @var ShibService $shib */ $shib = $this->getServiceLocator()->get(ShibService::class); $this->resolvedIdentity = $shib->getAuthenticatedUser(); return $this->resolvedIdentity; } /** * @return bool */ private function isShibbolethEnabled() { $options = $this->getModuleOptions(); $shibboleth = $options->getShibboleth(); return isset($shibboleth['enable']) && (bool) $shibboleth['enable']; } /** * @return ModuleOptions */ private function getModuleOptions() { if (null === $this->options) { $this->options = $this->getServiceLocator()->get('unicaen-auth_module_options'); } return $this->options; } /** * Writes $contents to storage * Loading
src/UnicaenAuth/Controller/AuthController.php +17 −6 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace UnicaenAuth\Controller; use UnicaenApp\Exception\RuntimeException; use UnicaenAuth\Service\ShibService; use UnicaenAuth\Service\Traits\ShibServiceAwareTrait; use UnicaenAuth\Service\Traits\UserServiceAwareTrait; use Zend\Authentication\AuthenticationService; Loading @@ -23,6 +24,16 @@ class AuthController extends AbstractActionController use UserServiceAwareTrait; /** * Cette action n'est exécutée qu'une fois l'authentification Shibboleth réalisée avec succès. * * Lorsque l'authentification Shibboleth est activée (unicaen-auth.shibboleth.enable === true), * et que la config Apache est correcte, une requête à l'adresse correspondant à cette action * (suite au clic sur le bouton "Authentification Shibboleth, typiquement) * est détournée pour réaliser l'authentification. * Ce n'est qu'une fois l'authentification réalisée avec succès que cette action entre en jeu. * * @see ShibService::apacheConfigSnippet() * * @return Response|array */ public function shibbolethAction() Loading @@ -36,9 +47,14 @@ class AuthController extends AbstractActionController $this->zfcUserAuthentication()->getAuthService()->clearIdentity(); // déconnexion Shibboleth le cas échéant if ($this->shibService->isShibbolethEnable()) { if ($this->shibService->isShibbolethEnabled()) { // désactivation de l'usurpation d'identité éventuelle $this->shibService->deactivateUsurpation(); // URL par défaut vers laquelle on redirige après déconnexion : accueil $homeUrl = $this->url()->fromRoute('home', [], ['force_canonical' => true]); $returnAbsoluteUrl = $this->params()->fromQuery('return', $homeUrl); return $this->redirect()->toUrl($this->shibService->getLogoutUrl($returnAbsoluteUrl)); } else { return []; // une page d'aide s'affichera Loading @@ -65,9 +81,4 @@ class AuthController extends AbstractActionController return $this->redirect()->toUrl($redirectUrl); } public function shibboleth() { } } No newline at end of file
src/UnicaenAuth/Controller/UtilisateurController.php +0 −2 Original line number Diff line number Diff line Loading @@ -6,8 +6,6 @@ use Zend\Http\Request; use Zend\Mvc\Controller\AbstractActionController; /** * * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ class UtilisateurController extends AbstractActionController Loading
src/UnicaenAuth/Entity/Shibboleth/ShibUser.php +10 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,16 @@ class ShibUser implements UserInterface return $this->getUsername(); } /** * Set eduPersoPrincipalName (EPPN). * * @param string $eppn eduPersoPrincipalName (EPPN), ex: 'gauthierb@unicaen.fr' */ public function setEppn($eppn) { $this->setUsername($eppn); } /** * Get id. * Loading