43 if (!isset($_SERVER[
'REQUEST_URI']) && isset($_SERVER[
'SCRIPT_NAME']) && isset($_SERVER[
'QUERY_STRING'])) {
44 $_SERVER[
'REQUEST_URI'] = $_SERVER[
'SCRIPT_NAME'] .
'?' . $_SERVER[
'QUERY_STRING'];
48 if (!defined(
'E_USER_DEPRECATED')) {
49 define(
'E_USER_DEPRECATED', E_USER_NOTICE);
64 define(
'PHPCAS_VERSION',
'1.3.6');
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');
249 if (!empty($_ENV[
'TMP'])) {
return realpath($_ENV[
'TMP']); }
250 if (!empty($_ENV[
'TMPDIR'])) {
return realpath( $_ENV[
'TMPDIR']); }
251 if (!empty($_ENV[
'TEMP'])) {
return realpath( $_ENV[
'TEMP']); }
259 require_once dirname(__FILE__) .
'/CAS/Autoload.php';
338 public static function client($server_version, $server_hostname,
339 $server_port, $server_uri, $changeSessionID =
true 342 if (is_object(self::$_PHPCAS_CLIENT)) {
343 phpCAS :: error(self::$_PHPCAS_INIT_CALL[
'method'] .
'() has already been called (at ' . self::$_PHPCAS_INIT_CALL[
'file'] .
':' . self::$_PHPCAS_INIT_CALL[
'line'] .
')');
347 $dbg = debug_backtrace();
348 self::$_PHPCAS_INIT_CALL = array (
350 'file' => $dbg[0][
'file'],
351 'line' => $dbg[0][
'line'],
352 'method' => __CLASS__ .
'::' . __FUNCTION__
358 $server_version,
false, $server_hostname, $server_port, $server_uri,
361 }
catch (Exception $e) {
382 public static function proxy($server_version, $server_hostname,
383 $server_port, $server_uri, $changeSessionID =
true 386 if (is_object(self::$_PHPCAS_CLIENT)) {
387 phpCAS :: error(self::$_PHPCAS_INIT_CALL[
'method'] .
'() has already been called (at ' . self::$_PHPCAS_INIT_CALL[
'file'] .
':' . self::$_PHPCAS_INIT_CALL[
'line'] .
')');
391 $dbg = debug_backtrace();
392 self::$_PHPCAS_INIT_CALL = array (
394 'file' => $dbg[0][
'file'],
395 'line' => $dbg[0][
'line'],
396 'method' => __CLASS__ .
'::' . __FUNCTION__
402 $server_version,
true, $server_hostname, $server_port, $server_uri,
405 }
catch (Exception $e) {
418 return (is_object(self::$_PHPCAS_CLIENT));
441 if ($filename !=
false && gettype($filename) !=
'string') {
442 phpCAS :: error(
'type mismatched for parameter $dbg (should be false or the name of the log file)');
444 if ($filename ===
false) {
445 self::$_PHPCAS_DEBUG[
'filename'] =
false;
448 if (empty ($filename)) {
449 if (preg_match(
'/^Win.*/', getenv(
'OS'))) {
450 if (isset ($_ENV[
'TMP'])) {
451 $debugDir = $_ENV[
'TMP'] .
'/';
458 $filename = $debugDir .
'phpCAS.log';
461 if (empty (self::$_PHPCAS_DEBUG[
'unique_id'])) {
462 self::$_PHPCAS_DEBUG[
'unique_id'] = substr(strtoupper(md5(uniqid(
''))), 0, 4);
465 self::$_PHPCAS_DEBUG[
'filename'] = $filename;
466 self::$_PHPCAS_DEBUG[
'indent'] = 0;
483 if ($verbose ===
true) {
484 self::$_PHPCAS_VERBOSE =
true;
486 self::$_PHPCAS_VERBOSE =
false;
498 return self::$_PHPCAS_VERBOSE;
509 public static function log($str)
514 if (!empty(self::$_PHPCAS_DEBUG[
'filename'])) {
517 if (!file_exists(self::$_PHPCAS_DEBUG[
'filename'])) {
518 touch(self::$_PHPCAS_DEBUG[
'filename']);
520 @chmod(self::$_PHPCAS_DEBUG[
'filename'], 0600);
522 for ($i = 0; $i < self::$_PHPCAS_DEBUG[
'indent']; $i++) {
528 $str2 = str_replace(
"\n",
"\n" . self::$_PHPCAS_DEBUG[
'unique_id'] .
' ' . $indent_str, $str);
529 error_log(self::$_PHPCAS_DEBUG[
'unique_id'] .
' ' . $indent_str . $str2 .
"\n", 3, self::$_PHPCAS_DEBUG[
'filename']);
546 $dbg = debug_backtrace();
550 if (is_array($dbg)) {
551 for ($i = 1; $i <
sizeof($dbg); $i++) {
552 if (is_array($dbg[$i]) && isset($dbg[$i][
'class']) ) {
553 if ($dbg[$i][
'class'] == __CLASS__) {
554 $function = $dbg[$i][
'function'];
555 $file = $dbg[$i][
'file'];
556 $line = $dbg[$i][
'line'];
561 if (self::$_PHPCAS_VERBOSE) {
562 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";
564 echo
"<br />\n<b>Error</b>: <font color=\"FF0000\"><b>".
DEFAULT_ERROR .
"</b><br />\n";
581 $dbg = debug_backtrace();
582 phpCAS :: log($str .
' [' . basename($dbg[0][
'file']) .
':' . $dbg[0][
'line'] .
']');
593 $dbg = debug_backtrace();
595 if (!empty ($dbg[1][
'class'])) {
596 $str .= $dbg[1][
'class'] .
'::';
598 $str .= $dbg[1][
'function'] .
'(';
599 if (is_array($dbg[1][
'args'])) {
600 foreach ($dbg[1][
'args'] as $index => $arg) {
604 if (is_object($arg)) {
605 $str .= get_class($arg);
607 $str .= str_replace(array(
"\r\n",
"\n",
"\r"),
"", var_export($arg,
true));
611 if (isset($dbg[1][
'file'])) {
612 $file = basename($dbg[1][
'file']);
614 $file =
'unknown_file';
616 if (isset($dbg[1][
'line'])) {
617 $line = $dbg[1][
'line'];
619 $line =
'unknown_line';
621 $str .=
') [' . $file .
':' . $line .
']';
623 if (!isset(self::$_PHPCAS_DEBUG[
'indent'])) {
624 self::$_PHPCAS_DEBUG[
'indent'] = 0;
626 self::$_PHPCAS_DEBUG[
'indent']++;
640 if (empty(self::$_PHPCAS_DEBUG[
'indent'])) {
641 self::$_PHPCAS_DEBUG[
'indent'] = 0;
643 self::$_PHPCAS_DEBUG[
'indent']--;
645 $dbg = debug_backtrace();
647 if (is_object($res)) {
648 $str .=
'<= ' . get_class($res);
650 $str .=
'<= ' . str_replace(array(
"\r\n",
"\n",
"\r"),
"", var_export($res,
true));
664 while (self::$_PHPCAS_DEBUG[
'indent'] > 0) {
666 self::$_PHPCAS_DEBUG[
'indent']--;
694 self::$_PHPCAS_CLIENT->setLang($lang);
695 }
catch (Exception $e) {
740 self::$_PHPCAS_CLIENT->setHTMLHeader($header);
741 }
catch (Exception $e) {
758 self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
759 }
catch (Exception $e) {
787 self::$_PHPCAS_CLIENT->setPGTStorage($storage);
788 }
catch (Exception $e) {
818 self::$_PHPCAS_CLIENT->setPGTStorageDb($dsn_or_pdo, $username, $password, $table,
$driver_options);
819 }
catch (Exception $e) {
839 self::$_PHPCAS_CLIENT->setPGTStorageFile($path);
840 }
catch (Exception $e) {
870 $res = self::$_PHPCAS_CLIENT->getProxiedService($type);
871 }
catch (Exception $e) {
896 self::$_PHPCAS_CLIENT->initializeProxiedService($proxiedService);
897 }
catch (Exception $e) {
917 public static function serviceWeb($url, & $err_code, & $output)
923 $res = self::$_PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
924 }
catch (Exception $e) {
951 public static function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
957 $res = self::$_PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
958 }
catch (Exception $e) {
991 self::$_PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
992 }
catch (Exception $e) {
1013 self::$_PHPCAS_CLIENT->setCasAttributeParserCallback($function, $additionalArgs);
1039 self::$_PHPCAS_CLIENT->setPostAuthenticateCallback($function, $additionalArgs);
1060 self::$_PHPCAS_CLIENT->setSingleSignoutCallback($function, $additionalArgs);
1078 $auth = self::$_PHPCAS_CLIENT->checkAuthentication();
1081 self::$_PHPCAS_CLIENT->markAuthenticationCall(
$auth);
1098 $auth = self::$_PHPCAS_CLIENT->forceAuthentication();
1101 self::$_PHPCAS_CLIENT->markAuthenticationCall(
$auth);
1124 $auth = self::$_PHPCAS_CLIENT->renewAuthentication();
1127 self::$_PHPCAS_CLIENT->markAuthenticationCall(
$auth);
1145 $auth = self::$_PHPCAS_CLIENT->isAuthenticated();
1148 self::$_PHPCAS_CLIENT->markAuthenticationCall(
$auth);
1180 return self::$_PHPCAS_CLIENT->getUser();
1181 }
catch (Exception $e) {
1199 return self::$_PHPCAS_CLIENT->getAttributes();
1200 }
catch (Exception $e) {
1218 return self::$_PHPCAS_CLIENT->hasAttributes();
1219 }
catch (Exception $e) {
1238 return self::$_PHPCAS_CLIENT->hasAttribute($key);
1239 }
catch (Exception $e) {
1258 return self::$_PHPCAS_CLIENT->getAttribute($key);
1259 }
catch (Exception $e) {
1289 return self::$_PHPCAS_CLIENT->getServerLoginURL();
1306 self::$_PHPCAS_CLIENT->setServerLoginURL($url);
1307 }
catch (Exception $e) {
1332 self::$_PHPCAS_CLIENT->setServerServiceValidateURL($url);
1333 }
catch (Exception $e) {
1358 self::$_PHPCAS_CLIENT->setServerProxyValidateURL($url);
1359 }
catch (Exception $e) {
1379 self::$_PHPCAS_CLIENT->setServerSamlValidateURL($url);
1380 }
catch (Exception $e) {
1397 return self::$_PHPCAS_CLIENT->getServerLogoutURL();
1414 self::$_PHPCAS_CLIENT->setServerLogoutURL($url);
1415 }
catch (Exception $e) {
1435 $parsedParams = array ();
1436 if ($params !=
"") {
1437 if (is_string($params)) {
1438 phpCAS :: error(
'method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');
1440 if (!is_array($params)) {
1441 phpCAS :: error(
'type mismatched for parameter $params (should be `array\')');
1443 foreach ($params as $key => $value) {
1444 if ($key !=
"service" && $key !=
"url") {
1445 phpCAS :: error(
'only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');
1447 $parsedParams[$key] = $value;
1450 self::$_PHPCAS_CLIENT->logout($parsedParams);
1468 if (!is_string($service)) {
1469 phpCAS :: error(
'type mismatched for parameter $service (should be `string\')');
1471 self::$_PHPCAS_CLIENT->logout(array (
"service" => $service ));
1488 trigger_error(
'Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
1490 if (!is_object(self::$_PHPCAS_CLIENT)) {
1491 phpCAS :: error(
'this method should only be called after ' . __CLASS__ .
'::client() or' . __CLASS__ .
'::proxy()');
1493 if (!is_string($url)) {
1494 phpCAS :: error(
'type mismatched for parameter $url (should be `string\')');
1496 self::$_PHPCAS_CLIENT->logout(array (
"url" => $url ));
1515 trigger_error(
'Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
1519 if (!is_string($service)) {
1520 phpCAS :: error(
'type mismatched for parameter $service (should be `string\')');
1522 if (!is_string($url)) {
1523 phpCAS :: error(
'type mismatched for parameter $url (should be `string\')');
1525 self::$_PHPCAS_CLIENT->logout(
1527 "service" => $service,
1550 self::$_PHPCAS_CLIENT->setCallbackURL($url);
1551 }
catch (Exception $e) {
1572 self::$_PHPCAS_CLIENT->setURL($url);
1573 }
catch (Exception $e) {
1588 return (self::$_PHPCAS_CLIENT->getURL());
1600 public static function retrievePT($target_service, & $err_code, & $err_msg)
1605 return (self::$_PHPCAS_CLIENT->
retrievePT($target_service, $err_code, $err_msg));
1606 }
catch (Exception $e) {
1626 self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
1627 }
catch (Exception $e) {
1644 phpCAS :: trace(
'You have configured no validation of the legitimacy of the cas server. This is not recommended for production use.');
1645 self::$_PHPCAS_CLIENT->setNoCasServerValidation();
1664 self::$_PHPCAS_CLIENT->setNoClearTicketsFromUrl();
1684 self::$_PHPCAS_CLIENT->setExtraCurlOption($key, $value);
1705 self::$_PHPCAS_CLIENT->setSessionIdSalt($salt);
1753 phpCAS :: error(
'this method can only be used with the cas 2.0/3.0 protocols');
1755 self::$_PHPCAS_CLIENT->getAllowedProxyChains()->allowProxyChain($proxy_chain);
1790 phpCAS::log(
'rebroadcastNodeUrl:'.$rebroadcastNodeUrl);
1794 self::$_PHPCAS_CLIENT->addRebroadcastNode($rebroadcastNodeUrl);
1795 }
catch (Exception $e) {
1816 self::$_PHPCAS_CLIENT->addRebroadcastHeader($header);
1817 }
catch (Exception $e) {
1833 if (!is_object(self::$_PHPCAS_CLIENT)) {
1847 if (!is_object(self::$_PHPCAS_CLIENT)) {
1859 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 setCacheTimesForAuthRecheck($n)
const PHPCAS_VERSION(!defined('E_USER_DEPRECATED'))
static setCasAttributeParserCallback($function, array $additionalArgs=array())
static addRebroadcastNode($rebroadcastNodeUrl)
static allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
static setFixedCallbackURL($url='')
static logoutWithRedirectServiceAndUrl($service, $url)
static checkAuthentication()
static setHTMLFooter($footer)
static getProxiedService($type)
static setServerLoginURL($url='')
static setServerSamlValidateURL($url='')
static setSessionIdSalt($salt)
static setHTMLHeader($header)
static initializeProxiedService(CAS_ProxiedService $proxiedService)
static setServerServiceValidateURL($url='')
const PHPCAS_LANG_ENGLISH
static proxy($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true)
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 handleLogoutRequests($check_client=true, $allowed_clients=false)
static setServerProxyValidateURL($url='')
static logout($params="")
static setFixedServiceURL($url)
static setCasServerCACert($cert, $validate_cn=true)
static renewAuthentication()
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 client($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true)
static hasAttribute($key)
static getServerLoginURL()