function authCAS($config) { require_once dirname(__FILE__) . '/CAS/CAS.php'; // get module configuration $cas_validate = true; $cas_version = CAS_VERSION_2_0; $cas_language = 'english'; // phpCAS::setDebug(); phpCAS::client($cas_version, $config->cashostname, (int) $config->casport, $config->casbaseuri, false); phpCAS::setLang($cas_language); error_log("CAS: Entering"); $check = phpCAS::isSessionAuthenticated(); phpCAS::forceAuthentication(); $NetUsername = phpCAS::getUser(); //this stores their network user id error_log("CAS: Exiting {$NetUsername}"); return $NetUsername; }
} // //////////////////////////////////////////////////////////////////////////////////////////////////// // Déconnexion avec le protocole CAS // //////////////////////////////////////////////////////////////////////////////////////////////////// if ($connexion_mode == 'cas') { // Pour tester, cette méthode statique créé un fichier de log sur ce qui se passe avec CAS if (DEBUG_PHPCAS) { if (HEBERGEUR_INSTALLATION == 'mono-structure' || !PHPCAS_ETABL_ID_LISTING || strpos(PHPCAS_ETABL_ID_LISTING, ',' . $BASE . ',') !== FALSE) { $fichier_nom_debut = 'debugcas_' . $BASE; $fichier_nom_fin = fabriquer_fin_nom_fichier__pseudo_alea($fichier_nom_debut); phpCAS::setDebug(PHPCAS_CHEMIN_LOGS . $fichier_nom_debut . '_' . $fichier_nom_fin . '.txt'); } } // Initialiser la connexion avec CAS ; le premier argument est la version du protocole CAS ; le dernier argument indique qu'on utilise la session existante phpCAS::client(CAS_VERSION_2_0, $cas_serveur_host, (int) $cas_serveur_port, $cas_serveur_root, FALSE); phpCAS::setLang(PHPCAS_LANG_FRENCH); // Surcharge éventuelle des URL if ($cas_serveur_url_login) { phpCAS::setServerLoginURL($cas_serveur_url_login); } if ($cas_serveur_url_logout) { phpCAS::setServerLogoutURL($cas_serveur_url_logout); } if ($cas_serveur_url_validate) { phpCAS::setServerServiceValidateURL($cas_serveur_url_validate); } // Suite à des attaques DDOS, Kosmos a décidé en avril 2015 de filtrer les requêtes en bloquant toutes celles sans User-Agent. // C'est idiot car cette valeur n'est pas fiable, n'importe qui peut présenter n'importe quel User-Agent ! // En attendant qu'ils appliquent un remède plus intelligent, et au cas où un autre prestataire aurait la même mauvaise idée, on envoie un User-Agent bidon (défini dans le loader)... phpCAS::setExtraCurlOption(CURLOPT_USERAGENT, CURL_AGENT); // Appliquer un proxy si défini par le webmestre ; voir cURL::get_contents() pour les commentaires.
/** * Authentication choice (CAS or other) * Redirection to the CAS form or to login/index.php * for other authentication */ function loginpage_hook() { global $frm; global $CFG; global $SESSION, $OUTPUT, $PAGE; $site = get_site(); $CASform = get_string('CASform', 'auth_cas'); $username = optional_param('username', '', PARAM_RAW); $courseid = optional_param('courseid', 0, PARAM_INT); if (!empty($username)) { if (isset($SESSION->wantsurl) && (strstr($SESSION->wantsurl, 'ticket') || strstr($SESSION->wantsurl, 'NOCAS'))) { unset($SESSION->wantsurl); } return; } // Return if CAS enabled and settings not specified yet if (empty($this->config->hostname)) { return; } // If the multi-authentication setting is used, check for the param before connecting to CAS. if ($this->config->multiauth) { // If there is an authentication error, stay on the default authentication page. if (!empty($SESSION->loginerrormsg)) { return; } $authCAS = optional_param('authCAS', '', PARAM_RAW); if ($authCAS == 'NOCAS') { return; } // Show authentication form for multi-authentication. // Test pgtIou parameter for proxy mode (https connection in background from CAS server to the php server). if ($authCAS != 'CAS' && !isset($_GET['pgtIou'])) { $PAGE->set_url('/login/index.php'); $PAGE->navbar->add($CASform); $PAGE->set_title("{$site->fullname}: {$CASform}"); $PAGE->set_heading($site->fullname); echo $OUTPUT->header(); include $CFG->dirroot . '/auth/cas/cas_form.html'; echo $OUTPUT->footer(); exit; } } // Connection to CAS server $this->connectCAS(); if (phpCAS::checkAuthentication()) { $frm = new stdClass(); $frm->username = phpCAS::getUser(); $frm->password = '******'; // Redirect to a course if multi-auth is activated, authCAS is set to CAS and the courseid is specified. if ($this->config->multiauth && !empty($courseid)) { redirect(new moodle_url('/course/view.php', array('id' => $courseid))); } return; } if (isset($_GET['loginguest']) && $_GET['loginguest'] == true) { $frm = new stdClass(); $frm->username = '******'; $frm->password = '******'; return; } // Force CAS authentication (if needed). if (!phpCAS::isAuthenticated()) { phpCAS::setLang($this->config->language); phpCAS::forceAuthentication(); } }
/** * Authentication choice (CAS or other) * Redirection to the CAS form or to login/index.php * for other authentication */ function loginpage_hook() { global $frm; global $CFG; global $SESSION, $OUTPUT, $PAGE; $site = get_site(); $CASform = get_string('CASform', 'auth_cas'); $username = optional_param('username', '', PARAM_RAW); if (!empty($username)) { if (isset($SESSION->wantsurl) && (strstr($SESSION->wantsurl, 'ticket') || strstr($SESSION->wantsurl, 'NOCAS'))) { unset($SESSION->wantsurl); } return; } // Return if CAS enabled and settings not specified yet if (empty($this->config->hostname)) { return; } // Connection to CAS server $this->connectCAS(); if (phpCAS::checkAuthentication()) { $frm = new stdClass(); $frm->username = phpCAS::getUser(); $frm->password = '******'; return; } if (isset($_GET['loginguest']) && $_GET['loginguest'] == true) { $frm = new stdClass(); $frm->username = '******'; $frm->password = '******'; return; } if ($this->config->multiauth) { $authCAS = optional_param('authCAS', '', PARAM_RAW); if ($authCAS == 'NOCAS') { return; } // Show authentication form for multi-authentication // test pgtIou parameter for proxy mode (https connection // in background from CAS server to the php server) if ($authCAS != 'CAS' && !isset($_GET['pgtIou'])) { $PAGE->set_url('/login/index.php'); $PAGE->navbar->add($CASform); $PAGE->set_title("{$site->fullname}: {$CASform}"); $PAGE->set_heading($site->fullname); echo $OUTPUT->header(); include $CFG->dirroot . '/auth/cas/cas_form.html'; echo $OUTPUT->footer(); exit; } } // Force CAS authentication (if needed). if (!phpCAS::isAuthenticated()) { phpCAS::setLang($this->config->language); phpCAS::forceAuthentication(); } }
public function logout_cas() { include_once('CAS.php'); // config_cas.inc.php est le fichier d'informations de connexions au serveur cas $path = dirname(__FILE__)."/../secure/config_cas.inc.php"; include($path); // Le premier argument est la version du protocole CAS phpCAS::client(CAS_VERSION_2_0,$cas_host,$cas_port,$cas_root,''); phpCAS::setLang(PHPCAS_LANG_FRENCH); if ($cas_use_logout) { phpCAS::logout(); }else{ if ($cas_logout_url != '') { header("Location:".$cas_logout_url); exit(); }else{ // Il faudra trouver mieux echo '<html><head><title>GEPI</title></head><body><h2>Vous êtes déconnecté.</h2></body></html>'; exit(); } } // redirige vers le serveur d'authentification si aucun utilisateur authentifié n'a // été trouvé par le client CAS. //phpCAS::setNoCasServerValidation(); //phpCAS::forceAuthentication(); //$this->login = phpCAS::getUser(); // On réinitialise la session //session_name("GEPI"); //session_start(); //$_SESSION['login'] = $this->login; //$this->current_auth_mode = "sso"; return true; }
function logout_cas() { include_once('CAS.php'); // config_cas.inc.php est le fichier d'informations de connexions au serveur cas $path = dirname(__FILE__)."/../secure/config_cas.inc.php"; include($path); // Le premier argument est la version du protocole CAS phpCAS::client(CAS_VERSION_2_0,$cas_host,$cas_port,$cas_root,''); phpCAS::setLang('french'); phpCAS::logout(); // redirige vers le serveur d'authentification si aucun utilisateur authentifié n'a // été trouvé par le client CAS. //phpCAS::setNoCasServerValidation(); //phpCAS::forceAuthentication(); //$this->login = phpCAS::getUser(); // On réinitialise la session //session_name("GEPI"); //session_start(); //$_SESSION['login'] = $this->login; //$this->current_auth_mode = "sso"; return true; }
* You should have received a copy of the GNU General Public License * along with GRR; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // Le package phpCAS doit etre stocké dans un sous-répertoire « CAS » // dans un répertoire correspondant a l'include_path du php.ini (exemple : /var/lib/php) include_once 'CAS/CAS.php'; // cas.sso est le fichier d'informations de connexions au serveur cas // Le fichier cas.sso doit etre stocké dans un sous-répertoire « CAS » // dans un répertoire correspondant a l'include_path du php.ini (exemple : /var/lib/php) include 'CAS/cas.sso'; /* declare le script comme un client CAS Si le dernier argument est à true, cela donne la possibilité à phpCAS d'ouvrir une session php. */ phpCAS::client(CAS_VERSION_2_0, $serveurSSO, $serveurSSOPort, $serveurSSORacine, true); phpCAS::setLang('french'); //Set the fixed URL that will be set as the CAS service parameter. When this method is not called, a phpCAS script uses its own URL. //Le paramètre $Url_CAS_setFixedServiceURL est défini dans le fichier config.inc.php if (isset($Url_CAS_setFixedServiceURL) && $Url_CAS_setFixedServiceURL != '') { phpCAS::setFixedServiceURL($Url_CAS_setFixedServiceURL); } /* Commentez la ligne suivante si vous avez une erreur du type PHP Fatal error: Call to undefined method phpCAS::setnocasservervalidation() in /var/www/html/grr/include/cas.inc.php Nécessite une version de phpCAS supérieure ou égale à 1.0.0. */ phpCAS::setNoCasServerValidation(); /* Gestion du single sign-out (version 1.0.0 de phpcas) Commentez la ligne suivante si vous avez une erreur du type PHP Fatal error: Call to undefined method phpCAS::handlelogoutrequests() in /var/www/html/grr/include/cas.inc.php