Commit 6d3ff3d5 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Ajout d'une option de config d'activation ou non de l'auth LDAP (nouvelle clé...

Ajout d'une option de config d'activation ou non de l'auth LDAP (nouvelle clé unicaen-auth > ldap > enabled). Pour l'instant, l'impact est juste l'affichage ou pas du formulaire de connexion LDAP.
parent 4f6859c0
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
<?php

use UnicaenAuth\Authentication\Adapter\ShibSimulatorAdapter;
use UnicaenAuth\Authentication\Storage\ShibSimulatorStorage;
use UnicaenAuth\Controller\AuthControllerFactory;
use UnicaenAuth\Service\ShibService;
use UnicaenAuth\Service\ShibServiceFactory;
use UnicaenAuth\Service\UserContextFactory;
use UnicaenAuth\View\Helper\LdapConnectViewHelperFactory;
use UnicaenAuth\View\Helper\ShibConnectViewHelperFactory;
use UnicaenAuth\View\Helper\UserUsurpationHelperFactory;

$settings = [

    /**
     * Configuration de l'authentification LDAP.
     */
    'ldap' => [
        /**
         * Possibilité ou non de s'authentifier via l'annuaire LDAP.
         */
        'enabled' => true,
    ],

    /**
     * Fournisseurs d'identité.
     */
@@ -442,6 +453,7 @@ return [
            'userProfileSelect'          => 'UnicaenAuth\View\Helper\UserProfileSelectFactory',
            'userProfileSelectRadioItem' => 'UnicaenAuth\View\Helper\UserProfileSelectRadioItemFactory',
            'userUsurpation'             => UserUsurpationHelperFactory::class,
            'ldapConnect'                => LdapConnectViewHelperFactory::class,
            'shibConnect'                => ShibConnectViewHelperFactory::class,
        ],
        'invokables' => [
+13 −0
Original line number Diff line number Diff line
@@ -6,6 +6,17 @@
 * drop this config file in it and change the values as you wish.
 */
$settings = [

    /**
     * Configuration de l'authentification LDAP.
     */
    'ldap' => [
        /**
         * Possibilité ou non de s'authentifier via l'annuaire LDAP.
         */
        'enabled' => true,
    ],

    /**
     * Flag indiquant si l'utilisateur authenitifié avec succès via l'annuaire LDAP doit
     * être enregistré/mis à jour dans la table des utilisateurs de l'appli.
@@ -25,6 +36,7 @@ $settings = [

$config = [
    'unicaen-auth' => $settings,

    'bjyauthorize' => [
        /* this module uses a meta-role that inherits from any roles that should
         * be applied to the active user. the identity provider tells us which
@@ -54,6 +66,7 @@ $config = [
            'UnicaenAuth\Provider\Role\Username' => [],
        ],
    ],

    'zfcuser'      => [
        /**
         * Classe de l'entité représentant un utilisateur authentifiable.
+50 −42
Original line number Diff line number Diff line
<?php

return [
    'unicaen-auth' => [

        /**
 * Configuration locale du module UnicaenAuth.
 *
 * If you have a ./config/autoload/ directory set up for your project, you can
 * drop this config file in it and change the values as you wish.
 */
$settings = [
    /**
     * Activation ou non de l'authentification Shibboleth.
         * Configuration de l'authentification Shibboleth.
         */
        'shibboleth' => [
            'enable' => false,
            'simulate' => [
                'eppn'        => 'gauthierb@unicaen.fr',
                'supannEmpId' => '00021237',
            ],
            'aliases' => [
                'eppn'                   => 'HTTP_EPPN',
                'mail'                   => 'HTTP_MAIL',
                'eduPersonPrincipalName' => 'HTTP_EPPN',
                'supannEtuId'            => 'HTTP_SUPANNETUID',
                'supannEmpId'            => 'HTTP_SUPANNEMPID',
                'supannCivilite'         => 'HTTP_SUPANNCIVILITE',
                'displayName'            => 'HTTP_DISPLAYNAME',
                'sn'                     => 'HTTP_SN',
                'givenName'              => 'HTTP_GIVENNAME',
            ],
        ],

        /**
         * Paramètres de connexion au serveur CAS :
         * - pour désactiver l'authentification CAS, le tableau 'cas' doit être vide.
         * - pour l'activer, renseigner les paramètres.
         */
        'cas' => [
//        'connection' => array(
//            'default' => array(
//                'params' => array(
//                    'hostname' => 'cas.unicaen.fr',
//                    'port' => 443,
//                    'version' => "2.0",
//                    'uri' => "",
//                    'debug' => false,
//                ),
//            ),
//        ),
            'connection' => [
                'default' => [
                    'params' => [
                        'hostname' => 'cas.unicaen.fr',
                        'port'     => 443,
                        'version'  => "2.0",
                        'uri'      => "",
                        'debug'    => false,
                    ],
                ],
            ],
        ],

        /**
         * Identifiants de connexion LDAP autorisés à faire de l'usurpation d'identité.
         * NB: à réserver exclusivement aux tests.
         */
//    'usurpation_allowed_usernames' => array(),
];

/**
 * You do not need to edit below this line
 */
return [
    'unicaen-auth' => $settings,
        'usurpation_allowed_usernames' => [],
    ],
];
+30 −6
Original line number Diff line number Diff line
@@ -9,6 +9,13 @@ namespace UnicaenAuth\Options;
 */
class ModuleOptions extends \ZfcUser\Options\ModuleOptions
{
    /**
     * Paramètres concernant l'authentification LDAP.
     *
     * @var array
     */
    protected $ldap = [];

    /**
     * @var array
     */
@@ -39,6 +46,29 @@ class ModuleOptions extends \ZfcUser\Options\ModuleOptions
     */
    protected $entityManagerName = 'doctrine.entitymanager.orm_default';

    /**
     * Retourne les paramètres concernant l'authentification LDAP.
     *
     * @return array
     */
    public function getLdap()
    {
        return $this->ldap;
    }

    /**
     * Spécifie les paramètres concernant l'authentification LDAP.
     *
     * @param array $ldap
     * @return self
     */
    public function setLdap(array $ldap)
    {
        $this->ldap = $ldap;

        return $this;
    }

    /**
     * set usernames allowed to make usurpation
     *
@@ -89,8 +119,6 @@ class ModuleOptions extends \ZfcUser\Options\ModuleOptions
        return $this->saveLdapUserInDatabase;
    }



    /**
     * @return string
     */
@@ -99,8 +127,6 @@ class ModuleOptions extends \ZfcUser\Options\ModuleOptions
        return $this->ldapUsername;
    }



    /**
     * @param string $ldapUsername
     *
@@ -113,8 +139,6 @@ class ModuleOptions extends \ZfcUser\Options\ModuleOptions
        return $this;
    }



    /**
     * set cas connection params
     *
+73 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenAuth\View\Helper;

use Zend\Form\Form;
use Zend\View\Helper\AbstractHelper;
use Zend\View\Renderer\PhpRenderer;
use Zend\View\Resolver\TemplatePathStack;

/**
 * Aide de vue dessinant le formulaire d'authentification LDAP,
 * si l'authentification LDAP est activée.
 *
 * @method PhpRenderer getView()
 * @author Unicaen
 */
class LdapConnectViewHelper extends AbstractHelper
{
    /**
     * @var bool
     */
    protected $enabled = true;

    /**
     * @var Form
     */
    protected $form;

    /**
     * @param bool $enabled
     * @return $this
     */
    public function setEnabled($enabled = true)
    {
        $this->enabled = $enabled;

        return $this;
    }

    /**
     * @param Form $form
     * @return $this
     */
    public function __invoke(Form $form)
    {
        $this->form = $form;

        $this->getView()->resolver()->attach(
            new TemplatePathStack(['script_paths' => [__DIR__ . "/partial"]])
        );

        return $this;
    }

    /**
     * @return string
     */
    public function __toString()
    {
        if (! $this->enabled) {
            return '';
        }

        try {
            return $this->getView()->render("ldap-connect", [
                'enabled' => $this->enabled,
                'form' => $this->form,
            ]);
        } catch (\Exception $e) {
            return '<p>' . $e->getMessage() . '</p><p>' . $e->getTraceAsString() . '</p>';
        }
    }
}
 No newline at end of file
Loading