44 if (!isset($_SERVER[
'REQUEST_URI']) && isset($_SERVER[
'SCRIPT_NAME']) && isset($_SERVER[
'QUERY_STRING'])) {
45 $_SERVER[
'REQUEST_URI'] = $_SERVER[
'SCRIPT_NAME'] .
'?' . $_SERVER[
'QUERY_STRING'];
60 define(
'PHPCAS_VERSION',
'1.4.0');
74 define(
"CAS_VERSION_1_0",
'1.0');
78 define(
"CAS_VERSION_2_0",
'2.0');
82 define(
"CAS_VERSION_3_0",
'3.0');
91 define(
"SAML_VERSION_1_1",
'S1');
96 define(
"SAML_XML_HEADER",
'<?xml version="1.0" encoding="UTF-8"?>');
101 define(
"SAML_SOAP_ENV",
'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/>');
106 define(
"SAML_SOAP_BODY",
'<SOAP-ENV:Body>');
111 define(
"SAMLP_REQUEST",
'<samlp:Request xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol" MajorVersion="1" MinorVersion="1" RequestID="_192.168.16.51.1024506224022" IssueInstant="2002-06-19T17:03:44.022Z">');
112 define(
"SAMLP_REQUEST_CLOSE",
'</samlp:Request>');
117 define(
"SAML_ASSERTION_ARTIFACT",
'<samlp:AssertionArtifact>');
122 define(
"SAML_ASSERTION_ARTIFACT_CLOSE",
'</samlp:AssertionArtifact>');
127 define(
"SAML_SOAP_BODY_CLOSE",
'</SOAP-ENV:Body>');
132 define(
"SAML_SOAP_ENV_CLOSE",
'</SOAP-ENV:Envelope>');
137 define(
"SAML_ATTRIBUTES",
'SAMLATTRIBS');
142 define(
"DEFAULT_ERROR",
'Internal script failure');
155 define(
"CAS_PGT_STORAGE_FILE_DEFAULT_PATH", session_save_path());
168 define(
"PHPCAS_SERVICE_OK", 0);
173 define(
"PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE", 1);
178 define(
"PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE", 2);
183 define(
"PHPCAS_SERVICE_PT_FAILURE", 3);
187 define(
"PHPCAS_SERVICE_NOT_AVAILABLE", 4);
195 define(
"PHPCAS_PROXIED_SERVICE_HTTP_GET",
'CAS_ProxiedService_Http_Get');
199 define(
"PHPCAS_PROXIED_SERVICE_HTTP_POST",
'CAS_ProxiedService_Http_Post');
203 define(
"PHPCAS_PROXIED_SERVICE_IMAP",
'CAS_ProxiedService_Imap');
215 define(
"PHPCAS_LANG_ENGLISH",
'CAS_Languages_English');
216 define(
"PHPCAS_LANG_FRENCH",
'CAS_Languages_French');
217 define(
"PHPCAS_LANG_GREEK",
'CAS_Languages_Greek');
218 define(
"PHPCAS_LANG_GERMAN",
'CAS_Languages_German');
219 define(
"PHPCAS_LANG_JAPANESE",
'CAS_Languages_Japanese');
220 define(
"PHPCAS_LANG_SPANISH",
'CAS_Languages_Spanish');
221 define(
"PHPCAS_LANG_CATALAN",
'CAS_Languages_Catalan');
222 define(
"PHPCAS_LANG_CHINESE_SIMPLIFIED",
'CAS_Languages_ChineseSimplified');
223 define(
"PHPCAS_LANG_GALEGO",
'CAS_Languages_Galego');
224 define(
"PHPCAS_LANG_PORTUGUESE",
'CAS_Languages_Portuguese');
252 if (!empty($_ENV[
'TMP'])) {
return realpath($_ENV[
'TMP']); }
253 if (!empty($_ENV[
'TMPDIR'])) {
return realpath( $_ENV[
'TMPDIR']); }
254 if (!empty($_ENV[
'TEMP'])) {
return realpath( $_ENV[
'TEMP']); }
262 require_once __DIR__ .
'/CAS/Autoload.php';
345 public static function client($server_version, $server_hostname,
346 $server_port, $server_uri, $changeSessionID =
true, \SessionHandlerInterface $sessionHandler = null
349 if (is_object(self::$_PHPCAS_CLIENT)) {
350 phpCAS :: error(self::$_PHPCAS_INIT_CALL[
'method'] .
'() has already been called (at ' . self::$_PHPCAS_INIT_CALL[
'file'] .
':' . self::$_PHPCAS_INIT_CALL[
'line'] .
')');
354 $dbg = debug_backtrace();
355 self::$_PHPCAS_INIT_CALL = array (
357 'file' => $dbg[0][
'file'],
358 'line' => $dbg[0][
'line'],
359 'method' => __CLASS__ .
'::' . __FUNCTION__
365 $server_version,
false, $server_hostname, $server_port, $server_uri,
366 $changeSessionID, $sessionHandler
368 }
catch (Exception $e) {
391 public static function proxy($server_version, $server_hostname,
392 $server_port, $server_uri, $changeSessionID =
true, \SessionHandlerInterface $sessionHandler = null
395 if (is_object(self::$_PHPCAS_CLIENT)) {
396 phpCAS :: error(self::$_PHPCAS_INIT_CALL[
'method'] .
'() has already been called (at ' . self::$_PHPCAS_INIT_CALL[
'file'] .
':' . self::$_PHPCAS_INIT_CALL[
'line'] .
')');
400 $dbg = debug_backtrace();
401 self::$_PHPCAS_INIT_CALL = array (
403 'file' => $dbg[0][
'file'],
404 'line' => $dbg[0][
'line'],
405 'method' => __CLASS__ .
'::' . __FUNCTION__
411 $server_version,
true, $server_hostname, $server_port, $server_uri,
412 $changeSessionID, $sessionHandler
414 }
catch (Exception $e) {
427 return (is_object(self::$_PHPCAS_CLIENT));
450 if (empty(self::$_PHPCAS_DEBUG[
'unique_id'])) {
451 self::$_PHPCAS_DEBUG[
'unique_id'] = substr(strtoupper(md5(uniqid(
''))), 0, 4);
453 self::$_PHPCAS_DEBUG[
'logger'] = $logger;
454 self::$_PHPCAS_DEBUG[
'indent'] = 0;
470 trigger_error(
'phpCAS::setDebug() is deprecated in favor of phpCAS::setLogger().', E_USER_DEPRECATED);
472 if ($filename !=
false && gettype($filename) !=
'string') {
473 phpCAS :: error(
'type mismatched for parameter $dbg (should be false or the name of the log file)');
475 if ($filename ===
false) {
476 self::$_PHPCAS_DEBUG[
'filename'] =
false;
479 if (empty ($filename)) {
480 if (preg_match(
'/^Win.*/', getenv(
'OS'))) {
481 if (isset ($_ENV[
'TMP'])) {
482 $debugDir = $_ENV[
'TMP'] .
'/';
489 $filename = $debugDir .
'phpCAS.log';
492 if (empty (self::$_PHPCAS_DEBUG[
'unique_id'])) {
493 self::$_PHPCAS_DEBUG[
'unique_id'] = substr(strtoupper(md5(uniqid(
''))), 0, 4);
496 self::$_PHPCAS_DEBUG[
'filename'] = $filename;
497 self::$_PHPCAS_DEBUG[
'indent'] = 0;
514 if ($verbose ===
true) {
515 self::$_PHPCAS_VERBOSE =
true;
517 self::$_PHPCAS_VERBOSE =
false;
529 return self::$_PHPCAS_VERBOSE;
540 public static function log($str)
545 if (isset(self::$_PHPCAS_DEBUG[
'logger']) || !empty(self::$_PHPCAS_DEBUG[
'filename'])) {
546 for ($i = 0; $i < self::$_PHPCAS_DEBUG[
'indent']; $i++) {
552 $str2 = str_replace(
"\n",
"\n" . self::$_PHPCAS_DEBUG[
'unique_id'] .
' ' . $indent_str, $str);
553 $str3 = self::$_PHPCAS_DEBUG[
'unique_id'] .
' ' . $indent_str . $str2;
554 if (isset(self::$_PHPCAS_DEBUG[
'logger'])) {
555 self::$_PHPCAS_DEBUG[
'logger']->info($str3);
557 if (!empty(self::$_PHPCAS_DEBUG[
'filename'])) {
560 if (!file_exists(self::$_PHPCAS_DEBUG[
'filename'])) {
561 touch(self::$_PHPCAS_DEBUG[
'filename']);
563 @chmod(self::$_PHPCAS_DEBUG[
'filename'], 0600);
565 error_log($str3 .
"\n", 3, self::$_PHPCAS_DEBUG[
'filename']);
583 $dbg = debug_backtrace();
587 if (is_array($dbg)) {
588 for ($i = 1; $i <
sizeof($dbg); $i++) {
589 if (is_array($dbg[$i]) && isset($dbg[$i][
'class']) ) {
590 if ($dbg[$i][
'class'] == __CLASS__) {
591 $function = $dbg[$i][
'function'];
592 $file = $dbg[$i][
'file'];
593 $line = $dbg[$i][
'line'];
598 if (self::$_PHPCAS_VERBOSE) {
599 echo
"<br />\n<b>phpCAS error</b>: <font color=\"FF0000\"><b>" . __CLASS__ .
"::" . $function .
'(): ' . htmlentities($msg) .
"</b></font> in <b>" . $file .
"</b> on line <b>" . $line .
"</b><br />\n";
601 echo
"<br />\n<b>Error</b>: <font color=\"FF0000\"><b>".
DEFAULT_ERROR .
"</b><br />\n";
618 $dbg = debug_backtrace();
619 phpCAS :: log($str .
' [' . basename($dbg[0][
'file']) .
':' . $dbg[0][
'line'] .
']');
630 $dbg = debug_backtrace();
632 if (!empty ($dbg[1][
'class'])) {
633 $str .= $dbg[1][
'class'] .
'::';
635 $str .= $dbg[1][
'function'] .
'(';
636 if (is_array($dbg[1][
'args'])) {
637 foreach ($dbg[1][
'args'] as $index => $arg) {
641 if (is_object($arg)) {
642 $str .= get_class($arg);
644 $str .= str_replace(array(
"\r\n",
"\n",
"\r"),
"", var_export($arg,
true));
648 if (isset($dbg[1][
'file'])) {
649 $file = basename($dbg[1][
'file']);
651 $file =
'unknown_file';
653 if (isset($dbg[1][
'line'])) {
654 $line = $dbg[1][
'line'];
656 $line =
'unknown_line';
658 $str .=
') [' . $file .
':' . $line .
']';
660 if (!isset(self::$_PHPCAS_DEBUG[
'indent'])) {
661 self::$_PHPCAS_DEBUG[
'indent'] = 0;
663 self::$_PHPCAS_DEBUG[
'indent']++;
677 if (empty(self::$_PHPCAS_DEBUG[
'indent'])) {
678 self::$_PHPCAS_DEBUG[
'indent'] = 0;
680 self::$_PHPCAS_DEBUG[
'indent']--;
683 if (is_object($res)) {
684 $str .=
'<= ' . get_class($res);
686 $str .=
'<= ' . str_replace(array(
"\r\n",
"\n",
"\r"),
"", var_export($res,
true));
700 while (self::$_PHPCAS_DEBUG[
'indent'] > 0) {
702 self::$_PHPCAS_DEBUG[
'indent']--;
730 self::$_PHPCAS_CLIENT->setLang($lang);
731 }
catch (Exception $e) {
762 $supportedProtocols = array();
768 return $supportedProtocols;
792 self::$_PHPCAS_CLIENT->setHTMLHeader($header);
793 }
catch (Exception $e) {
810 self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
811 }
catch (Exception $e) {
839 self::$_PHPCAS_CLIENT->setPGTStorage($storage);
840 }
catch (Exception $e) {
870 self::$_PHPCAS_CLIENT->setPGTStorageDb($dsn_or_pdo, $username, $password, $table,
$driver_options);
871 }
catch (Exception $e) {
891 self::$_PHPCAS_CLIENT->setPGTStorageFile($path);
892 }
catch (Exception $e) {
922 $res = self::$_PHPCAS_CLIENT->getProxiedService($type);
923 }
catch (Exception $e) {
948 self::$_PHPCAS_CLIENT->initializeProxiedService($proxiedService);
949 }
catch (Exception $e) {
969 public static function serviceWeb($url, & $err_code, & $output)
975 $res = self::$_PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
976 }
catch (Exception $e) {
1003 public static function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
1009 $res = self::$_PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
1010 }
catch (Exception $e) {
1043 self::$_PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
1044 }
catch (Exception $e) {
1065 self::$_PHPCAS_CLIENT->setCasAttributeParserCallback($function, $additionalArgs);
1091 self::$_PHPCAS_CLIENT->setPostAuthenticateCallback($function, $additionalArgs);
1112 self::$_PHPCAS_CLIENT->setSingleSignoutCallback($function, $additionalArgs);
1130 $auth = self::$_PHPCAS_CLIENT->checkAuthentication();
1133 self::$_PHPCAS_CLIENT->markAuthenticationCall(
$auth);
1150 $auth = self::$_PHPCAS_CLIENT->forceAuthentication();
1153 self::$_PHPCAS_CLIENT->markAuthenticationCall(
$auth);
1176 $auth = self::$_PHPCAS_CLIENT->renewAuthentication();
1179 self::$_PHPCAS_CLIENT->markAuthenticationCall(
$auth);
1197 $auth = self::$_PHPCAS_CLIENT->isAuthenticated();
1200 self::$_PHPCAS_CLIENT->markAuthenticationCall(
$auth);
1232 return self::$_PHPCAS_CLIENT->getUser();
1233 }
catch (Exception $e) {
1251 return self::$_PHPCAS_CLIENT->getAttributes();
1252 }
catch (Exception $e) {
1270 return self::$_PHPCAS_CLIENT->hasAttributes();
1271 }
catch (Exception $e) {
1290 return self::$_PHPCAS_CLIENT->hasAttribute($key);
1291 }
catch (Exception $e) {
1310 return self::$_PHPCAS_CLIENT->getAttribute($key);
1311 }
catch (Exception $e) {
1340 return self::$_PHPCAS_CLIENT->getServerLoginURL();
1357 self::$_PHPCAS_CLIENT->setServerLoginURL($url);
1358 }
catch (Exception $e) {
1383 self::$_PHPCAS_CLIENT->setServerServiceValidateURL($url);
1384 }
catch (Exception $e) {
1409 self::$_PHPCAS_CLIENT->setServerProxyValidateURL($url);
1410 }
catch (Exception $e) {
1430 self::$_PHPCAS_CLIENT->setServerSamlValidateURL($url);
1431 }
catch (Exception $e) {
1447 return self::$_PHPCAS_CLIENT->getServerLogoutURL();
1464 self::$_PHPCAS_CLIENT->setServerLogoutURL($url);
1465 }
catch (Exception $e) {
1485 $parsedParams = array ();
1486 if ($params !=
"") {
1487 if (is_string($params)) {
1488 phpCAS :: error(
'method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');
1490 if (!is_array($params)) {
1491 phpCAS :: error(
'type mismatched for parameter $params (should be `array\')');
1493 foreach ($params as $key => $value) {
1494 if ($key !=
"service" && $key !=
"url") {
1495 phpCAS :: error(
'only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');
1497 $parsedParams[$key] = $value;
1500 self::$_PHPCAS_CLIENT->logout($parsedParams);
1518 if (!is_string($service)) {
1519 phpCAS :: error(
'type mismatched for parameter $service (should be `string\')');
1521 self::$_PHPCAS_CLIENT->logout(array (
"service" => $service ));
1538 trigger_error(
'Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
1540 if (!is_object(self::$_PHPCAS_CLIENT)) {
1541 phpCAS :: error(
'this method should only be called after ' . __CLASS__ .
'::client() or' . __CLASS__ .
'::proxy()');
1543 if (!is_string($url)) {
1544 phpCAS :: error(
'type mismatched for parameter $url (should be `string\')');
1546 self::$_PHPCAS_CLIENT->logout(array (
"url" => $url ));
1565 trigger_error(
'Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
1569 if (!is_string($service)) {
1570 phpCAS :: error(
'type mismatched for parameter $service (should be `string\')');
1572 if (!is_string($url)) {
1573 phpCAS :: error(
'type mismatched for parameter $url (should be `string\')');
1575 self::$_PHPCAS_CLIENT->logout(
1577 "service" => $service,
1600 self::$_PHPCAS_CLIENT->setCallbackURL($url);
1601 }
catch (Exception $e) {
1622 self::$_PHPCAS_CLIENT->setURL($url);
1623 }
catch (Exception $e) {
1638 return (self::$_PHPCAS_CLIENT->getURL());
1650 public static function retrievePT($target_service, & $err_code, & $err_msg)
1655 return (self::$_PHPCAS_CLIENT->
retrievePT($target_service, $err_code, $err_msg));
1656 }
catch (Exception $e) {
1676 self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
1677 }
catch (Exception $e) {
1694 phpCAS :: trace(
'You have configured no validation of the legitimacy of the cas server. This is not recommended for production use.');
1695 self::$_PHPCAS_CLIENT->setNoCasServerValidation();
1714 self::$_PHPCAS_CLIENT->setNoClearTicketsFromUrl();
1734 self::$_PHPCAS_CLIENT->setExtraCurlOption($key, $value);
1755 self::$_PHPCAS_CLIENT->setSessionIdSalt($salt);
1803 phpCAS :: error(
'this method can only be used with the cas 2.0/3.0 protocols');
1805 self::$_PHPCAS_CLIENT->getAllowedProxyChains()->allowProxyChain($proxy_chain);
1840 phpCAS::log(
'rebroadcastNodeUrl:'.$rebroadcastNodeUrl);
1844 self::$_PHPCAS_CLIENT->addRebroadcastNode($rebroadcastNodeUrl);
1845 }
catch (Exception $e) {
1866 self::$_PHPCAS_CLIENT->addRebroadcastHeader($header);
1867 }
catch (Exception $e) {
1883 if (!is_object(self::$_PHPCAS_CLIENT)) {
1897 if (!is_object(self::$_PHPCAS_CLIENT)) {
1907 return self::$_PHPCAS_CLIENT;
1917 self::$_PHPCAS_CLIENT =
$client;
static forceAuthentication()
static serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
static serviceWeb($url, & $err_code, & $output)
static logoutWithUrl($url)
static getAttribute($key)
static $_PHPCAS_INIT_CALL
static setNoClearTicketsFromUrl()
static handleLogoutRequests($check_client=true, $allowed_clients=array())
static setCacheTimesForAuthRecheck($n)
static setCasAttributeParserCallback($function, array $additionalArgs=array())
static addRebroadcastNode($rebroadcastNodeUrl)
static allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
static setFixedCallbackURL($url='')
static proxy($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true, \SessionHandlerInterface $sessionHandler=null)
static logoutWithRedirectServiceAndUrl($service, $url)
static checkAuthentication()
static setHTMLFooter($footer)
static client($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true, \SessionHandlerInterface $sessionHandler=null)
static getProxiedService($type)
static setServerLoginURL($url='')
static setServerSamlValidateURL($url='')
static getSupportedProtocols()
static setSessionIdSalt($salt)
static setHTMLHeader($header)
static initializeProxiedService(CAS_ProxiedService $proxiedService)
static setServerServiceValidateURL($url='')
static setLogger($logger=null)
const PHPCAS_LANG_ENGLISH
static isSessionAuthenticated()
static setSingleSignoutCallback($function, array $additionalArgs=array())
static setPGTStorageDb($dsn_or_pdo, $username='', $password='', $table='', $driver_options=null)
static setPostAuthenticateCallback($function, array $additionalArgs=array())
static setExtraCurlOption($key, $value)
static setServerProxyValidateURL($url='')
static logout($params="")
static setFixedServiceURL($url)
static setCasServerCACert($cert, $validate_cn=true)
static renewAuthentication()
const PHPCAS_VERSION(!isset($_SERVER['REQUEST_URI']) &&isset($_SERVER['SCRIPT_NAME']) &&isset($_SERVER['QUERY_STRING']))
static setVerbose($verbose)
static _validateProxyExists()
static logoutWithRedirectService($service)
static retrievePT($target_service, & $err_code, & $err_msg)
static setDebug($filename='')
static setPGTStorage($storage)
static setServerLogoutURL($url='')
static getServerLogoutURL()
static setPGTStorageFile($path='')
static setCasClient(\CAS_Client $client)
if(isset($_REQUEST['logout'])) if(isset($_REQUEST['login'])) $auth
static _validateClientExists()
static setNoCasServerValidation()
static addRebroadcastHeader($header)
static hasAttribute($key)
static getServerLoginURL()