diff --git a/config/unicaen-auth.global.php.dist b/config/unicaen-auth.global.php.dist index 4a939cbc4128ff1563dec701e2a825cdf663a36c..60918a2a7b091517f00140b501413de9c7dd1654 100644 --- a/config/unicaen-auth.global.php.dist +++ b/config/unicaen-auth.global.php.dist @@ -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. diff --git a/src/UnicaenAuth/Options/ModuleOptionsFactory.php b/src/UnicaenAuth/Options/ModuleOptionsFactory.php index dd7e1a86c125d6e118c294a924c61435fb0f7946..a07434a1f0e92149c63c647556f5429f2da02e03 100644 --- a/src/UnicaenAuth/Options/ModuleOptionsFactory.php +++ b/src/UnicaenAuth/Options/ModuleOptionsFactory.php @@ -2,6 +2,9 @@ namespace UnicaenAuth\Options; +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 diff --git a/src/UnicaenAuth/Service/ShibService.php b/src/UnicaenAuth/Service/ShibService.php index 7d9d488113df0d6d87304812fcd6f387711c10f8..40899029b509a6e4d4c3578fa4c05e7801da139a 100644 --- a/src/UnicaenAuth/Service/ShibService.php +++ b/src/UnicaenAuth/Service/ShibService.php @@ -100,7 +100,10 @@ EOS; */ private function isAuthenticated() { - return (bool) $this->getServerArrayVariable('REMOTE_USER'); + return + $this->getServerArrayVariable('REMOTE_USER') || + $this->getServerArrayVariable('Shib-Session-ID') || + $this->getServerArrayVariable('HTTP_SHIB_SESSION_ID'); } /** @@ -363,7 +366,7 @@ EOS; */ public function simulateAuthenticatedUser(ShibUser $shibUser, $keyForId = 'supannEmpId') { - // 'REMOTE_USER' est utilisé pour savoir si un utilisateur est authentifié ou non + // '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 @@ -434,13 +437,13 @@ 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; } /**