Commit 94f5896c authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Merge branch 'macclane-patch-ldap' into spartan

parents 364579a9 278c4292
Loading
Loading
Loading
Loading
+396 −297

File changed.

Preview size limit exceeded, changes collapsed.

+158 −0
Original line number Diff line number Diff line
@@ -6,6 +6,164 @@
 * drop this config file in it and change the values as you wish.
 */
$settings = array(
/**
    // -------------------------------------- Authentification BDD/LDAP
    'local' => [
        'order' => 2,
        'enabled' => true,
        'description' => "Utilisez ce formulaire si vous possédez un compte LDAP établissement ou un compte local dédié à l'application.",

        // --- Base de données
        'db' => [
            'enabled' => true, // doit être activé pour que l'usurpation fonctionne (cf. Authentication/Storage/Db::read()) :-/
        ],
        // -- LDAP
        'ldap' => [
            'enabled' => true,
        ],
    ],

//    'db' => [
//        'order' => 1,
//        'enabled' => true,
//        'type' => 'local',
//
//        /**
//         * Description facultative de ce mode d'authentification qui apparaîtra sur le formulaire d'authentification.
//         * (NB: Si l'authentification LDAP est également activée, c'est cette description qui sera utilisée)
//         */
//        'description' => "Utilisez ce formulaire si vous possédez un compte local dédié à cette application.",
//    ],
//
//    'ldap' => [
//        /**
//         * Ordre d'affichage du formulaire de connexion.
//         */
//        'order' => 2,
//
//        /**
//         * Activation ou non de ce mode d'authentification.
//         */
//        'enabled' => true,
//
//        /**
//         * Type de substitution.
//         * Permet de "fusionner" les types d'authentification applicative (db) et établissement (ldap) et donc leurs
//         * formulaires de connexion respectifs.
//         */
//        'type' => 'local',
//
//        /**
//         * Description facultative de ce mode d'authentification qui apparaîtra sur le formulaire de connexion.
//         */
//        'description' => "Utilisez ce formulaire si vous possédez un compte établissement.",
//    ],

    /**
     * Authentification via la fédération d'identité (Shibboleth).
     */
    'shib' => [
        'order' => 4,
        'enabled' => false,
        'description' =>
            "Cliquez sur le bouton ci-dessous pour accéder à l'authentification via la fédération d'identité. " .
            "<strong>NB: Vous devrez utiliser votre compte " .
            "&laquo; <a href='http://vie-etudiante.unicaen.fr/vie-numerique/etupass/'>etupass</a> &raquo; " .
            "pour vous authentifier...</strong>",

        /**
         * URL de déconnexion.
         */
        'logout_url' => '/Shibboleth.sso/Logout?return=', // NB: '?return=' semble obligatoire!

        /**
         * Simulation d'authentification d'un utilisateur.
         */
        //'simulate' => [
        //    'eppn'        => 'eppn@domain.fr',
        //    'supannEmpId' => '00012345',
        //],

        /**
         * Alias éventuels des clés renseignées par Shibboleth dans la variable superglobale $_SERVER
         * une fois l'authentification réussie.
         */
        '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',
        ],

        /**
         * Clés dont la présence sera requise par l'application dans la variable superglobale $_SERVER
         * une fois l'authentification réussie.
         */
        //'required_attributes' => [
        //    'eppn',
        //    'mail',
        //    'eduPersonPrincipalName',
        //    'supannCivilite',
        //    'displayName',
        //    'sn|surname', // i.e. 'sn' ou 'surname'
        //    'givenName',
        //    'supannEtuId|supannEmpId',
        //],
    ],

    'cas' => [
        /**
         * Ordre d'affichage du formulaire de connexion.
         */
        'order' => 1,

        /**
         * Activation ou non de ce mode d'authentification.
         */
        'enabled' => false,

        /**
         * Description facultative de ce mode d'authentification qui apparaîtra sur la page de connexion.
         */
        'description' => "Cliquez sur le bouton ci-dessous pour accéder à l'authentification centralisée.",

        /**
         * Infos de connexion au serveur CAS.
         */
        'connection' => [
            'default' => [
                'params' => [
                    'hostname' => 'host.domain.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('sbouvry', 'bouvry', 'turbout'),

    // Champ utilisé pour l'autentification (côté LDAP)
    //'ldap_username' => 'supanaliaslogin',





////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /**
     * Paramètres de connexion au serveur CAS :
     * - pour désactiver l'authentification CAS, le tableau 'cas' doit être vide.
+74 −0
Original line number Diff line number Diff line
# MACCLANE : Patch LDAP
## 6 mai 2021

Ce patch introduit un FIX/Up sur la partie authentification de Oscar. 
Il simplifie la configuration d'authentification multiple 
 - CAS
 - LDAP / Local(Base de données)
 - Shibboleth

Ce patch résout également certains problème d'authentification liè au rôles LDAP.

La mise en place de ce patch implique des changements sur la configuration de l'authentification. Voici le **contenu minimal** attendu dans le fichier `config/autoload/unicaen-auth.local.php`

> **Important** : Toutes les clefs doivent être présentent dans le fichier, même si la méthode de connexion n'est pas utilisée. Pour activer/désactiver une méthode de configuration, modifiez simplement la valeur `enable` sur `true/false` selon les besoins.

```php
<?php
// ./config/autoload/unicaen-auth.local.php
$settings = array(
    // LDAP / DB
    'local' => [
        'order' => 2,
        'enabled' => true,
        'db' => [
            'enabled' => true,
        ],
        'ldap' => [
            'enabled' => true,
        ],
    ],

     // Authentification via la fédération d'identité (Shibboleth).
    'shib' => [
        'order' => 4,
        'enabled' => false,
        'logout_url' => '/Shibboleth.sso/Logout?return=', // NB: '?return=' semble obligatoire!
        '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',
        ],
    ],
    
    // CAS
    'cas' => [
        'order' => 1,
        'enabled' => false,
        'connection' => [
            'default' => [
                'params' => [
                    'hostname' => 'host.domain.fr',
                    'port'     => 443,
                    'version'  => "2.0",
                    'uri'      => "",
                    'debug'    => false,
                ],
            ],
        ]
    ],
);

/**
 * You do not need to edit below this line
 */
return array(
    'unicaen-auth' => $settings,
);
```
 No newline at end of file
+36 −26
Original line number Diff line number Diff line
@@ -9,39 +9,49 @@

namespace Oscar;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Monolog\Logger;
use Oscar\Auth\UserAuthenticatedEventListener;
use Oscar\Entity\LogActivity;
use Oscar\Entity\ActivityLogRepository;
use Oscar\Entity\Authentification;
use Oscar\Exception\OscarException;
use Oscar\Service\ActivityLogService;
use Oscar\Service\OscarUserContext;
use Oscar\Service\PersonService;
use UnicaenAuth\Authentication\Adapter\Ldap;
use UnicaenAuth\Event\UserAuthenticatedEvent;
use UnicaenAuth\Provider\Identity\ChainEvent;
use UnicaenAuth\Service\User;
use UnicaenAuth\Service\UserContext;
use Zend\Authentication\Result;
use Zend\Console\Adapter\AdapterInterface;
use Zend\EventManager\Event;
use Zend\Http\PhpEnvironment\Request;
use Zend\ModuleManager\Feature\ConsoleBannerProviderInterface;
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface;
use Zend\ModuleManager\ModuleEvent;
use Zend\Authentication\Result as AuthenticationResult;
use Zend\ModuleManager\ModuleManager;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\Router\Http\RouteMatch;
use Zend\ServiceManager\ServiceManager;
use ZfcUser\Authentication\Adapter\AdapterChainEvent;

class Module
{


    public function onBootstrap(MvcEvent $e)
    {
        // TODO a tester
        $e->getApplication()->getEventManager()->getSharedManager()->attach(
            "*",
            'authenticate', //"authentication.success",
                    [$this, "onUserLogin"],
                100
        );
    }

    public function onUserLogin( $e ) {
        die("onUserLogin");

//        if (is_string(\$identity = \$e->getIdentity())) {
//            // login de l'utilisateur authentifié
//            \$username = \$identity;
//            //...
//        } else {
//            // id de l'utilisateur authentifié dans la table
//            \$id = \$identity;
//            //...
//        }
      //...
}

    // FIX : ZendFramework 3
    public function init(ModuleManager $manager)
    {

    }


    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
+6 −0
Original line number Diff line number Diff line
@@ -23,6 +23,12 @@ return array(
                    'roles' => [],
                ],

                [
                    'controller' => '\UnicaenAuth\Controller\Utilisateur',
                    'action' => ['usurperIdentite'],
                    'roles' => []
                ],

                [ 'controller' =>  'Public',
                    'action' => ['documentation', 'parameters', 'gitlog'],
                    'roles' => ['user'],
Loading