diff --git a/app/inc/init.php b/app/inc/init.php index ed973be..9d18ec2 100644 --- a/app/inc/init.php +++ b/app/inc/init.php @@ -89,3 +89,6 @@ if (is_file(CONF_FILENAME)) { require_once __DIR__ . '/i18n.php'; // Smarty require_once __DIR__ . '/smarty.php'; + +// SAML +require_once __DIR__ . '/saml.php'; diff --git a/app/inc/saml.php b/app/inc/saml.php new file mode 100644 index 0000000..7bb286d --- /dev/null +++ b/app/inc/saml.php @@ -0,0 +1,116 @@ + array( + 'create_poll' => true, // Front - Création d'un sondage + 'find_polls' => true, // Front - Ou sont mes sondages + 'studs' => false, // Front - Réponse à un sondage + 'adminstuds' => true, // Front - Edition d'un sondage + 'exportcsv' => false, // Front - export CSV d'un sondage + ), + + 'admin' => array( + 'admin/index' => true, // Administration - Accueil + 'admin/polls' => true, // Administration - Sondages + 'admin/purge' => true, // Administration - Purge + 'admin/logs' => true, // Administration - Historique + 'admin/migration' => true, // Administration - Migration + 'admin/check' => true, // Administration - Vérifications de l'installation + ) +); + +/** + * Champs de l'AD à mapper avec SAML + */ +$hashConfigFieldsMapping = array( + 'name' => 'cn', // Nom complet + 'email' => 'mail' // Adresse mail +); + +/** + * Attributs de l'AD qui sont authorisés à se connecter aux différentes parties de Framadate + */ +$hashGroupAuthorized = array( + 'front' => array( + 'resMemberOf' => 'Framadate', // Valeurs à remplacer + ), + 'admin' => array( + 'resMemberOf' => 'FramadateAdmin' // Valeurs à remplacer + ) +); + +if(SAML_SSO_ACTIVE == true){ + + if(!file_exists(SAML_PATH)){ + die('Impossible de charger la librairie SimplePHPSAML'); + } + require_once(SAML_PATH); + + //On parcourt les pages des sections (front / back) + foreach($hashPagesToSecure as $strSection => $hashPages){ + + // On vérifie si la page courante doit-être sécurisée + foreach($hashPages as $strPageName => $boolSecure){ + + // SI page courante doit-être sécurisé on vérifie l'accès + if(strpos($_SERVER['SCRIPT_FILENAME'], $strPageName) !== false && $boolSecure == true){ + $objAuthSaml = new SimpleSAML_Auth_Simple('framadate-sp'); + $objAuthSaml->requireAuth(); + + $hashAuthAttributes = $objAuthSaml->getAttributes(); + + // On récupère le nom et l'email de l'utilisateur + $strUserName = array_shift($hashAuthAttributes[$hashConfigFieldsMapping['name']]); + $strUserEmail = array_shift($hashAuthAttributes[$hashConfigFieldsMapping['email']]); + + // On assigne à Smarty l'URL de déconnexion + l'adresse email pour retrouver les sondages + $strHttpPrepfix = (substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https')? 'https' : 'http'; + $smarty->assign('saml_logout', $objAuthSaml->getLogoutURL($strHttpPrepfix.'://'.$_SERVER['HTTP_HOST'])); + $smarty->assign('email', $strUserEmail); + + // Si on est dans la section (front / back), on regarde si l'utilisateur est bien autorisé + if(isset($hashGroupAuthorized[$strSection])) { + foreach ($hashGroupAuthorized[$strSection] as $strAttribute => $strValue) { + if (!in_array(trim($strValue), $hashAuthAttributes[$strAttribute])) { + header('Location:'.$strHttpPrepfix.'://'.$_SERVER['HTTP_HOST'].'/forbidden.php'); + break; + } + } + } + + // Si il s'agit d'un nouveau sondage on affecte les infos du user en session + if(strpos($_SERVER['SCRIPT_FILENAME'], 'create_poll') !== FALSE && AUTO_COMPLETE_USER == true){ + if(isset($_SESSION['form']) && empty($_SESSION['form']->id)){ + $_SESSION['form']->admin_name = $strUserName; + $_SESSION['form']->admin_mail = $strUserEmail; + } + } + break; + } + } + } +} \ No newline at end of file diff --git a/forbidden.php b/forbidden.php new file mode 100644 index 0000000..8e3aa46 --- /dev/null +++ b/forbidden.php @@ -0,0 +1,30 @@ +display('forbidden.tpl'); diff --git a/locale/en.json b/locale/en.json index 39a6c97..797850d 100644 --- a/locale/en.json +++ b/locale/en.json @@ -203,6 +203,7 @@ "Date": "Date", "Day": "Day", "Description": "Description", + "Disconnect": "Disconnect", "Edit": "Edit", "Framadate is an online service for planning an appointment or make a decision quickly and easily.": "Framadate is an online service for planning an appointment or make a decision quickly and easily.", "Home": "Home", diff --git a/tpl/forbidden.tpl b/tpl/forbidden.tpl new file mode 100644 index 0000000..ad5ddf8 --- /dev/null +++ b/tpl/forbidden.tpl @@ -0,0 +1,12 @@ +{extends file='page.tpl'} + +{block name=main} + + + Retour à l'accueil + +{/block} diff --git a/tpl/header.tpl b/tpl/header.tpl index 5f68c92..ddf9bbb 100644 --- a/tpl/header.tpl +++ b/tpl/header.tpl @@ -20,6 +20,12 @@ {if !empty($title)}

{$title|html}

{/if} + + {if $saml_logout} + {__('Generic', 'Disconnect')} + {/if} + + -
+
\ No newline at end of file