Commit cb28b510 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Merge de la branche 1.2.0.x-dev

parents e491c9ce fc06f5fd
Loading
Loading
Loading
Loading
+48 −58
Original line number Diff line number Diff line
@@ -2,9 +2,18 @@

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.
@@ -14,7 +23,11 @@ use Zend\ModuleManager\Feature\ServiceProviderInterface;
class Module implements AutoloaderProviderInterface, ConfigProviderInterface, ServiceProviderInterface
{
    /**
     *
     * @var ModuleOptions
     */
    private $options;

    /**
     * @return array
     * @see ConfigProviderInterface
     */
@@ -23,10 +36,7 @@ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, Se
        return include __DIR__ . '/config/module.config.php';
    }



    /**
     *
     * @return array
     * @see AutoloaderProviderInterface
     */
@@ -44,8 +54,6 @@ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, Se
        ];
    }



    /**
     * This method is called once the MVC bootstrapping is complete,
     * after the "loadModule.post" event, once $application->bootstrap() is called.
@@ -54,9 +62,9 @@ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, Se
     *
     * @see BootstrapListenerInterface
     */
    public function onBootstrap(\Zend\EventManager\EventInterface $e)
        /* @var \Zend\Mvc\MvcEvent $e */
    public function onBootstrap(EventInterface $e)
    {
        /* @var \Zend\Mvc\MvcEvent $e */
        $application = $e->getApplication();
        /* @var $services \Zend\ServiceManager\ServiceManager */
        $services = $application->getServiceManager();
@@ -65,63 +73,45 @@ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, Se
        try {
            $authorizeService = $services->get('BjyAuthorize\Service\Authorize');
            /* @var $authorizeService \BjyAuthorize\Service\Authorize */
            \Zend\View\Helper\Navigation::setDefaultAcl($authorizeService->getAcl());
            \Zend\View\Helper\Navigation::setDefaultRole($authorizeService->getIdentity());
        } catch (\Zend\ServiceManager\Exception\ServiceNotFoundException $snfe) {
            Navigation::setDefaultAcl($authorizeService->getAcl());
            Navigation::setDefaultRole($authorizeService->getIdentity());
        } catch (ServiceNotFoundException $snfe) {
            // pas de module BjyAuthorize : pas d'ACL
        }

        /* @var $options Options\ModuleOptions */
        $options = $services->get('unicaen-auth_module_options');
        /* @var $options ModuleOptions */
        $this->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->getCas() && php_sapi_name() !== 'cli') {
            /* @var $router \Zend\Mvc\Router\Http\TreeRouteStack */
            $router = $services->get('router');
            $router->addRoutes([
                // remplace les routes existantes (cf. config du module)
                'zfcuser' => [
                    'type'          => 'Literal',
                    'priority'      => 1000,
                    'options'       => [
                        'route'    => '/auth',
                        'defaults' => [
                            'controller' => 'zfcuser',
                            'action'     => 'index',
                        ],
                    ],
                    'may_terminate' => true,
                    'child_routes'  => [
                        'login'  => [
                            'type'    => 'Literal',
                            'options' => [
                                'route'    => '/connexion',
                                'defaults' => [
                                    'controller' => 'zfcuser',
                                    'action'     => 'authenticate', // zappe l'action 'login'
                                ],
                            ],
                        ],
                        'logout' => [
                            'type'    => 'Literal',
                            'options' => [
                                'route'    => '/deconnexion',
                                'defaults' => [
                                    'controller' => 'zfcuser',
                                    'action'     => 'logout',
                                ],
                            ],
                        ],
                    ],
                ],
            ]);
        }
        $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
     */
@@ -132,8 +122,8 @@ class Module implements AutoloaderProviderInterface, ConfigProviderInterface, Se
                // 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 \ZfcUser\Form\Login(null, $options);
                    $form->setInputFilter(new \ZfcUser\Form\LoginFilter($options));
                    $form    = new Login(null, $options);
                    $form->setInputFilter(new LoginFilter($options));
                    $form->get('identity')->setLabel("Username");

                    return $form;
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
    "repositories": [
        {
            "type": "composer",
            "url": "https://dev.unicaen.fr/packagist"
            "url": "https://gest.unicaen.fr/packagist"
        }
    ],
    "require": {
+35 −4
Original line number Diff line number Diff line
<?php

use UnicaenAuth\Provider\Privilege\Privileges;
use UnicaenAuth\Controller\AuthControllerFactory;
use UnicaenAuth\Service\ShibService;
use UnicaenAuth\Service\ShibServiceFactory;
use UnicaenAuth\View\Helper\ShibConnectViewHelperFactory;

$settings = [

    /**
     * Fournisseurs d'identité.
     */
@@ -119,6 +121,8 @@ return [
                ['controller' => 'UnicaenApp\Controller\Application', 'action' => 'informatique-et-libertes', 'roles' => []],
                ['controller' => 'UnicaenApp\Controller\Application', 'action' => 'refresh-session', 'roles' => []],
                ['controller' => 'UnicaenAuth\Controller\Utilisateur', 'action' => 'selectionner-profil', 'roles' => []],

                ['controller' => 'UnicaenAuth\Controller\Auth', 'action' => 'shibboleth', 'roles' => []],
            ],
        ],
    ],
@@ -167,6 +171,27 @@ return [
    ],
    'router'          => [
        'routes' => [
            'auth'     => [
                'type'          => 'Literal',
                'options'       => [
                    'route'    => '/auth',
                    'defaults' => [
                        'controller' => 'UnicaenAuth\Controller\Auth',
                    ],
                ],
                'may_terminate' => false,
                'child_routes'  => [
                    'shibboleth' => [
                        'type' => 'Literal',
                        'options' => [
                            'route'    => '/shibboleth',
                            'defaults' => [
                                'action'     => 'shibboleth',
                            ],
                        ],
                    ],
                ],
            ],
            'zfcuser'     => [
                'type'          => 'Literal',
                'priority'      => 1000,
@@ -346,12 +371,11 @@ return [
        'invokables'         => [
            '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\View\RedirectionStrategy'    => 'UnicaenAuth\View\RedirectionStrategy',
            'UnicaenAuth\Service\UserContext'         => 'UnicaenAuth\Service\UserContext',
            'UnicaenAuth\Service\User'                => 'UnicaenAuth\Service\User',
            'UnicaenAuth\Service\Privilege'           => 'UnicaenAuth\Service\PrivilegeService',
            'UnicaenAuth\Service\CategoriePrivilege'  => 'UnicaenAuth\Service\CategoriePrivilegeService',
            'UnicaenAuth\Service\Role'                => 'UnicaenAuth\Service\RoleService',
        ],
        'abstract_factories' => [
            'UnicaenAuth\Authentication\Adapter\AbstractFactory',
@@ -367,8 +391,11 @@ return [
            'UnicaenAuth\Provider\Role\Config'         => 'UnicaenAuth\Provider\Role\ConfigServiceFactory',
            'UnicaenAuth\Provider\Role\DbRole'         => 'UnicaenAuth\Provider\Role\DbRoleServiceFactory',
            'UnicaenAuth\Provider\Role\Username'       => 'UnicaenAuth\Provider\Role\UsernameServiceFactory',
            'UnicaenAuth\Service\Role'                 => 'UnicaenAuth\Service\RoleServiceFactory',
            'UnicaenAuth\Service\Privilege'            => 'UnicaenAuth\Service\PrivilegeServiceFactory',
            'BjyAuthorize\Service\Authorize'           => 'UnicaenAuth\Service\AuthorizeServiceFactory', // substituion
            'zfcuser_redirect_callback'                => 'UnicaenAuth\Authentication\RedirectCallbackFactory', // substituion
            ShibService::class                         => ShibServiceFactory::class,
            'MouchardCompleterAuth'        => 'UnicaenAuth\Mouchard\MouchardCompleterAuthFactory',
        ],
        'shared' => [
@@ -384,6 +411,9 @@ return [
            'UnicaenAuth\Controller\Utilisateur' => 'UnicaenAuth\Controller\UtilisateurController',
            'UnicaenAuth\Controller\Droits'      => 'UnicaenAuth\Controller\DroitsController',
        ],
        'factories' => [
            'UnicaenAuth\Controller\Auth'        => AuthControllerFactory::class,
        ],
    ],

    'form_elements' => [
@@ -401,6 +431,7 @@ return [
            'userInfo'                   => 'UnicaenAuth\View\Helper\UserInfoFactory',
            'userProfileSelect'          => 'UnicaenAuth\View\Helper\UserProfileSelectFactory',
            'userProfileSelectRadioItem' => 'UnicaenAuth\View\Helper\UserProfileSelectRadioItemFactory',
            'shibConnect'                => ShibConnectViewHelperFactory::class,
        ],
        'invokables' => [
            'appConnection' => 'UnicaenAuth\View\Helper\AppConnection',
+14 −0
Original line number Diff line number Diff line
@@ -67,6 +67,20 @@ $config = [

if ($settings['enable_privileges']) {
    $privileges = [
        'unicaen-auth' => [
            /**
             * Classes représentant les entités rôle et privilège.
             * - Entité rôle      : héritant de \UnicaenAuth\Entity\Db\AbstractRole      ou implémentant \UnicaenAuth\Entity\Db\RoleInterface.
             * - Entité privilège : héritant de \UnicaenAuth\Entity\Db\AbstractPrivilege ou implémentant \UnicaenAuth\Entity\Db\PrivilegeInterface.
             *
             * Valeurs par défaut :
             * - 'role_entity_class'      : 'UnicaenAuth\Entity\Db\Role'
             * - 'privilege_entity_class' : 'UnicaenAuth\Entity\Db\Privilege'
             */
            'role_entity_class'      => 'UnicaenAuth\Entity\Db\Role',
            'privilege_entity_class' => 'UnicaenAuth\Entity\Db\Privilege',
        ],

        'bjyauthorize' => [

            'resource_providers' => [
+6 −0
Original line number Diff line number Diff line
@@ -6,6 +6,12 @@
 * drop this config file in it and change the values as you wish.
 */
$settings = [
    /**
     * Activation ou non de l'authentification Shibboleth.
     */
    'shibboleth' => [
        'enable' => false,
    ],
    /**
     * Paramètres de connexion au serveur CAS :
     * - pour désactiver l'authentification CAS, le tableau 'cas' doit être vide.
Loading