Commit 2f5ea0dd authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Merge branch 'master' of https://git.unicaen.fr/lib/unicaen/auth into zf-3.x

# Conflicts:
#	composer.json
#	composer.lock
#	data/schema.sqlite.sql
#	src/UnicaenAuth/Options/ModuleOptionsFactory.php
#	src/UnicaenAuth/Service/ShibService.php
parents 5ca0247c 2ed36d74
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -11,7 +11,8 @@
        "unicaen/app":                                  "dev-zf-3.x",
        "unicaen/bjy-authorize":                        "dev-zf-3.x",
        "jasig/phpcas":                                 "^1.3",
        "ramsey/uuid":                                  "^3.7"
        "ramsey/uuid":                                  "^3.7",
        "beberlei/assert":                              "^2.9"
    },
    "require-dev": {
        "phpunit/phpunit":                              "^5.6"
+16 −0
Original line number Diff line number Diff line
@@ -28,6 +28,22 @@ $settings = [
        'enabled' => true,
    ],

    /**
     * Configuration de l'authentification Shibboleth.
     */
    'shibboleth' => [
        /**
         * Affichage ou non du formulaire d'authentification via l'annuaire LDAP.
         * NB: en réalité cela permet aussi l'authentification avec un compte local.
         */
        'enable' => false,

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

    /**
     * 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.
+4 −0
Original line number Diff line number Diff line
@@ -69,6 +69,10 @@ CREATE INDEX idx_privilege_id on role_privilege(privilege_id);

-- Données

INSERT INTO user (username, email, display_name, password, state) VALUES
    -- utilisateur admin/azerty
    ('admin', 'admin@mail.fr', 'Administrateur', '$2y$10$QPbyqusyGOOuLlnRCmvZpuKDlAKorxtJJsjeW78bXnIKCFEE.bQiK', 1);

INSERT INTO user_role (id, role_id, is_default, parent_id) VALUES
    (1, 'Standard', 1, NULL),
    (2, 'Gestionnaire', 0, 1),
+39 −0
Original line number Diff line number Diff line
@@ -3,6 +3,9 @@
namespace UnicaenAuth\Options;

use Interop\Container\ContainerInterface;
use Assert\Assertion;
use Assert\AssertionFailedException;
use UnicaenApp\Exception\RuntimeException;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

@@ -24,6 +27,42 @@ class ModuleOptionsFactory implements FactoryInterface
        $moduleConfig = isset($config['unicaen-auth']) ? $config['unicaen-auth'] : [];
        $moduleConfig = array_merge($config['zfcuser'], $moduleConfig);

        $this->validateConfig($moduleConfig);

        return new ModuleOptions($moduleConfig);
    }

    /**
     * @param array $config
     */
    private function validateConfig(array $config)
    {
        $configKeyPath = ['unicaen-auth'];

        //
        // Config shibboleth.
        //
        $parentKey = 'shibboleth';
        if (array_key_exists($parentKey, $config)) {
            $shibConfig = $config[$parentKey];
            $configKeyPath[] = $parentKey;

            try {
                Assertion::keyExists($shibConfig, $k = 'logout_url');
            } catch (AssertionFailedException $e) {
                throw new RuntimeException(sprintf(
                    "La clé de configuration '%s.$k' est absente (inspirez-vous du fichier de config " .
                    "unicaen-auth.global.php.dist du module unicaen/auth si besoin)",
                    join('.', $configKeyPath)
                ));
            }

            array_pop($configKeyPath);
        }

        //
        // Autres.
        //

    }
}
 No newline at end of file
+30 −3
Original line number Diff line number Diff line
@@ -85,12 +85,27 @@ EOS;
            // ENSUITE activation éventuelle de l'usurpation
            $this->handleUsurpation();

            if (! $this->isAuthenticated()) {
                return null;
            }

            $this->authenticatedUser = $this->createShibUserFromServerArrayData();
        }

        return $this->authenticatedUser;
    }

    /**
     * @return bool
     */
    private function isAuthenticated()
    {
        return
            $this->getServerArrayVariable('REMOTE_USER') ||
            $this->getServerArrayVariable('Shib-Session-ID') ||
            $this->getServerArrayVariable('HTTP_SHIB_SESSION_ID');
    }

    /**
     * @return boolean
     */
@@ -351,6 +366,9 @@ EOS;
     */
    public function simulateAuthenticatedUser(ShibUser $shibUser, $keyForId = 'supannEmpId')
    {
        // 'REMOTE_USER' (notamment) est utilisé pour savoir si un utilisateur est authentifié ou non
        $this->setServerArrayVariable('REMOTE_USER', $shibUser->getEppn());

//        // on s'assure que tous les attributs obligatoires ont une valeur
//        foreach ($this->getShibbolethRequiredAttributes() as $requiredAttribute) {
//            // un pipe permet d'exprimer un OU logique, ex: 'supannEmpId|supannEtuId'
@@ -419,13 +437,22 @@ EOS;
            return '/';
        }

        $logoutRelativeUrl = '/Shibboleth.sso/Logout?return='; // NB: '?return=' semble obligatoire!
        $logoutUrl = $this->shibbolethConfig['logout_url'];

        if ($returnAbsoluteUrl) {
            $logoutRelativeUrl .= urlencode($returnAbsoluteUrl);
            $logoutUrl .= urlencode($returnAbsoluteUrl);
        }

        return $logoutRelativeUrl;
        return $logoutUrl;

//        A supprimer si ce code est obsolète (doutes suite merge master => branche ZF3.
//        $logoutRelativeUrl = '/Shibboleth.sso/Logout?return='; // NB: '?return=' semble obligatoire!
//
//        if ($returnAbsoluteUrl) {
//            $logoutRelativeUrl .= urlencode($returnAbsoluteUrl);
//        }
//
//        return $logoutRelativeUrl;
    }

    /**
Loading