phpCAS  version 1.4.0
CAS.php
Go to the documentation of this file.
1 <?php
2 
39 
40 //
41 // hack by Vangelis Haniotakis to handle the absence of $_SERVER['REQUEST_URI']
42 // in IIS
43 //
44 if (!isset($_SERVER['REQUEST_URI']) && isset($_SERVER['SCRIPT_NAME']) && isset($_SERVER['QUERY_STRING'])) {
45  $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
46 }
47 
48 
49 // ########################################################################
50 // CONSTANTS
51 // ########################################################################
52 
53 // ------------------------------------------------------------------------
54 // CAS VERSIONS
55 // ------------------------------------------------------------------------
56 
60 define('PHPCAS_VERSION', '1.4.0');
61 
74 define("CAS_VERSION_1_0", '1.0');
78 define("CAS_VERSION_2_0", '2.0');
82 define("CAS_VERSION_3_0", '3.0');
83 
84 // ------------------------------------------------------------------------
85 // SAML defines
86 // ------------------------------------------------------------------------
87 
91 define("SAML_VERSION_1_1", 'S1');
92 
96 define("SAML_XML_HEADER", '<?xml version="1.0" encoding="UTF-8"?>');
97 
101 define("SAML_SOAP_ENV", '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/>');
102 
106 define("SAML_SOAP_BODY", '<SOAP-ENV:Body>');
107 
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>');
113 
117 define("SAML_ASSERTION_ARTIFACT", '<samlp:AssertionArtifact>');
118 
122 define("SAML_ASSERTION_ARTIFACT_CLOSE", '</samlp:AssertionArtifact>');
123 
127 define("SAML_SOAP_BODY_CLOSE", '</SOAP-ENV:Body>');
128 
132 define("SAML_SOAP_ENV_CLOSE", '</SOAP-ENV:Envelope>');
133 
137 define("SAML_ATTRIBUTES", 'SAMLATTRIBS');
138 
142 define("DEFAULT_ERROR", 'Internal script failure');
143 
149 // ------------------------------------------------------------------------
150 // FILE PGT STORAGE
151 // ------------------------------------------------------------------------
155 define("CAS_PGT_STORAGE_FILE_DEFAULT_PATH", session_save_path());
157 // ------------------------------------------------------------------------
158 // SERVICE ACCESS ERRORS
159 // ------------------------------------------------------------------------
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);
188 
189 // ------------------------------------------------------------------------
190 // SERVICE TYPES
191 // ------------------------------------------------------------------------
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');
204 
205 
207 // ------------------------------------------------------------------------
208 // LANGUAGES
209 // ------------------------------------------------------------------------
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');
225 
236 define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);
237 
239 // ------------------------------------------------------------------------
240 // DEBUG
241 // ------------------------------------------------------------------------
251 function gettmpdir() {
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']); }
255 return "/tmp";
256 }
257 define('DEFAULT_DEBUG_DIR', gettmpdir()."/");
258 
261 // include the class autoloader
262 require_once __DIR__ . '/CAS/Autoload.php';
263 
281 class phpCAS
282 {
283 
290  private static $_PHPCAS_CLIENT;
291 
299  private static $_PHPCAS_INIT_CALL;
300 
307  private static $_PHPCAS_DEBUG;
308 
316  private static $_PHPCAS_VERBOSE = false;
317 
318 
319  // ########################################################################
320  // INITIALIZATION
321  // ########################################################################
322 
345  public static function client($server_version, $server_hostname,
346  $server_port, $server_uri, $changeSessionID = true, \SessionHandlerInterface $sessionHandler = null
347  ) {
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'] . ')');
351  }
352 
353  // store where the initializer is called from
354  $dbg = debug_backtrace();
355  self::$_PHPCAS_INIT_CALL = array (
356  'done' => true,
357  'file' => $dbg[0]['file'],
358  'line' => $dbg[0]['line'],
359  'method' => __CLASS__ . '::' . __FUNCTION__
360  );
361 
362  // initialize the object $_PHPCAS_CLIENT
363  try {
364  self::$_PHPCAS_CLIENT = new CAS_Client(
365  $server_version, false, $server_hostname, $server_port, $server_uri,
366  $changeSessionID, $sessionHandler
367  );
368  } catch (Exception $e) {
369  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
370  }
372  }
373 
391  public static function proxy($server_version, $server_hostname,
392  $server_port, $server_uri, $changeSessionID = true, \SessionHandlerInterface $sessionHandler = null
393  ) {
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'] . ')');
397  }
398 
399  // store where the initialzer is called from
400  $dbg = debug_backtrace();
401  self::$_PHPCAS_INIT_CALL = array (
402  'done' => true,
403  'file' => $dbg[0]['file'],
404  'line' => $dbg[0]['line'],
405  'method' => __CLASS__ . '::' . __FUNCTION__
406  );
407 
408  // initialize the object $_PHPCAS_CLIENT
409  try {
410  self::$_PHPCAS_CLIENT = new CAS_Client(
411  $server_version, true, $server_hostname, $server_port, $server_uri,
412  $changeSessionID, $sessionHandler
413  );
414  } catch (Exception $e) {
415  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
416  }
418  }
419 
425  public static function isInitialized ()
426  {
427  return (is_object(self::$_PHPCAS_CLIENT));
428  }
429 
431  // ########################################################################
432  // DEBUGGING
433  // ########################################################################
434 
448  public static function setLogger($logger = null)
449  {
450  if (empty(self::$_PHPCAS_DEBUG['unique_id'])) {
451  self::$_PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4);
452  }
453  self::$_PHPCAS_DEBUG['logger'] = $logger;
454  self::$_PHPCAS_DEBUG['indent'] = 0;
455  phpCAS :: trace('START ('.date("Y-m-d H:i:s").') phpCAS-' . PHPCAS_VERSION . ' ******************');
456  }
457 
468  public static function setDebug($filename = '')
469  {
470  trigger_error('phpCAS::setDebug() is deprecated in favor of phpCAS::setLogger().', E_USER_DEPRECATED);
471 
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)');
474  }
475  if ($filename === false) {
476  self::$_PHPCAS_DEBUG['filename'] = false;
477 
478  } else {
479  if (empty ($filename)) {
480  if (preg_match('/^Win.*/', getenv('OS'))) {
481  if (isset ($_ENV['TMP'])) {
482  $debugDir = $_ENV['TMP'] . '/';
483  } else {
484  $debugDir = '';
485  }
486  } else {
487  $debugDir = DEFAULT_DEBUG_DIR;
488  }
489  $filename = $debugDir . 'phpCAS.log';
490  }
491 
492  if (empty (self::$_PHPCAS_DEBUG['unique_id'])) {
493  self::$_PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4);
494  }
495 
496  self::$_PHPCAS_DEBUG['filename'] = $filename;
497  self::$_PHPCAS_DEBUG['indent'] = 0;
498 
499  phpCAS :: trace('START ('.date("Y-m-d H:i:s").') phpCAS-' . PHPCAS_VERSION . ' ******************');
500  }
501  }
502 
512  public static function setVerbose($verbose)
513  {
514  if ($verbose === true) {
515  self::$_PHPCAS_VERBOSE = true;
516  } else {
517  self::$_PHPCAS_VERBOSE = false;
518  }
519  }
520 
521 
527  public static function getVerbose()
528  {
529  return self::$_PHPCAS_VERBOSE;
530  }
531 
540  public static function log($str)
541  {
542  $indent_str = ".";
543 
544 
545  if (isset(self::$_PHPCAS_DEBUG['logger']) || !empty(self::$_PHPCAS_DEBUG['filename'])) {
546  for ($i = 0; $i < self::$_PHPCAS_DEBUG['indent']; $i++) {
547 
548  $indent_str .= '| ';
549  }
550  // allow for multiline output with proper identing. Usefull for
551  // dumping cas answers etc.
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);
556  }
557  if (!empty(self::$_PHPCAS_DEBUG['filename'])) {
558  // Check if file exists and modifiy file permissions to be only
559  // readable by the webserver
560  if (!file_exists(self::$_PHPCAS_DEBUG['filename'])) {
561  touch(self::$_PHPCAS_DEBUG['filename']);
562  // Chmod will fail on windows
563  @chmod(self::$_PHPCAS_DEBUG['filename'], 0600);
564  }
565  error_log($str3 . "\n", 3, self::$_PHPCAS_DEBUG['filename']);
566  }
567  }
568 
569  }
570 
580  public static function error($msg)
581  {
583  $dbg = debug_backtrace();
584  $function = '?';
585  $file = '?';
586  $line = '?';
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'];
594  }
595  }
596  }
597  }
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";
600  } else {
601  echo "<br />\n<b>Error</b>: <font color=\"FF0000\"><b>". DEFAULT_ERROR ."</b><br />\n";
602  }
603  phpCAS :: trace($msg . ' in ' . $file . 'on line ' . $line );
605 
606  throw new CAS_GracefullTerminationException(__CLASS__ . "::" . $function . '(): ' . $msg);
607  }
608 
616  public static function trace($str)
617  {
618  $dbg = debug_backtrace();
619  phpCAS :: log($str . ' [' . basename($dbg[0]['file']) . ':' . $dbg[0]['line'] . ']');
620  }
621 
628  public static function traceBegin()
629  {
630  $dbg = debug_backtrace();
631  $str = '=> ';
632  if (!empty ($dbg[1]['class'])) {
633  $str .= $dbg[1]['class'] . '::';
634  }
635  $str .= $dbg[1]['function'] . '(';
636  if (is_array($dbg[1]['args'])) {
637  foreach ($dbg[1]['args'] as $index => $arg) {
638  if ($index != 0) {
639  $str .= ', ';
640  }
641  if (is_object($arg)) {
642  $str .= get_class($arg);
643  } else {
644  $str .= str_replace(array("\r\n", "\n", "\r"), "", var_export($arg, true));
645  }
646  }
647  }
648  if (isset($dbg[1]['file'])) {
649  $file = basename($dbg[1]['file']);
650  } else {
651  $file = 'unknown_file';
652  }
653  if (isset($dbg[1]['line'])) {
654  $line = $dbg[1]['line'];
655  } else {
656  $line = 'unknown_line';
657  }
658  $str .= ') [' . $file . ':' . $line . ']';
659  phpCAS :: log($str);
660  if (!isset(self::$_PHPCAS_DEBUG['indent'])) {
661  self::$_PHPCAS_DEBUG['indent'] = 0;
662  } else {
663  self::$_PHPCAS_DEBUG['indent']++;
664  }
665  }
666 
675  public static function traceEnd($res = '')
676  {
677  if (empty(self::$_PHPCAS_DEBUG['indent'])) {
678  self::$_PHPCAS_DEBUG['indent'] = 0;
679  } else {
680  self::$_PHPCAS_DEBUG['indent']--;
681  }
682  $str = '';
683  if (is_object($res)) {
684  $str .= '<= ' . get_class($res);
685  } else {
686  $str .= '<= ' . str_replace(array("\r\n", "\n", "\r"), "", var_export($res, true));
687  }
688 
689  phpCAS :: log($str);
690  }
691 
697  public static function traceExit()
698  {
699  phpCAS :: log('exit()');
700  while (self::$_PHPCAS_DEBUG['indent'] > 0) {
701  phpCAS :: log('-');
702  self::$_PHPCAS_DEBUG['indent']--;
703  }
704  }
705 
707  // ########################################################################
708  // INTERNATIONALIZATION
709  // ########################################################################
725  public static function setLang($lang)
726  {
728 
729  try {
730  self::$_PHPCAS_CLIENT->setLang($lang);
731  } catch (Exception $e) {
732  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
733  }
734  }
735 
737  // ########################################################################
738  // VERSION
739  // ########################################################################
750  public static function getVersion()
751  {
752  return PHPCAS_VERSION;
753  }
754 
760  public static function getSupportedProtocols()
761  {
762  $supportedProtocols = array();
763  $supportedProtocols[CAS_VERSION_1_0] = 'CAS 1.0';
764  $supportedProtocols[CAS_VERSION_2_0] = 'CAS 2.0';
765  $supportedProtocols[CAS_VERSION_3_0] = 'CAS 3.0';
766  $supportedProtocols[SAML_VERSION_1_1] = 'SAML 1.1';
767 
768  return $supportedProtocols;
769  }
770 
772  // ########################################################################
773  // HTML OUTPUT
774  // ########################################################################
787  public static function setHTMLHeader($header)
788  {
790 
791  try {
792  self::$_PHPCAS_CLIENT->setHTMLHeader($header);
793  } catch (Exception $e) {
794  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
795  }
796  }
797 
805  public static function setHTMLFooter($footer)
806  {
808 
809  try {
810  self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
811  } catch (Exception $e) {
812  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
813  }
814  }
815 
817  // ########################################################################
818  // PGT STORAGE
819  // ########################################################################
833  public static function setPGTStorage($storage)
834  {
837 
838  try {
839  self::$_PHPCAS_CLIENT->setPGTStorage($storage);
840  } catch (Exception $e) {
841  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
842  }
844  }
845 
863  public static function setPGTStorageDb($dsn_or_pdo, $username='',
864  $password='', $table='', $driver_options=null
865  ) {
868 
869  try {
870  self::$_PHPCAS_CLIENT->setPGTStorageDb($dsn_or_pdo, $username, $password, $table, $driver_options);
871  } catch (Exception $e) {
872  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
873  }
875  }
876 
885  public static function setPGTStorageFile($path = '')
886  {
889 
890  try {
891  self::$_PHPCAS_CLIENT->setPGTStorageFile($path);
892  } catch (Exception $e) {
893  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
894  }
896  }
898  // ########################################################################
899  // ACCESS TO EXTERNAL SERVICES
900  // ########################################################################
916  public static function getProxiedService ($type)
917  {
920 
921  try {
922  $res = self::$_PHPCAS_CLIENT->getProxiedService($type);
923  } catch (Exception $e) {
924  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
925  }
926 
928  return $res;
929  }
930 
943  public static function initializeProxiedService (CAS_ProxiedService $proxiedService)
944  {
946 
947  try {
948  self::$_PHPCAS_CLIENT->initializeProxiedService($proxiedService);
949  } catch (Exception $e) {
950  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
951  }
952  }
953 
969  public static function serviceWeb($url, & $err_code, & $output)
970  {
973 
974  try {
975  $res = self::$_PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
976  } catch (Exception $e) {
977  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
978  }
979 
980  phpCAS :: traceEnd($res);
981  return $res;
982  }
983 
1003  public static function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
1004  {
1007 
1008  try {
1009  $res = self::$_PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
1010  } catch (Exception $e) {
1011  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1012  }
1013 
1014  phpCAS :: traceEnd($res);
1015  return $res;
1016  }
1017 
1019  // ########################################################################
1020  // AUTHENTICATION
1021  // ########################################################################
1038  public static function setCacheTimesForAuthRecheck($n)
1039  {
1041 
1042  try {
1043  self::$_PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
1044  } catch (Exception $e) {
1045  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1046  }
1047  }
1048 
1049 
1061  public static function setCasAttributeParserCallback($function, array $additionalArgs = array())
1062  {
1064 
1065  self::$_PHPCAS_CLIENT->setCasAttributeParserCallback($function, $additionalArgs);
1066  }
1067 
1087  public static function setPostAuthenticateCallback ($function, array $additionalArgs = array())
1088  {
1090 
1091  self::$_PHPCAS_CLIENT->setPostAuthenticateCallback($function, $additionalArgs);
1092  }
1093 
1108  public static function setSingleSignoutCallback ($function, array $additionalArgs = array())
1109  {
1111 
1112  self::$_PHPCAS_CLIENT->setSingleSignoutCallback($function, $additionalArgs);
1113  }
1114 
1125  public static function checkAuthentication()
1126  {
1129 
1130  $auth = self::$_PHPCAS_CLIENT->checkAuthentication();
1131 
1132  // store where the authentication has been checked and the result
1133  self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
1134 
1136  return $auth;
1137  }
1138 
1146  public static function forceAuthentication()
1147  {
1150  $auth = self::$_PHPCAS_CLIENT->forceAuthentication();
1151 
1152  // store where the authentication has been checked and the result
1153  self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
1154 
1155  /* if (!$auth) {
1156  phpCAS :: trace('user is not authenticated, redirecting to the CAS server');
1157  self::$_PHPCAS_CLIENT->forceAuthentication();
1158  } else {
1159  phpCAS :: trace('no need to authenticate (user `' . phpCAS :: getUser() . '\' is already authenticated)');
1160  }*/
1161 
1163  return $auth;
1164  }
1165 
1171  public static function renewAuthentication()
1172  {
1175 
1176  $auth = self::$_PHPCAS_CLIENT->renewAuthentication();
1177 
1178  // store where the authentication has been checked and the result
1179  self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
1180 
1181  //self::$_PHPCAS_CLIENT->renewAuthentication();
1183  }
1184 
1191  public static function isAuthenticated()
1192  {
1195 
1196  // call the isAuthenticated method of the $_PHPCAS_CLIENT object
1197  $auth = self::$_PHPCAS_CLIENT->isAuthenticated();
1198 
1199  // store where the authentication has been checked and the result
1200  self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
1201 
1203  return $auth;
1204  }
1205 
1213  public static function isSessionAuthenticated()
1214  {
1216 
1217  return (self::$_PHPCAS_CLIENT->isSessionAuthenticated());
1218  }
1219 
1227  public static function getUser()
1228  {
1230 
1231  try {
1232  return self::$_PHPCAS_CLIENT->getUser();
1233  } catch (Exception $e) {
1234  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1235  }
1236  }
1237 
1246  public static function getAttributes()
1247  {
1249 
1250  try {
1251  return self::$_PHPCAS_CLIENT->getAttributes();
1252  } catch (Exception $e) {
1253  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1254  }
1255  }
1256 
1265  public static function hasAttributes()
1266  {
1268 
1269  try {
1270  return self::$_PHPCAS_CLIENT->hasAttributes();
1271  } catch (Exception $e) {
1272  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1273  }
1274  }
1275 
1285  public static function hasAttribute($key)
1286  {
1288 
1289  try {
1290  return self::$_PHPCAS_CLIENT->hasAttribute($key);
1291  } catch (Exception $e) {
1292  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1293  }
1294  }
1295 
1305  public static function getAttribute($key)
1306  {
1308 
1309  try {
1310  return self::$_PHPCAS_CLIENT->getAttribute($key);
1311  } catch (Exception $e) {
1312  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1313  }
1314  }
1315 
1324  public static function handleLogoutRequests($check_client = true, $allowed_clients = array())
1325  {
1327 
1328  return (self::$_PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
1329  }
1330 
1336  public static function getServerLoginURL()
1337  {
1339 
1340  return self::$_PHPCAS_CLIENT->getServerLoginURL();
1341  }
1342 
1351  public static function setServerLoginURL($url = '')
1352  {
1355 
1356  try {
1357  self::$_PHPCAS_CLIENT->setServerLoginURL($url);
1358  } catch (Exception $e) {
1359  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1360  }
1361 
1363  }
1364 
1377  public static function setServerServiceValidateURL($url = '')
1378  {
1381 
1382  try {
1383  self::$_PHPCAS_CLIENT->setServerServiceValidateURL($url);
1384  } catch (Exception $e) {
1385  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1386  }
1387 
1389  }
1390 
1403  public static function setServerProxyValidateURL($url = '')
1404  {
1407 
1408  try {
1409  self::$_PHPCAS_CLIENT->setServerProxyValidateURL($url);
1410  } catch (Exception $e) {
1411  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1412  }
1413 
1415  }
1416 
1424  public static function setServerSamlValidateURL($url = '')
1425  {
1428 
1429  try {
1430  self::$_PHPCAS_CLIENT->setServerSamlValidateURL($url);
1431  } catch (Exception $e) {
1432  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1433  }
1434 
1436  }
1437 
1443  public static function getServerLogoutURL()
1444  {
1446 
1447  return self::$_PHPCAS_CLIENT->getServerLogoutURL();
1448  }
1449 
1458  public static function setServerLogoutURL($url = '')
1459  {
1462 
1463  try {
1464  self::$_PHPCAS_CLIENT->setServerLogoutURL($url);
1465  } catch (Exception $e) {
1466  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1467  }
1468 
1470  }
1471 
1480  public static function logout($params = "")
1481  {
1484 
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');
1489  }
1490  if (!is_array($params)) {
1491  phpCAS :: error('type mismatched for parameter $params (should be `array\')');
1492  }
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)\'');
1496  }
1497  $parsedParams[$key] = $value;
1498  }
1499  }
1500  self::$_PHPCAS_CLIENT->logout($parsedParams);
1501  // never reached
1503  }
1504 
1513  public static function logoutWithRedirectService($service)
1514  {
1517 
1518  if (!is_string($service)) {
1519  phpCAS :: error('type mismatched for parameter $service (should be `string\')');
1520  }
1521  self::$_PHPCAS_CLIENT->logout(array ( "service" => $service ));
1522  // never reached
1524  }
1525 
1536  public static function logoutWithUrl($url)
1537  {
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()');
1542  }
1543  if (!is_string($url)) {
1544  phpCAS :: error('type mismatched for parameter $url (should be `string\')');
1545  }
1546  self::$_PHPCAS_CLIENT->logout(array ( "url" => $url ));
1547  // never reached
1549  }
1550 
1563  public static function logoutWithRedirectServiceAndUrl($service, $url)
1564  {
1565  trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
1568 
1569  if (!is_string($service)) {
1570  phpCAS :: error('type mismatched for parameter $service (should be `string\')');
1571  }
1572  if (!is_string($url)) {
1573  phpCAS :: error('type mismatched for parameter $url (should be `string\')');
1574  }
1575  self::$_PHPCAS_CLIENT->logout(
1576  array (
1577  "service" => $service,
1578  "url" => $url
1579  )
1580  );
1581  // never reached
1583  }
1584 
1594  public static function setFixedCallbackURL($url = '')
1595  {
1598 
1599  try {
1600  self::$_PHPCAS_CLIENT->setCallbackURL($url);
1601  } catch (Exception $e) {
1602  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1603  }
1604 
1606  }
1607 
1616  public static function setFixedServiceURL($url)
1617  {
1620 
1621  try {
1622  self::$_PHPCAS_CLIENT->setURL($url);
1623  } catch (Exception $e) {
1624  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1625  }
1626 
1628  }
1629 
1635  public static function getServiceURL()
1636  {
1638  return (self::$_PHPCAS_CLIENT->getURL());
1639  }
1640 
1650  public static function retrievePT($target_service, & $err_code, & $err_msg)
1651  {
1653 
1654  try {
1655  return (self::$_PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
1656  } catch (Exception $e) {
1657  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1658  }
1659  }
1660 
1670  public static function setCasServerCACert($cert, $validate_cn = true)
1671  {
1674 
1675  try {
1676  self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
1677  } catch (Exception $e) {
1678  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1679  }
1680 
1682  }
1683 
1689  public static function setNoCasServerValidation()
1690  {
1693 
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();
1697  }
1698 
1699 
1709  public static function setNoClearTicketsFromUrl()
1710  {
1713 
1714  self::$_PHPCAS_CLIENT->setNoClearTicketsFromUrl();
1716  }
1717 
1729  public static function setExtraCurlOption($key, $value)
1730  {
1733 
1734  self::$_PHPCAS_CLIENT->setExtraCurlOption($key, $value);
1736  }
1737 
1752  public static function setSessionIdSalt($salt) {
1755  self::$_PHPCAS_CLIENT->setSessionIdSalt($salt);
1757  }
1758 
1795  public static function allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
1796  {
1799 
1800  if (self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_2_0
1801  && self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_3_0
1802  ) {
1803  phpCAS :: error('this method can only be used with the cas 2.0/3.0 protocols');
1804  }
1805  self::$_PHPCAS_CLIENT->getAllowedProxyChains()->allowProxyChain($proxy_chain);
1807  }
1808 
1818  public static function getProxies ()
1819  {
1821 
1822  return(self::$_PHPCAS_CLIENT->getProxies());
1823  }
1824 
1825  // ########################################################################
1826  // PGTIOU/PGTID and logoutRequest rebroadcasting
1827  // ########################################################################
1828 
1837  public static function addRebroadcastNode($rebroadcastNodeUrl)
1838  {
1840  phpCAS::log('rebroadcastNodeUrl:'.$rebroadcastNodeUrl);
1842 
1843  try {
1844  self::$_PHPCAS_CLIENT->addRebroadcastNode($rebroadcastNodeUrl);
1845  } catch (Exception $e) {
1846  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1847  }
1848 
1849  phpCAS::traceEnd();
1850  }
1851 
1860  public static function addRebroadcastHeader($header)
1861  {
1864 
1865  try {
1866  self::$_PHPCAS_CLIENT->addRebroadcastHeader($header);
1867  } catch (Exception $e) {
1868  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1869  }
1870 
1872  }
1873 
1881  private static function _validateClientExists()
1882  {
1883  if (!is_object(self::$_PHPCAS_CLIENT)) {
1885  }
1886  }
1887 
1895  private static function _validateProxyExists()
1896  {
1897  if (!is_object(self::$_PHPCAS_CLIENT)) {
1899  }
1900  }
1901 
1905  public static function getCasClient()
1906  {
1907  return self::$_PHPCAS_CLIENT;
1908  }
1909 
1915  public static function setCasClient(\CAS_Client $client)
1916  {
1917  self::$_PHPCAS_CLIENT = $client;
1918  }
1919 }
1920 // ########################################################################
1921 // DOCUMENTATION
1922 // ########################################################################
1923 
1924 // ########################################################################
1925 // MAIN PAGE
1926 
1934 // ########################################################################
1935 // MODULES DEFINITION
1936 
2019 // ########################################################################
2020 // EXAMPLES
2021 
static forceAuthentication()
Definition: CAS.php:1146
static serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
Definition: CAS.php:1003
gettmpdir()
Definition: CAS.php:251
static getCasClient()
Definition: CAS.php:1905
static serviceWeb($url, & $err_code, & $output)
Definition: CAS.php:969
static logoutWithUrl($url)
Definition: CAS.php:1536
static getUser()
Definition: CAS.php:1227
const CAS_VERSION_1_0
Definition: CAS.php:74
Definition: CAS.php:281
static getAttribute($key)
Definition: CAS.php:1305
static $_PHPCAS_INIT_CALL
Definition: CAS.php:299
static setNoClearTicketsFromUrl()
Definition: CAS.php:1709
static error($msg)
Definition: CAS.php:580
static isInitialized()
Definition: CAS.php:425
static traceExit()
Definition: CAS.php:697
const SAML_VERSION_1_1
Definition: CAS.php:91
static $_PHPCAS_VERBOSE
Definition: CAS.php:316
const CAS_VERSION_3_0
Definition: CAS.php:82
static handleLogoutRequests($check_client=true, $allowed_clients=array())
Definition: CAS.php:1324
static setCacheTimesForAuthRecheck($n)
Definition: CAS.php:1038
static setCasAttributeParserCallback($function, array $additionalArgs=array())
Definition: CAS.php:1061
static addRebroadcastNode($rebroadcastNodeUrl)
Definition: CAS.php:1837
static allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
Definition: CAS.php:1795
static setFixedCallbackURL($url='')
Definition: CAS.php:1594
static getProxies()
Definition: CAS.php:1818
static proxy($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true, \SessionHandlerInterface $sessionHandler=null)
Definition: CAS.php:391
const DEFAULT_ERROR
Definition: CAS.php:142
static getAttributes()
Definition: CAS.php:1246
static traceEnd($res='')
Definition: CAS.php:675
static trace($str)
Definition: CAS.php:616
static getServiceURL()
Definition: CAS.php:1635
static logoutWithRedirectServiceAndUrl($service, $url)
Definition: CAS.php:1563
static log($str)
Definition: CAS.php:540
static checkAuthentication()
Definition: CAS.php:1125
static setHTMLFooter($footer)
Definition: CAS.php:805
static client($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true, \SessionHandlerInterface $sessionHandler=null)
Definition: CAS.php:345
static getProxiedService($type)
Definition: CAS.php:916
static setServerLoginURL($url='')
Definition: CAS.php:1351
static setLang($lang)
Definition: CAS.php:725
static setServerSamlValidateURL($url='')
Definition: CAS.php:1424
static getSupportedProtocols()
Definition: CAS.php:760
static setSessionIdSalt($salt)
Definition: CAS.php:1752
static setHTMLHeader($header)
Definition: CAS.php:787
static initializeProxiedService(CAS_ProxiedService $proxiedService)
Definition: CAS.php:943
static setServerServiceValidateURL($url='')
Definition: CAS.php:1377
static setLogger($logger=null)
Definition: CAS.php:448
const PHPCAS_LANG_ENGLISH
Definition: CAS.php:215
static isSessionAuthenticated()
Definition: CAS.php:1213
static setSingleSignoutCallback($function, array $additionalArgs=array())
Definition: CAS.php:1108
$driver_options
static setPGTStorageDb($dsn_or_pdo, $username='', $password='', $table='', $driver_options=null)
Definition: CAS.php:863
const CAS_VERSION_2_0
Definition: CAS.php:78
static getVerbose()
Definition: CAS.php:527
static setPostAuthenticateCallback($function, array $additionalArgs=array())
Definition: CAS.php:1087
static getVersion()
Definition: CAS.php:750
static setExtraCurlOption($key, $value)
Definition: CAS.php:1729
static setServerProxyValidateURL($url='')
Definition: CAS.php:1403
static logout($params="")
Definition: CAS.php:1480
static setFixedServiceURL($url)
Definition: CAS.php:1616
const DEFAULT_DEBUG_DIR
Definition: CAS.php:257
static setCasServerCACert($cert, $validate_cn=true)
Definition: CAS.php:1670
static renewAuthentication()
Definition: CAS.php:1171
const PHPCAS_VERSION(!isset($_SERVER['REQUEST_URI']) &&isset($_SERVER['SCRIPT_NAME']) &&isset($_SERVER['QUERY_STRING']))
Definition: CAS.php:60
static setVerbose($verbose)
Definition: CAS.php:512
static _validateProxyExists()
Definition: CAS.php:1895
static isAuthenticated()
Definition: CAS.php:1191
static logoutWithRedirectService($service)
Definition: CAS.php:1513
static traceBegin()
Definition: CAS.php:628
static retrievePT($target_service, & $err_code, & $err_msg)
Definition: CAS.php:1650
static setDebug($filename='')
Definition: CAS.php:468
static setPGTStorage($storage)
Definition: CAS.php:833
static setServerLogoutURL($url='')
Definition: CAS.php:1458
static getServerLogoutURL()
Definition: CAS.php:1443
static setPGTStorageFile($path='')
Definition: CAS.php:885
static setCasClient(\CAS_Client $client)
Definition: CAS.php:1915
if(isset($_REQUEST['logout'])) if(isset($_REQUEST['login'])) $auth
static _validateClientExists()
Definition: CAS.php:1881
static setNoCasServerValidation()
Definition: CAS.php:1689
static addRebroadcastHeader($header)
Definition: CAS.php:1860
static $_PHPCAS_DEBUG
Definition: CAS.php:307
static hasAttributes()
Definition: CAS.php:1265
static hasAttribute($key)
Definition: CAS.php:1285
static $_PHPCAS_CLIENT
Definition: CAS.php:290
static getServerLoginURL()
Definition: CAS.php:1336