Skip to content
Snippets Groups Projects
Select Git revision
  • ac49004201ab5d834685959d79b73a0d4eafa92d
  • master default protected
  • ll-workflow
  • alc-scindage-donnees-pj
  • b24
  • FJ_LL_Tbl_Contrat
  • alc-docker-node
  • ll-apiplatform
  • php84
  • ll-rgpd
  • b23
  • alc-filtre-type-intervenant
  • ll-sans-mdb5
  • formules-ancienne-infra
  • ll-formules
  • alc-intervenant-dmep
  • ll-suppr-v_vol-s
  • b20
  • ll-postgresql
  • b23.0.1
  • b22
  • 24.8
  • 24.7
  • 24.6
  • 24.5
  • 24.4
  • 24.3
  • 24.2
  • 24.1
  • 24.0
  • 23.15
  • 24.0-beta19
  • 24.0-beta18
  • 24.0-beta17
  • 24.0-beta16
  • 24.0-beta15
  • 24.0-beta14
  • 24.0-beta13
  • 23.14
  • 24.0-beta12
  • 24.0-beta11
41 results

DataGen.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Module.php 4.46 KiB
    <?php
    
    namespace UnicaenAuth;
    
    use UnicaenAuth\Authentication\Adapter\Cas as CasAdapter;
    use UnicaenAuth\Options\ModuleOptions;
    use UnicaenAuth\Service\ShibService;
    use Zend\EventManager\EventInterface;
    use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
    use Zend\ModuleManager\Feature\ConfigProviderInterface;
    use Zend\ModuleManager\Feature\ServiceProviderInterface;
    use Zend\ServiceManager\Exception\ServiceNotFoundException;
    use Zend\ServiceManager\ServiceLocatorInterface;
    use Zend\View\Helper\Navigation;
    use ZfcUser\Form\Login;
    use ZfcUser\Form\LoginFilter;
    
    /**
     * Point d'entrée du module d'authentification Unicaen.
     *
     * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
     */
    class Module implements AutoloaderProviderInterface, ConfigProviderInterface, ServiceProviderInterface
    {
        /**
         * @var ModuleOptions
         */
        private $options;
    
        /**
         * @return array
         * @see ConfigProviderInterface
         */
        public function getConfig()
        {
            return include __DIR__ . '/config/module.config.php';
        }
    
        /**
         * @return array
         * @see AutoloaderProviderInterface
         */
        public function getAutoloaderConfig()
        {
            return [
                'Zend\Loader\ClassMapAutoloader' => [
                    __DIR__ . '/autoload_classmap.php',
                ],
                'Zend\Loader\StandardAutoloader' => [
                    'namespaces' => [
                        __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                    ],
                ],
            ];
        }
    
        /**
         * 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
         */
        public function onBootstrap(EventInterface $e)
        {
            /* @var \Zend\Mvc\MvcEvent $e */
            $application = $e->getApplication();
            /* @var $services \Zend\ServiceManager\ServiceManager */
            $services = $application->getServiceManager();
    
            // transmission des ACL aux aides de vue de navigation
            try {
                $authorizeService = $services->get('BjyAuthorize\Service\Authorize');
                /* @var $authorizeService \BjyAuthorize\Service\Authorize */
                Navigation::setDefaultAcl($authorizeService->getAcl());
                Navigation::setDefaultRole($authorizeService->getIdentity());
            } catch (ServiceNotFoundException $snfe) {
                // pas de module BjyAuthorize : pas d'ACL
            }
    
            /* @var $options ModuleOptions */
            $this->options = $services->get('unicaen-auth_module_options');
    
            $this->reconfigureRoutesForAuth($services);
        }
    
        /**
         * @param ServiceLocatorInterface $sl
         */
        private function reconfigureRoutesForAuth(ServiceLocatorInterface $sl)
        {
            /* @var $router \Zend\Mvc\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.
            $isCasEnable = (bool) $this->options->getCas();
            if ($isCasEnable && php_sapi_name() !== 'cli') {
                /** @var CasAdapter $casAdapter */
                $casAdapter = $sl->get('UnicaenAuth\Authentication\Adapter\Cas');
                $casAdapter->reconfigureRoutesForCasAuth($router);
            }
    
            // si l'auth Shibboleth est activée, modif de la route de déconnexion pour réaliser la déconnexion Shibboleth.
            $shibOptions = $this->options->getShibboleth();
            $isShibEnable = array_key_exists('enable', $shibOptions) && (bool) $shibOptions['enable'];
            if ($isShibEnable && php_sapi_name() !== 'cli') {
                /** @var ShibService $shibService */
                $shibService = $sl->get(ShibService::class);
                $shibService->reconfigureRoutesForShibAuth($router);
            }
        }
    
        /**
         * @return array
         * @see ServiceProviderInterface
         */
        public function getServiceConfig()
        {
            return [
                'factories' => [
                    // verrue pour forcer le label de l'identifiant qqsoit l'options 'auth_identity_fields'
                    'zfcuser_login_form' => function ($sm) {
                        $options = $sm->get('zfcuser_module_options');
                        $form    = new Login(null, $options);
                        $form->setInputFilter(new LoginFilter($options));
                        $form->get('identity')->setLabel("Username");
    
                        return $form;
                    },
                ],
            ];
        }
    }