From 66c59cdd0cb336201dbec1520356ac7b727b5b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Mon, 29 Apr 2013 09:09:55 +0200 Subject: [PATCH] Begin simplesmal impletation * saml_options.php: load simplesamlphp * balise/login_saml.php: begin support of login, logout and attributes sync * plugin.xml: spip plugin definitions --- balise/login_saml.php | 93 +++++++++++++++++++++++++++++++++++++++++++ plugin.xml | 22 ++++++++++ saml_options.php | 8 ++++ 3 files changed, 123 insertions(+) create mode 100644 balise/login_saml.php create mode 100644 plugin.xml create mode 100644 saml_options.php diff --git a/balise/login_saml.php b/balise/login_saml.php new file mode 100644 index 0000000..0f44d8d --- /dev/null +++ b/balise/login_saml.php @@ -0,0 +1,93 @@ +isAuthenticated()) { + $url = lire_config('saml/login_url'); + spip_log("[auth_shib] login url =".$url); + + // Appeler le squelette du formulaire de login + return array('formulaires/saml', + $GLOBALS['delais'],array('saml_url' => $url)); + } + else return login_saml_successfull(); +} + +function login_saml_successfull() +{ + + global $simplesaml; + + spip_log("[auth_saml] Traitement login SAML"); + + $attributes = $simplesaml->getAttributes(); + $login = $attributes['uid'][0]; + $first_name = $attributes['gn'][0]; + $last_name = $attributes['sn'][0]; + $email = $attributes['email'][0]; + $given_name = $first_name . ' ' . $last_name; + + spip_log("[auth_saml] authentification reussi pour l'utilisateur =".$login); + + // Si l'utilisateur figure deja dans la base, y recuperer les infos + $result = spip_query("SELECT * FROM spip_auteurs WHERE login=" ._q($login). " AND statut<>'5poubelle'" ); + $row_auteur = spip_fetch_array($result); + + spip_log("[auth_saml] attribus utilisateur =".$row_auteur['login']); + + if ($row_auteur) { + $GLOBALS['auteur_session'] = $row_auteur; + + spip_log("[auth_saml] updating user [" . $login . "] attributes : ".\ + $given_name); + spip_query("UPDATE spip_auteurs SET nom=" . \ + _q($display_name) . \ + ", email=" . _q($email) . \ + " WHERE login="._q($login)); + + $session = charger_fonction('session', 'inc'); + $cookie_session = $session($row_auteur); + spip_setcookie('spip_session', $cookie_session); + $redirect = _DIR_RESTREINT_ABS. "?bonjour=oui"; + redirige_par_entete($redirect); + } + else + { + // Logout SAML au cas ou + $simplesaml->logout(); + } +} + +?> diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..83e1df6 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,22 @@ + + SPIPSaml + [Jérôme Schneider->jschneider@entrouvert.org] + 0.1 + experimental + + + [en]SAML plugin providing Shibboleth authentication. + [fr]plugin SPIP fournissant une authentification SAML. + + + + [http://repos.entrouvert.org/spip-saml.git->http://repos.entrouvert.org/spip-saml.git] + + saml_options.php + + saml + + ajouter_boutons + shib_pipelines_private.php + + diff --git a/saml_options.php b/saml_options.php new file mode 100644 index 0000000..41ec047 --- /dev/null +++ b/saml_options.php @@ -0,0 +1,8 @@ +