Skip to content
Snippets Groups Projects
Select Git revision
  • 2803eb8fe53ec9e696d9ada2a22d7839dda4801d
  • 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

Module.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Module.php 8.27 KiB
    <?php
    
    namespace UnicaenAuth;
    
    use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
    use Zend\ModuleManager\Feature\ConfigProviderInterface;
    use Zend\ModuleManager\Feature\ServiceProviderInterface;
    use Zend\ModuleManager\Feature\ViewHelperProviderInterface;
    use Zend\View\HelperPluginManager;
    
    /**
     * Point d'entrée du module d'authentification Unicaen.
     * 
     * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
     */
    class Module implements ConfigProviderInterface, ViewHelperProviderInterface, ServiceProviderInterface
    {
        /**
         * 
         * @return array
         * @see ConfigProviderInterface
         */
        public function getConfig()
        {
            return include __DIR__ . '/config/module.config.php';
        }
    
        /**
         * 
         * @return array
         * @see AutoloaderProviderInterface
         */
        public function getAutoloaderConfig()
        {
            return array(
                'Zend\Loader\ClassMapAutoloader' => array(
                    __DIR__ . '/autoload_classmap.php',
                ),
                'Zend\Loader\StandardAutoloader' => array(
                    'namespaces' => array(
                        __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(\Zend\EventManager\EventInterface $e) /* @var \Zend\Mvc\MvcEvent $e */
        {
            $application = $e->getApplication();
            /* @var $services \Zend\ServiceManager\ServiceManager */
            $services    = $application->getServiceManager();
            
    //        /* @var $vhm HelperPluginManager */
    //        $vhm = $services->get('view_helper_manager');
    //        /* @var $nvh Navigation */
    //        $nvh = $vhm->get('navigation');
    //        /* @var $authorizeService \BjyAuthorize\Service\Authorize */
    //        $authorizeService = $services->get('BjyAuthorize\Service\Authorize');
    //        $nvh->setAcl($authorizeService->getAcl())->setRole($authorizeService->getIdentity());
    
            /* @var $options Options\ModuleOptions */
            $options = $services->get('unicaen-auth_module_options');
            
            // si l'auth CAS est demandée, modif de la route de connexion pour zapper le formulaire
            if ($options->getCasAuthenticationActivated()) {
                /* @var $router \Zend\Mvc\Router\Http\TreeRouteStack */
                $router = $services->get('router');
                $router->addRoutes(array(
                    // remplace les routes existantes (cf. config du module)
                    'zfcuser' => array(
                        'type' => 'Literal',
                        'priority' => 1000,
                        'options' => array(
                            'route' => '/utilisateur',
                            'defaults' => array(
                                'controller' => 'zfcuser',
                                'action'     => 'index',
                            ),
                        ),
                        'may_terminate' => true,
                        'child_routes' => array(
                            'login' => array(
                                'type' => 'Literal',
                                'options' => array(
                                    'route' => '/connexion',
                                    'defaults' => array(
                                        'controller' => 'zfcuser',
                                        'action'     => 'authenticate', // zappe l'action 'login'
                                    ),
                                ),
                            ),
                            'logout' => array(
                                'type' => 'Literal',
                                'options' => array(
                                    'route' => '/deconnexion',
                                    'defaults' => array(
                                        'controller' => 'zfcuser',
                                        'action'     => 'logout',
                                    ),
                                ),
                            ),
                        ),
                    )
                ));
            }
        }
    
        /**
         * 
         * @return array
         * @see ViewHelperProviderInterface
         */
        public function getViewHelperConfig()
        {
            return array(
                'factories' => array(
                    'appConnection' => function (HelperPluginManager $sm) {
                        return new View\Helper\AppConnection();
                    },
                    'userConnection' => function (HelperPluginManager $sm) {
                        return new View\Helper\UserConnection($sm->getServiceLocator()->get('zfcuser_auth_service'));
                    },
                    'userCurrent' => function (HelperPluginManager $sm) {
                        return new View\Helper\UserCurrent($sm->getServiceLocator()->get('zfcuser_auth_service'));
                    },
                    'userStatus' => function (HelperPluginManager $sm) {
                        return new View\Helper\UserStatus($sm->getServiceLocator()->get('zfcuser_auth_service'));
                    },
                    'userProfile' => function (HelperPluginManager $sm) {
                        $helper = new View\Helper\UserProfile($sm->getServiceLocator()->get('zfcuser_auth_service'));
    //                    $helper->setIdentityProvider($sm->getServiceLocator()->get('BjyAuthorize\Service\Authorize')->getIdentityProvider());
                        return $helper;
                    },
                    'userInfo' => function (HelperPluginManager $sm) {
                        $helper = new View\Helper\UserInfo($sm->getServiceLocator()->get('zfcuser_auth_service'));
                        $helper->setServiceStructure($sm->getServiceLocator()->get('ldap_structure_service'));
                        return $helper;
                    },
                ),
            );
        }
    
        /**
         * 
         * @return array
         * @see ServiceProviderInterface
         */
        public function getServiceConfig()
        {
            return array(
                'factories' => array(
                    'unicaen-auth_module_options' => function($sm) {
                        $config = $sm->get('Configuration');
                        return new Options\ModuleOptions(isset($config['unicaen-auth']) ? $config['unicaen-auth'] : array());
                    },
                    'UnicaenAuth\Authentication\Adapter\Db' => function() {
                        return new Authentication\Adapter\Db();
                    },
                    'UnicaenAuth\Authentication\Adapter\Ldap' => function() {
                        return new Authentication\Adapter\Ldap();
                    },
                    'UnicaenAuth\Authentication\Adapter\Cas' => function() {
                        return new Authentication\Adapter\Cas();
                    },
                    'UnicaenAuth\Authentication\Storage\Db' => function() {
                        return new Authentication\Storage\Db();
                    },
                    'UnicaenAuth\Authentication\Storage\Ldap' => function() {
                        return new Authentication\Storage\Ldap();
                    },
                    'unicaen-auth_user_service' => function () {
                        return new Service\User();
                    },
                    'zfcuser_auth_service' => function ($sm) {
                        return new \Zend\Authentication\AuthenticationService(
                            $sm->get('UnicaenAuth\Authentication\Storage\Mixed'),
                            $sm->get('ZfcUser\Authentication\Adapter\AdapterChain')
                        );
                    },
                    'UnicaenAuth\View\UnauthorizedStrategy' => function (\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) {
                        $config = $serviceLocator->get('Config');
                        return new View\UnauthorizedStrategy($config['bjyauthorize']['template']);
                    },
                    'UnicaenAuth\Authentication\Storage\Mixed' => function($sm) {
                        $storage = new Authentication\Storage\Mixed();
                        $storage->setLdapStorage($sm->get('UnicaenAuth\Authentication\Storage\Ldap'))
                                ->setDbStorage($sm->get('UnicaenAuth\Authentication\Storage\Db'));
                        return $storage;
                    },
                    'ZfcUser\Authentication\Adapter\AdapterChain' => 'UnicaenAuth\Authentication\Adapter\AdapterChainServiceFactory',
                ),
            );
        }
    }