Skip to content
Snippets Groups Projects
Select Git revision
  • 0dac91d42c550986b47d5f43478f777d6fd1c386
  • master default protected
  • 5.x
  • ll-php8-bs5
  • release_5_bs5
  • ll-php8
  • 4.x
  • laminas_migration
  • release_1.0.0.2
  • release_4.0.0
  • release_3.2.8
  • bootstrap4_migration
  • 1.0.0.3
  • 6.0.7
  • 6.0.6
  • 6.0.5
  • 6.0.4
  • 6.0.3
  • 6.0.2
  • 6.0.1
  • 5.1.1
  • 6.0.0
  • 5.1.0
  • 5.0.0
  • 4.0.2
  • 3.2.11
  • 4.0.1
  • 3.2.10
  • 4.0.0
  • 1.0.0.2
  • 3.2.9
  • 3.2.8
32 results

UserProfileFactoryTest.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AuthController.php 2.43 KiB
    <?php
    
    namespace UnicaenAuth\Controller;
    
    use UnicaenApp\Exception\RuntimeException;
    use UnicaenAuth\Service\Traits\ShibServiceAwareTrait;
    use UnicaenAuth\Service\Traits\UserServiceAwareTrait;
    use Zend\Authentication\AuthenticationService;
    use Zend\Authentication\Exception\ExceptionInterface;
    use Zend\Http\Response;
    use Zend\Mvc\Controller\AbstractActionController;
    use ZfcUser\Controller\Plugin\ZfcUserAuthentication;
    
    /**
     * Classe ajoutée lors de l'implémentation de l'auth Shibboleth.
     *
     * @method ZfcUserAuthentication zfcUserAuthentication()
     * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
     */
    class AuthController extends AbstractActionController
    {
        use ShibServiceAwareTrait;
        use UserServiceAwareTrait;
    
        /**
         * @return Response|array
         */
        public function shibbolethAction()
        {
            $operation = $this->params()->fromRoute('operation');
    
            if ($operation === 'deconnexion') {
                // déconnexion applicative quoiqu'il arrive
                $this->zfcUserAuthentication()->getAuthAdapter()->resetAdapters();
                $this->zfcUserAuthentication()->getAuthAdapter()->logoutAdapters();
                $this->zfcUserAuthentication()->getAuthService()->clearIdentity();
    
                // déconnexion Shibboleth le cas échéant
                if ($this->shibService->isShibbolethEnable()) {
                    $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
                }
            }
    
            $shibUser = $this->shibService->getAuthenticatedUser();
    
            if ($shibUser === null) {
                return []; // une page d'aide s'affichera
            }
    
            /** @var AuthenticationService $authService */
            $authService = $this->getServiceLocator()->get('zfcuser_auth_service');
            try {
                $authService->getStorage()->write($shibUser->getUsername());
            } catch (ExceptionInterface $e) {
                throw new RuntimeException("Impossible d'écrire dans le storage");
            }
    
            $this->userService->userAuthenticated($shibUser);
    
            $redirectUrl = $this->params()->fromQuery('redirect', '/');
    
            return $this->redirect()->toUrl($redirectUrl);
        }
    
        public function shibboleth()
        {
    
        }
    }