From b2029163f222e04dd5ee50712c49627031004135 Mon Sep 17 00:00:00 2001 From: Laurent Giovannoni <laurent.giovannoni@maarch.org> Date: Mon, 22 Oct 2018 17:09:08 +0200 Subject: [PATCH] shibboleth integration --- apps/maarch_entreprise/shibbolethConnect.php | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 apps/maarch_entreprise/shibbolethConnect.php diff --git a/apps/maarch_entreprise/shibbolethConnect.php b/apps/maarch_entreprise/shibbolethConnect.php new file mode 100644 index 00000000000..1f50dc59c5b --- /dev/null +++ b/apps/maarch_entreprise/shibbolethConnect.php @@ -0,0 +1,56 @@ +<?php + +//require 'vendor/autoload.php'; +//$shibbolethConfig = \SrcCore\models\CoreConfigModel::getShibbolethConfiguration(); + +//test if no shibboleth authentication +//$_SERVER['REMOTE_USER'] = ''; +//test if user doesn't exists +//$_SERVER['REMOTE_USER'] = 'aUserTest'; + +if ($_SERVER['REMOTE_USER'] <> '' && $_SERVER['AUTH_TYPE'] = 'shibboleth') { + $login = $_SERVER['REMOTE_USER']; + $password = 'aFakePass'; + + require_once('core/class/class_core_tools.php'); + require_once 'core/class/class_security.php'; + require_once 'core/class/class_db_pdo.php'; + $core = new core_tools(); + $sec = new security(); + + $database = new Database(); + $stmt = $database->query("SELECT * FROM users WHERE user_id ILIKE ?", array($login)); + $result = $stmt->fetch(); + + if ($result) { + $_SESSION['error'] = ''; + + $res = $sec->login($login, $password, 'shibboleth'); + + $_SESSION['user'] = $res['user']; + + if (empty($_SESSION['error'])) { + $_SESSION['error'] = $res['error']; + } + + if ($res['error'] == '') { + \SrcCore\models\SecurityModel::setCookieAuth(['userId' => $login]); + $core->load_menu($_SESSION['modules']); + //login OK + $trace = new history(); + header('location: ' . $_SESSION['config']['businessappurl']. $res['url']); + exit(); + } else { + $_SESSION['error'] = $res['error']; + echo $_SESSION['error']; + exit; + } + } else { + $_SESSION['error'] = _USER_NOT_EXIST . ' ' . $login; + echo $_SESSION['error']; + exit; + } +} else { + //redirect to shibboleth authentication ? + //header('location: ' . $shibbolethConfig['shibbolethUri'] ); +} -- GitLab