2010-03-10 19:49:04 +01:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
|
|
|
* http://ldapsaisie.labs.libre-entreprise.org
|
|
|
|
*
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2010-11-24 19:12:21 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-03-10 19:49:04 +01:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-11-24 19:12:21 +01:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
2010-03-10 19:49:04 +01:00
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
2010-11-24 19:12:21 +01:00
|
|
|
* CAS Authentication provider for LSauth
|
2010-03-10 19:49:04 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
2010-11-24 19:12:21 +01:00
|
|
|
class LSauthMethod_CAS extends LSauthMethod {
|
|
|
|
|
2019-03-12 11:42:53 +01:00
|
|
|
public function __construct() {
|
2010-11-24 19:12:21 +01:00
|
|
|
LSauth :: disableLoginForm();
|
|
|
|
|
2019-03-12 13:10:24 +01:00
|
|
|
if (!parent :: __construct())
|
2010-11-24 19:12:21 +01:00
|
|
|
return;
|
2010-03-10 19:49:04 +01:00
|
|
|
|
|
|
|
if (LSsession :: includeFile(PHP_CAS_PATH)) {
|
|
|
|
if (defined('PHP_CAS_DEBUG_FILE')) {
|
|
|
|
phpCAS::setDebug(PHP_CAS_DEBUG_FILE);
|
|
|
|
}
|
|
|
|
phpCAS::client(constant(LSAUTH_CAS_VERSION),LSAUTH_CAS_SERVER_HOSTNAME,LSAUTH_CAS_SERVER_PORT,LSAUTH_CAS_SERVER_URI,false);
|
|
|
|
if (LSAUTH_CAS_SERVER_NO_SSL_VALIDATION) {
|
|
|
|
phpCAS::setNoCasServerValidation();
|
|
|
|
}
|
|
|
|
|
2012-03-29 18:32:13 +02:00
|
|
|
if (defined('LSAUTH_CAS_SERVER_SSL_CERT')) {
|
2010-03-10 19:49:04 +01:00
|
|
|
phpCAS::setCasServerCert(LSAUTH_CAS_SERVER_SSL_CERT);
|
|
|
|
}
|
|
|
|
|
2012-03-29 18:32:13 +02:00
|
|
|
if (defined('LSAUTH_CAS_SERVER_SSL_CACERT')) {
|
2010-03-10 19:49:04 +01:00
|
|
|
phpCAS::setCasServerCACert(LSAUTH_CAS_SERVER_SSL_CACERT);
|
|
|
|
}
|
|
|
|
|
2012-03-29 18:33:12 +02:00
|
|
|
if (defined('LSAUTH_CAS_CURL_SSLVERION')) {
|
|
|
|
phpCAS::setExtraCurlOption(CURLOPT_SSLVERSION,LSAUTH_CAS_CURL_SSLVERION);
|
|
|
|
}
|
|
|
|
|
2010-03-10 19:49:04 +01:00
|
|
|
if (LSAUTH_CAS_DISABLE_LOGOUT) {
|
2010-11-24 19:12:21 +01:00
|
|
|
LSauth :: disableLogoutBtn();
|
2010-03-10 19:49:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
2010-11-24 19:12:21 +01:00
|
|
|
LSerror :: addErrorCode('LSauthMethod_CAS_01');
|
2010-03-10 19:49:04 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-24 19:12:21 +01:00
|
|
|
/**
|
|
|
|
* Check Auth Data
|
|
|
|
*
|
|
|
|
* Return authentication data or false
|
|
|
|
*
|
|
|
|
* @retval Array|false Array of authentication data or False
|
|
|
|
**/
|
|
|
|
public function getAuthData() {
|
|
|
|
|
2010-03-10 19:49:04 +01:00
|
|
|
if (class_exists('phpCAS')) {
|
2010-11-24 19:12:21 +01:00
|
|
|
|
2010-03-10 19:49:04 +01:00
|
|
|
// Launch Auth
|
|
|
|
phpCAS::forceAuthentication();
|
|
|
|
|
|
|
|
$this -> authData = array(
|
2010-11-24 19:12:21 +01:00
|
|
|
'username' => phpCAS::getUser()
|
2010-03-10 19:49:04 +01:00
|
|
|
);
|
2010-11-24 19:12:21 +01:00
|
|
|
return $this -> authData;
|
2010-03-10 19:49:04 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-24 19:12:21 +01:00
|
|
|
/**
|
|
|
|
* Logout
|
|
|
|
*
|
|
|
|
* @retval boolean True on success or False
|
|
|
|
**/
|
2010-03-10 19:49:04 +01:00
|
|
|
public function logout() {
|
|
|
|
if(class_exists('phpCAS')) {
|
2010-11-24 19:12:21 +01:00
|
|
|
if (LSauth :: displayLogoutBtn()) {
|
2010-03-10 19:49:04 +01:00
|
|
|
phpCAS :: forceAuthentication();
|
|
|
|
phpCAS :: logout();
|
2010-11-24 19:12:21 +01:00
|
|
|
return true;
|
2010-03-10 19:49:04 +01:00
|
|
|
}
|
|
|
|
}
|
2010-11-24 19:12:21 +01:00
|
|
|
return;
|
2010-03-10 19:49:04 +01:00
|
|
|
}
|
2010-11-24 19:12:21 +01:00
|
|
|
|
2010-03-10 19:49:04 +01:00
|
|
|
}
|
2019-03-11 22:42:20 +01:00
|
|
|
|
2010-03-10 19:49:04 +01:00
|
|
|
/*
|
|
|
|
* Error Codes
|
|
|
|
*/
|
2010-11-24 19:12:21 +01:00
|
|
|
LSerror :: defineError('LSauthMethod_CAS_01',
|
|
|
|
_("LSauthMethod_CAS : Failed to load phpCAS.")
|
2010-03-10 19:49:04 +01:00
|
|
|
);
|
2019-03-11 22:42:20 +01:00
|
|
|
|