/** * Initialize the class, this must be called before anything else * @param $config * @param bool $changeSessionID Allow phpCAS to change the session_id (Single Sign Out/handleLogoutRequests is based on that change) * @param $debugLog Set to a path to enable debug log */ public static function init($config, $changeSessionID = true, $debugLog = null) { if ($debugLog != null) { phpCAS::setDebug($debugLog); } phpCAS::client(CAS_VERSION_2_0, $config['site'], $config['port'], "cas", $changeSessionID); self::$config = $config; $private_key = null; if (isset($config['private_key'])) { $key = static::resolve_filename($config['private_key']); $private_key = openssl_get_privatekey("file:///{$key}"); if ($private_key === false) { throw new NXAuthError("Failed to open private key {$key}"); } } if (isset($config['ca_cert']) && $config['ca_cert'] != null) { self::$ca_cert = static::resolve_filename($config['ca_cert']); phpCAS::setCasServerCACert(self::$ca_cert); } else { phpCAS::setNoCasServerValidation(); // Disable curl ssl verification phpCAS::setExtraCurlOption(CURLOPT_SSL_VERIFYHOST, 0); phpCAS::setExtraCurlOption(CURLOPT_SSL_VERIFYPEER, 0); } NXAPI::init(array('private_key' => $private_key, 'key_id' => $config['key_id'], 'url' => "https://" . $config['site'], 'ca_cert' => self::$ca_cert)); }
} 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. if (defined('SERVEUR_PROXY_USED') && SERVEUR_PROXY_USED) { phpCAS::setExtraCurlOption(CURLOPT_PROXY, SERVEUR_PROXY_NAME); phpCAS::setExtraCurlOption(CURLOPT_PROXYPORT, (int) SERVEUR_PROXY_PORT); phpCAS::setExtraCurlOption(CURLOPT_PROXYTYPE, constant(SERVEUR_PROXY_TYPE)); if (SERVEUR_PROXY_AUTH_USED) { phpCAS::setExtraCurlOption(CURLOPT_PROXYAUTH, constant(SERVEUR_PROXY_AUTH_METHOD)); phpCAS::setExtraCurlOption(CURLOPT_PROXYUSERPWD, SERVEUR_PROXY_AUTH_USER . ':' . SERVEUR_PROXY_AUTH_PASS); } } // On indique qu'il faut vérifier la validité du certificat SSL, sauf exception paramétrée, mais alors dans ce cas ça ne sert à rien d'utiliser une connexion sécurisée. if (strpos(PHPCAS_NO_CERTIF_LISTING, ',' . $connexion_nom . ',') === FALSE) { phpCAS::setCasServerCACert(CHEMIN_FICHIER_CA_CERTS_FILE); } else { phpCAS::setNoCasServerValidation(); } // Gestion du single sign-out phpCAS::handleLogoutRequests(FALSE); // Déconnexion de CAS phpCAS::logout(); exit; } // ////////////////////////////////////////////////////////////////////////////////////////////////////
/** * Connect to the CAS (clientcas connection or proxycas connection) * */ function connectCAS() { global $CFG; static $connected = false; if (!$connected) { // Make sure phpCAS doesn't try to start a new PHP session when connecting to the CAS server. if ($this->config->proxycas) { phpCAS::proxy($this->config->casversion, $this->config->hostname, (int) $this->config->port, $this->config->baseuri, false); } else { phpCAS::client($this->config->casversion, $this->config->hostname, (int) $this->config->port, $this->config->baseuri, false); } $connected = true; } // If Moodle is configured to use a proxy, phpCAS needs some curl options set. if (!empty($CFG->proxyhost) && !is_proxybypass($this->config->hostname)) { phpCAS::setExtraCurlOption(CURLOPT_PROXY, $CFG->proxyhost); if (!empty($CFG->proxyport)) { phpCAS::setExtraCurlOption(CURLOPT_PROXYPORT, $CFG->proxyport); } if (!empty($CFG->proxytype)) { // Only set CURLOPT_PROXYTYPE if it's something other than the curl-default http if ($CFG->proxytype == 'SOCKS5') { phpCAS::setExtraCurlOption(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); } } if (!empty($CFG->proxyuser) and !empty($CFG->proxypassword)) { phpCAS::setExtraCurlOption(CURLOPT_PROXYUSERPWD, $CFG->proxyuser . ':' . $CFG->proxypassword); if (defined('CURLOPT_PROXYAUTH')) { // any proxy authentication if PHP 5.1 phpCAS::setExtraCurlOption(CURLOPT_PROXYAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM); } } } if ($this->config->certificate_check && $this->config->certificate_path) { phpCAS::setCasServerCACert($this->config->certificate_path); } else { // Don't try to validate the server SSL credentials phpCAS::setNoCasServerValidation(); } }
* @category Authentication * @package PhpCAS * @author Joachim Fritschi <*****@*****.**> * @author Adam Franco <*****@*****.**> * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://wiki.jasig.org/display/CASC/phpCAS */ // Load the settings from the central config file require_once 'config.php'; // Load the CAS lib require_once $phpcas_path . '/CAS.php'; // Enable debugging phpCAS::setDebug(); // Initialize phpCAS phpCAS::client(CAS_VERSION_2_0, $cas_host, $cas_port, $cas_context); phpCAS::setExtraCurlOption(CURLOPT_SSLVERSION, 6); // For production use set the CA certificate that is the issuer of the cert // on the CAS server and uncomment the line below // phpCAS::setCasServerCACert($cas_server_ca_cert_path); // For quick testing you can disable SSL validation of the CAS server. // THIS SETTING IS NOT RECOMMENDED FOR PRODUCTION. // VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS PROTOCOL! phpCAS::setNoCasServerValidation(); // force CAS authentication phpCAS::forceAuthentication(); // at this step, the user has been authenticated by the CAS server // and the user's login name can be read with phpCAS::getUser(). // logout if desired if (isset($_REQUEST['logout'])) { phpCAS::logout(); }
/** * Set adapater state from options array * * @param array $options * @return Zend_Auth_Adapter_Cas */ public function setOptions(array $options) { $forbidden = array('Options', 'Config'); foreach ($options as $key => $value) { $normalized = ucfirst($key); if (in_array($normalized, $forbidden)) { continue; } $method = 'set' . $normalized; if (method_exists($this, $method)) { $this->{$method}($value); } } if (empty($this->getApiKey())) { throw new Exception("API Key not found"); } if (empty($this->getSecret())) { throw new Exception("API Secret not found"); } if (!phpCAS::isInitialized()) { phpCAS::client(CAS_VERSION_2_0, $this->getHostname(), $this->getPort(), $this->getPath()); phpCAS::setExtraCurlOption(CURLOPT_SSL_VERIFYHOST, false); phpCAS::setExtraCurlOption(CURLOPT_SSL_VERIFYPEER, false); } // Set the URL $url = $this->getUrl(); if (empty($url)) { $this->setUrl(); } // Set the service URL $service = $this->getService(); if (empty($service)) { $this->setService(); } // Set the login URL $loginUrl = $this->getLoginUrl(); if (empty($loginUrl)) { $this->setLoginUrl(); } // Set the logout URL $logoutUrl = $this->getLogoutUrl(); if (empty($logoutUrl)) { $this->setLogoutUrl(); } $this->configureCasValidation($options); return $this; }
protected function iniciar_pedido_cas() { $this->instanciar_cliente_cas(); phpCAS::setExtraCurlOption(CURLOPT_SSLVERSION, 3); // Se genera la URL de servicio $param = array(); if (isset($this->parametros_url) && is_array($this->parametros_url)) { $param = $this->parametros_url; } $url = $this->generar_url($param); phpCAS::setFixedServiceURL($url); // Tipo de auth if (toba::instalacion()->es_produccion()) { phpCAS::setCasServerCACert($this->archivo_certificado, $this->validar_cn); } else { phpCAS::setNoCasServerValidation(); } phpCAS::setServerLoginURL(''); /** Llamada principal al authentificación de CAS, si no estás autenticado te redirecciona ahí adentro y no sigue ejecutando Si pasa está función significa que estás autenticado **/ phpCAS::forceAuthentication(); }
$url_base = Session::https_request() ? 'https' : 'http'; $url_base .= '://'; $url_base .= $_SERVER['SERVER_NAME']; } // La session doit être nommée de la même manière dans Session.class.php // sinon ça ne marchera pas... session_name("GEPI"); // Le premier argument est la version du protocole CAS // Le dernier argument a été ajouté par patchage manuel de phpCAS. settype($cas_port, "integer"); phpCAS::client(CAS_VERSION_2_0, $cas_host, $cas_port, $cas_root, true, $url_base); phpCAS::setLang(PHPCAS_LANG_FRENCH); if (isset($cas_proxy_server) && $cas_proxy_server != "" && isset($cas_proxy_port) && $cas_proxy_port != "") { phpCAS::setExtraCurlOption(CURLOPT_PROXY, $cas_proxy_server); phpCAS::setExtraCurlOption(CURLOPT_PROXYPORT, $cas_proxy_port); phpCAS::setExtraCurlOption(CURLOPT_PROXYTYPE, CURLPROXY_HTTP); } // redirige vers le serveur d'authentification si aucun utilisateur authentifié n'a // été trouvé par le client CAS. phpCAS::setNoCasServerValidation(); // On a une demande de logout envoyée par le serveur CAS : // il faut initialiser la session tout de suite, pour pouvoir la détruire complètement if (isset($logout_request)) { $session_gepi = new Session(); // Gestion du single sign-out phpCAS::setSingleSignoutCallback(array($session_gepi, 'cas_logout_callback')); phpCAS::handleLogoutRequests(false); } // Authentification phpCAS::forceAuthentication(); // Initialisation de la session, avec blocage de l'initialisation de la