Merge remote-tracking branch 'saml/master' into saml

This commit is contained in:
Thomas Citharel 2018-07-06 16:05:11 +02:00
commit 037198786c
6 changed files with 169 additions and 1 deletions

View file

@ -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';

116
app/inc/saml.php Normal file
View file

@ -0,0 +1,116 @@
<?php
/**
* Fichier de configuration pour l'authentification de Framadate avec SimpleSAMLPHP
* Il est indispensable d'avoir configuré un Service Provider au préalable
*
*/
/**
* Chemin de la libraire PHPSimpleSAML
*/
const SAML_PATH = '/home/framadate/www/simplesamlphp/lib/_autoload.php';
/**
* Active la connexion SSO
*/
const SAML_SSO_ACTIVE = true;
/**
* Prérempli les coordonées (nom / email) dans le formulaire de création d'un sondage
*/
const AUTO_COMPLETE_USER = true;
/**
* Lise des pages que l'on veut sécuriser
*/
$hashPagesToSecure = array(
'front' => 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;
}
}
}
}

30
forbidden.php Normal file
View file

@ -0,0 +1,30 @@
<?php
/**
* This software is governed by the CeCILL-B license. If a copy of this license
* is not distributed with this file, you can obtain one at
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
*
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
*
* =============================
*
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
*
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
use Framadate\Utils;
include_once __DIR__ . '/app/inc/init.php';
if (!is_file(CONF_FILENAME)) {
header(('Location: ' . Utils::get_server_name() . 'admin/check.php'));
exit;
}
$smarty->display('forbidden.tpl');

View file

@ -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",

12
tpl/forbidden.tpl Normal file
View file

@ -0,0 +1,12 @@
{extends file='page.tpl'}
{block name=main}
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Problème d'accès :</span>
C'est embarassant... Il semblerait pour que vous n'ayez pas le droit d'accéder à cette partie... Pour plus d'informations, veuillez contacter votre administrateur.
</div>
<a href="/"><span class="glyphicon glyphicon-arrow-left aria-hidden="true"></span> Retour à l'accueil</a>
{/block}

View file

@ -20,6 +20,12 @@
</a>
</h1>
{if !empty($title)}<h2 class="lead col-xs-12"><i>{$title|html}</i></h2>{/if}
{if $saml_logout}
<a href="{$saml_logout}" class="pull-right" style="margin-top: -60px;"><span class="glyphicon glyphicon-log-out"></span> {__('Generic', 'Disconnect')}</a>
{/if}
<div class="trait col-xs-12" role="presentation"></div>
</header>
<main role="main">
<main role="main">