ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
CAS.php
Go to the documentation of this file.
1 <?php
2 
39 //
40 // hack by Vangelis Haniotakis to handle the absence of $_SERVER['REQUEST_URI']
41 // in IIS
42 //
43 if (!isset($_SERVER['REQUEST_URI']) && isset($_SERVER['SCRIPT_NAME']) && isset($_SERVER['QUERY_STRING'])) {
44  $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
45 }
46 
47 // Add a E_USER_DEPRECATED for php versions <= 5.2
48 if (!defined('E_USER_DEPRECATED')) {
49  define('E_USER_DEPRECATED', E_USER_NOTICE);
50 }
51 
52 
53 // ########################################################################
54 // CONSTANTS
55 // ########################################################################
56 
57 // ------------------------------------------------------------------------
58 // CAS VERSIONS
59 // ------------------------------------------------------------------------
60 
64 define('PHPCAS_VERSION', '1.3.5');
65 
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 
234 define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);
235 
237 // ------------------------------------------------------------------------
238 // DEBUG
239 // ------------------------------------------------------------------------
248 function gettmpdir() {
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']); }
252 return "/tmp";
253 }
254 define('DEFAULT_DEBUG_DIR', gettmpdir()."/");
255 
258 // include the class autoloader
259 require_once dirname(__FILE__) . '/CAS/Autoload.php';
260 
278 class phpCAS
279 {
280 
287  private static $_PHPCAS_CLIENT;
288 
295  private static $_PHPCAS_INIT_CALL;
296 
302  private static $_PHPCAS_DEBUG;
303 
311  private static $_PHPCAS_VERBOSE = false;
312 
313 
314  // ########################################################################
315  // INITIALIZATION
316  // ########################################################################
317 
338  public static function client($server_version, $server_hostname,
339  $server_port, $server_uri, $changeSessionID = true
340  ) {
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'] . ')');
344  }
345 
346  // store where the initializer is called from
347  $dbg = debug_backtrace();
348  self::$_PHPCAS_INIT_CALL = array (
349  'done' => true,
350  'file' => $dbg[0]['file'],
351  'line' => $dbg[0]['line'],
352  'method' => __CLASS__ . '::' . __FUNCTION__
353  );
354 
355  // initialize the object $_PHPCAS_CLIENT
356  try {
357  self::$_PHPCAS_CLIENT = new CAS_Client(
358  $server_version, false, $server_hostname, $server_port, $server_uri,
359  $changeSessionID
360  );
361  } catch (Exception $e) {
362  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
363  }
365  }
366 
382  public static function proxy($server_version, $server_hostname,
383  $server_port, $server_uri, $changeSessionID = true
384  ) {
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'] . ')');
388  }
389 
390  // store where the initialzer is called from
391  $dbg = debug_backtrace();
392  self::$_PHPCAS_INIT_CALL = array (
393  'done' => true,
394  'file' => $dbg[0]['file'],
395  'line' => $dbg[0]['line'],
396  'method' => __CLASS__ . '::' . __FUNCTION__
397  );
398 
399  // initialize the object $_PHPCAS_CLIENT
400  try {
401  self::$_PHPCAS_CLIENT = new CAS_Client(
402  $server_version, true, $server_hostname, $server_port, $server_uri,
403  $changeSessionID
404  );
405  } catch (Exception $e) {
406  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
407  }
409  }
410 
416  public static function isInitialized ()
417  {
418  return (is_object(self::$_PHPCAS_CLIENT));
419  }
420 
422  // ########################################################################
423  // DEBUGGING
424  // ########################################################################
425 
439  public static function setDebug($filename = '')
440  {
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)');
443  }
444  if ($filename === false) {
445  self::$_PHPCAS_DEBUG['filename'] = false;
446 
447  } else {
448  if (empty ($filename)) {
449  if (preg_match('/^Win.*/', getenv('OS'))) {
450  if (isset ($_ENV['TMP'])) {
451  $debugDir = $_ENV['TMP'] . '/';
452  } else {
453  $debugDir = '';
454  }
455  } else {
456  $debugDir = DEFAULT_DEBUG_DIR;
457  }
458  $filename = $debugDir . 'phpCAS.log';
459  }
460 
461  if (empty (self::$_PHPCAS_DEBUG['unique_id'])) {
462  self::$_PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4);
463  }
464 
465  self::$_PHPCAS_DEBUG['filename'] = $filename;
466  self::$_PHPCAS_DEBUG['indent'] = 0;
467 
468  phpCAS :: trace('START ('.date("Y-m-d H:i:s").') phpCAS-' . PHPCAS_VERSION . ' ******************');
469  }
470  }
471 
481  public static function setVerbose($verbose)
482  {
483  if ($verbose === true) {
484  self::$_PHPCAS_VERBOSE = true;
485  } else {
486  self::$_PHPCAS_VERBOSE = false;
487  }
488  }
489 
490 
496  public static function getVerbose()
497  {
498  return self::$_PHPCAS_VERBOSE;
499  }
500 
509  public static function log($str)
510  {
511  $indent_str = ".";
512 
513 
514  if (!empty(self::$_PHPCAS_DEBUG['filename'])) {
515  // Check if file exists and modifiy file permissions to be only
516  // readable by the webserver
517  if (!file_exists(self::$_PHPCAS_DEBUG['filename'])) {
518  touch(self::$_PHPCAS_DEBUG['filename']);
519  // Chmod will fail on windows
520  @chmod(self::$_PHPCAS_DEBUG['filename'], 0600);
521  }
522  for ($i = 0; $i < self::$_PHPCAS_DEBUG['indent']; $i++) {
523 
524  $indent_str .= '| ';
525  }
526  // allow for multiline output with proper identing. Usefull for
527  // dumping cas answers etc.
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']);
530  }
531 
532  }
533 
543  public static function error($msg)
544  {
546  $dbg = debug_backtrace();
547  $function = '?';
548  $file = '?';
549  $line = '?';
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'];
557  }
558  }
559  }
560  }
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";
563  } else {
564  echo "<br />\n<b>Error</b>: <font color=\"FF0000\"><b>". DEFAULT_ERROR ."</b><br />\n";
565  }
566  phpCAS :: trace($msg . ' in ' . $file . 'on line ' . $line );
568 
569  throw new CAS_GracefullTerminationException(__CLASS__ . "::" . $function . '(): ' . $msg);
570  }
571 
579  public static function trace($str)
580  {
581  $dbg = debug_backtrace();
582  phpCAS :: log($str . ' [' . basename($dbg[0]['file']) . ':' . $dbg[0]['line'] . ']');
583  }
584 
591  public static function traceBegin()
592  {
593  $dbg = debug_backtrace();
594  $str = '=> ';
595  if (!empty ($dbg[1]['class'])) {
596  $str .= $dbg[1]['class'] . '::';
597  }
598  $str .= $dbg[1]['function'] . '(';
599  if (is_array($dbg[1]['args'])) {
600  foreach ($dbg[1]['args'] as $index => $arg) {
601  if ($index != 0) {
602  $str .= ', ';
603  }
604  if (is_object($arg)) {
605  $str .= get_class($arg);
606  } else {
607  $str .= str_replace(array("\r\n", "\n", "\r"), "", var_export($arg, true));
608  }
609  }
610  }
611  if (isset($dbg[1]['file'])) {
612  $file = basename($dbg[1]['file']);
613  } else {
614  $file = 'unknown_file';
615  }
616  if (isset($dbg[1]['line'])) {
617  $line = $dbg[1]['line'];
618  } else {
619  $line = 'unknown_line';
620  }
621  $str .= ') [' . $file . ':' . $line . ']';
622  phpCAS :: log($str);
623  if (!isset(self::$_PHPCAS_DEBUG['indent'])) {
624  self::$_PHPCAS_DEBUG['indent'] = 0;
625  } else {
626  self::$_PHPCAS_DEBUG['indent']++;
627  }
628  }
629 
638  public static function traceEnd($res = '')
639  {
640  if (empty(self::$_PHPCAS_DEBUG['indent'])) {
641  self::$_PHPCAS_DEBUG['indent'] = 0;
642  } else {
643  self::$_PHPCAS_DEBUG['indent']--;
644  }
645  $dbg = debug_backtrace();
646  $str = '';
647  if (is_object($res)) {
648  $str .= '<= ' . get_class($res);
649  } else {
650  $str .= '<= ' . str_replace(array("\r\n", "\n", "\r"), "", var_export($res, true));
651  }
652 
653  phpCAS :: log($str);
654  }
655 
661  public static function traceExit()
662  {
663  phpCAS :: log('exit()');
664  while (self::$_PHPCAS_DEBUG['indent'] > 0) {
665  phpCAS :: log('-');
666  self::$_PHPCAS_DEBUG['indent']--;
667  }
668  }
669 
671  // ########################################################################
672  // INTERNATIONALIZATION
673  // ########################################################################
689  public static function setLang($lang)
690  {
692 
693  try {
694  self::$_PHPCAS_CLIENT->setLang($lang);
695  } catch (Exception $e) {
696  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
697  }
698  }
699 
701  // ########################################################################
702  // VERSION
703  // ########################################################################
714  public static function getVersion()
715  {
716  return PHPCAS_VERSION;
717  }
718 
720  // ########################################################################
721  // HTML OUTPUT
722  // ########################################################################
735  public static function setHTMLHeader($header)
736  {
738 
739  try {
740  self::$_PHPCAS_CLIENT->setHTMLHeader($header);
741  } catch (Exception $e) {
742  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
743  }
744  }
745 
753  public static function setHTMLFooter($footer)
754  {
756 
757  try {
758  self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
759  } catch (Exception $e) {
760  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
761  }
762  }
763 
765  // ########################################################################
766  // PGT STORAGE
767  // ########################################################################
781  public static function setPGTStorage($storage)
782  {
785 
786  try {
787  self::$_PHPCAS_CLIENT->setPGTStorage($storage);
788  } catch (Exception $e) {
789  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
790  }
792  }
793 
811  public static function setPGTStorageDb($dsn_or_pdo, $username='',
812  $password='', $table='', $driver_options=null
813  ) {
816 
817  try {
818  self::$_PHPCAS_CLIENT->setPGTStorageDb($dsn_or_pdo, $username, $password, $table, $driver_options);
819  } catch (Exception $e) {
820  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
821  }
823  }
824 
833  public static function setPGTStorageFile($path = '')
834  {
837 
838  try {
839  self::$_PHPCAS_CLIENT->setPGTStorageFile($path);
840  } catch (Exception $e) {
841  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
842  }
844  }
846  // ########################################################################
847  // ACCESS TO EXTERNAL SERVICES
848  // ########################################################################
864  public static function getProxiedService ($type)
865  {
868 
869  try {
870  $res = self::$_PHPCAS_CLIENT->getProxiedService($type);
871  } catch (Exception $e) {
872  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
873  }
874 
876  return $res;
877  }
878 
891  public static function initializeProxiedService (CAS_ProxiedService $proxiedService)
892  {
894 
895  try {
896  self::$_PHPCAS_CLIENT->initializeProxiedService($proxiedService);
897  } catch (Exception $e) {
898  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
899  }
900  }
901 
917  public static function serviceWeb($url, & $err_code, & $output)
918  {
921 
922  try {
923  $res = self::$_PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
924  } catch (Exception $e) {
925  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
926  }
927 
929  return $res;
930  }
931 
951  public static function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
952  {
955 
956  try {
957  $res = self::$_PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
958  } catch (Exception $e) {
959  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
960  }
961 
963  return $res;
964  }
965 
967  // ########################################################################
968  // AUTHENTICATION
969  // ########################################################################
986  public static function setCacheTimesForAuthRecheck($n)
987  {
989 
990  try {
991  self::$_PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
992  } catch (Exception $e) {
993  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
994  }
995  }
996 
997 
1009  public static function setCasAttributeParserCallback($function, array $additionalArgs = array())
1010  {
1012 
1013  self::$_PHPCAS_CLIENT->setCasAttributeParserCallback($function, $additionalArgs);
1014  }
1015 
1035  public static function setPostAuthenticateCallback ($function, array $additionalArgs = array())
1036  {
1038 
1039  self::$_PHPCAS_CLIENT->setPostAuthenticateCallback($function, $additionalArgs);
1040  }
1041 
1056  public static function setSingleSignoutCallback ($function, array $additionalArgs = array())
1057  {
1059 
1060  self::$_PHPCAS_CLIENT->setSingleSignoutCallback($function, $additionalArgs);
1061  }
1062 
1073  public static function checkAuthentication()
1074  {
1077 
1078  $auth = self::$_PHPCAS_CLIENT->checkAuthentication();
1079 
1080  // store where the authentication has been checked and the result
1081  self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
1082 
1084  return $auth;
1085  }
1086 
1094  public static function forceAuthentication()
1095  {
1098  $auth = self::$_PHPCAS_CLIENT->forceAuthentication();
1099 
1100  // store where the authentication has been checked and the result
1101  self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
1102 
1103  /* if (!$auth) {
1104  phpCAS :: trace('user is not authenticated, redirecting to the CAS server');
1105  self::$_PHPCAS_CLIENT->forceAuthentication();
1106  } else {
1107  phpCAS :: trace('no need to authenticate (user `' . phpCAS :: getUser() . '\' is already authenticated)');
1108  }*/
1109 
1111  return $auth;
1112  }
1113 
1119  public static function renewAuthentication()
1120  {
1123 
1124  $auth = self::$_PHPCAS_CLIENT->renewAuthentication();
1125 
1126  // store where the authentication has been checked and the result
1127  self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
1128 
1129  //self::$_PHPCAS_CLIENT->renewAuthentication();
1131  }
1132 
1139  public static function isAuthenticated()
1140  {
1143 
1144  // call the isAuthenticated method of the $_PHPCAS_CLIENT object
1145  $auth = self::$_PHPCAS_CLIENT->isAuthenticated();
1146 
1147  // store where the authentication has been checked and the result
1148  self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
1149 
1151  return $auth;
1152  }
1153 
1161  public static function isSessionAuthenticated()
1162  {
1164 
1165  return (self::$_PHPCAS_CLIENT->isSessionAuthenticated());
1166  }
1167 
1175  public static function getUser()
1176  {
1178 
1179  try {
1180  return self::$_PHPCAS_CLIENT->getUser();
1181  } catch (Exception $e) {
1182  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1183  }
1184  }
1185 
1194  public static function getAttributes()
1195  {
1197 
1198  try {
1199  return self::$_PHPCAS_CLIENT->getAttributes();
1200  } catch (Exception $e) {
1201  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1202  }
1203  }
1204 
1213  public static function hasAttributes()
1214  {
1216 
1217  try {
1218  return self::$_PHPCAS_CLIENT->hasAttributes();
1219  } catch (Exception $e) {
1220  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1221  }
1222  }
1223 
1233  public static function hasAttribute($key)
1234  {
1236 
1237  try {
1238  return self::$_PHPCAS_CLIENT->hasAttribute($key);
1239  } catch (Exception $e) {
1240  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1241  }
1242  }
1243 
1253  public static function getAttribute($key)
1254  {
1256 
1257  try {
1258  return self::$_PHPCAS_CLIENT->getAttribute($key);
1259  } catch (Exception $e) {
1260  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1261  }
1262  }
1263 
1272  public static function handleLogoutRequests($check_client = true, $allowed_clients = false)
1273  {
1275 
1276  return (self::$_PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
1277  }
1278 
1285  public static function getServerLoginURL()
1286  {
1288 
1289  return self::$_PHPCAS_CLIENT->getServerLoginURL();
1290  }
1291 
1300  public static function setServerLoginURL($url = '')
1301  {
1304 
1305  try {
1306  self::$_PHPCAS_CLIENT->setServerLoginURL($url);
1307  } catch (Exception $e) {
1308  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1309  }
1310 
1312  }
1313 
1326  public static function setServerServiceValidateURL($url = '')
1327  {
1330 
1331  try {
1332  self::$_PHPCAS_CLIENT->setServerServiceValidateURL($url);
1333  } catch (Exception $e) {
1334  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1335  }
1336 
1338  }
1339 
1352  public static function setServerProxyValidateURL($url = '')
1353  {
1356 
1357  try {
1358  self::$_PHPCAS_CLIENT->setServerProxyValidateURL($url);
1359  } catch (Exception $e) {
1360  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1361  }
1362 
1364  }
1365 
1373  public static function setServerSamlValidateURL($url = '')
1374  {
1377 
1378  try {
1379  self::$_PHPCAS_CLIENT->setServerSamlValidateURL($url);
1380  } catch (Exception $e) {
1381  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1382  }
1383 
1385  }
1386 
1393  public static function getServerLogoutURL()
1394  {
1396 
1397  return self::$_PHPCAS_CLIENT->getServerLogoutURL();
1398  }
1399 
1408  public static function setServerLogoutURL($url = '')
1409  {
1412 
1413  try {
1414  self::$_PHPCAS_CLIENT->setServerLogoutURL($url);
1415  } catch (Exception $e) {
1416  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1417  }
1418 
1420  }
1421 
1430  public static function logout($params = "")
1431  {
1434 
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');
1439  }
1440  if (!is_array($params)) {
1441  phpCAS :: error('type mismatched for parameter $params (should be `array\')');
1442  }
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)\'');
1446  }
1447  $parsedParams[$key] = $value;
1448  }
1449  }
1450  self::$_PHPCAS_CLIENT->logout($parsedParams);
1451  // never reached
1453  }
1454 
1463  public static function logoutWithRedirectService($service)
1464  {
1467 
1468  if (!is_string($service)) {
1469  phpCAS :: error('type mismatched for parameter $service (should be `string\')');
1470  }
1471  self::$_PHPCAS_CLIENT->logout(array ( "service" => $service ));
1472  // never reached
1474  }
1475 
1486  public static function logoutWithUrl($url)
1487  {
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()');
1492  }
1493  if (!is_string($url)) {
1494  phpCAS :: error('type mismatched for parameter $url (should be `string\')');
1495  }
1496  self::$_PHPCAS_CLIENT->logout(array ( "url" => $url ));
1497  // never reached
1499  }
1500 
1514  {
1515  trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
1518 
1519  if (!is_string($service)) {
1520  phpCAS :: error('type mismatched for parameter $service (should be `string\')');
1521  }
1522  if (!is_string($url)) {
1523  phpCAS :: error('type mismatched for parameter $url (should be `string\')');
1524  }
1525  self::$_PHPCAS_CLIENT->logout(
1526  array (
1527  "service" => $service,
1528  "url" => $url
1529  )
1530  );
1531  // never reached
1533  }
1534 
1544  public static function setFixedCallbackURL($url = '')
1545  {
1548 
1549  try {
1550  self::$_PHPCAS_CLIENT->setCallbackURL($url);
1551  } catch (Exception $e) {
1552  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1553  }
1554 
1556  }
1557 
1566  public static function setFixedServiceURL($url)
1567  {
1570 
1571  try {
1572  self::$_PHPCAS_CLIENT->setURL($url);
1573  } catch (Exception $e) {
1574  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1575  }
1576 
1578  }
1579 
1585  public static function getServiceURL()
1586  {
1588  return (self::$_PHPCAS_CLIENT->getURL());
1589  }
1590 
1600  public static function retrievePT($target_service, & $err_code, & $err_msg)
1601  {
1603 
1604  try {
1605  return (self::$_PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
1606  } catch (Exception $e) {
1607  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1608  }
1609  }
1610 
1620  public static function setCasServerCACert($cert, $validate_cn = true)
1621  {
1624 
1625  try {
1626  self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
1627  } catch (Exception $e) {
1628  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1629  }
1630 
1632  }
1633 
1639  public static function setNoCasServerValidation()
1640  {
1643 
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();
1647  }
1648 
1649 
1659  public static function setNoClearTicketsFromUrl()
1660  {
1663 
1664  self::$_PHPCAS_CLIENT->setNoClearTicketsFromUrl();
1666  }
1667 
1679  public static function setExtraCurlOption($key, $value)
1680  {
1683 
1684  self::$_PHPCAS_CLIENT->setExtraCurlOption($key, $value);
1686  }
1687 
1724  public static function allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
1725  {
1728 
1729  if (self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_2_0
1730  && self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_3_0
1731  ) {
1732  phpCAS :: error('this method can only be used with the cas 2.0/3.0 protocols');
1733  }
1734  self::$_PHPCAS_CLIENT->getAllowedProxyChains()->allowProxyChain($proxy_chain);
1736  }
1737 
1747  public static function getProxies ()
1748  {
1750 
1751  return(self::$_PHPCAS_CLIENT->getProxies());
1752  }
1753 
1754  // ########################################################################
1755  // PGTIOU/PGTID and logoutRequest rebroadcasting
1756  // ########################################################################
1757 
1766  public static function addRebroadcastNode($rebroadcastNodeUrl)
1767  {
1769  phpCAS::log('rebroadcastNodeUrl:'.$rebroadcastNodeUrl);
1771 
1772  try {
1773  self::$_PHPCAS_CLIENT->addRebroadcastNode($rebroadcastNodeUrl);
1774  } catch (Exception $e) {
1775  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1776  }
1777 
1778  phpCAS::traceEnd();
1779  }
1780 
1789  public static function addRebroadcastHeader($header)
1790  {
1793 
1794  try {
1795  self::$_PHPCAS_CLIENT->addRebroadcastHeader($header);
1796  } catch (Exception $e) {
1797  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1798  }
1799 
1801  }
1802 
1810  private static function _validateClientExists()
1811  {
1812  if (!is_object(self::$_PHPCAS_CLIENT)) {
1814  }
1815  }
1816 
1824  private static function _validateProxyExists()
1825  {
1826  if (!is_object(self::$_PHPCAS_CLIENT)) {
1828  }
1829  }
1830 
1836  public static function setCasClient(\CAS_Client $client)
1837  {
1838  self::$_PHPCAS_CLIENT = $client;
1839  }
1840 }
1841 // ########################################################################
1842 // DOCUMENTATION
1843 // ########################################################################
1844 
1845 // ########################################################################
1846 // MAIN PAGE
1847 
1855 // ########################################################################
1856 // MODULES DEFINITION
1857 
1940 // ########################################################################
1941 // EXAMPLES
1942 
1994 ?>
$params
Definition: disable.php:11
$auth
Definition: metadata.php:48
static forceAuthentication()
This method is called to force authentication if the user was not already authenticated.
Definition: CAS.php:1094
static serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
This method is used to access an IMAP/POP3/NNTP service.
Definition: CAS.php:951
gettmpdir()
The default directory for the debug file under Unix.
Definition: CAS.php:248
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
An interface for classes that define a list of allowed proxies in front of the current application...
Definition: Interface.php:41
static serviceWeb($url, & $err_code, & $output)
This method is used to access an HTTP[S] service.
Definition: CAS.php:917
static logoutWithUrl($url)
This method is used to logout from CAS.
Definition: CAS.php:1486
static getUser()
This method returns the CAS user&#39;s login name.
Definition: CAS.php:1175
The phpCAS class is a simple container for the phpCAS library.
Definition: CAS.php:278
static getAttribute($key)
Answer an attribute for the authenticated user.
Definition: CAS.php:1253
$type
static $_PHPCAS_INIT_CALL
This variable is used to store where the initializer is called from (to print a comprehensive error i...
Definition: CAS.php:295
static setNoClearTicketsFromUrl()
Disable the removal of a CAS-Ticket from the URL when authenticating DISABLING POSES A SECURITY RISK:...
Definition: CAS.php:1659
static error($msg)
This method is used by interface methods to print an error and where the function was originally call...
Definition: CAS.php:543
static isInitialized()
Answer whether or not the client or proxy has been initialized.
Definition: CAS.php:416
static traceExit()
This method is used to indicate the end of the execution of the program.
Definition: CAS.php:661
static $_PHPCAS_VERBOSE
This variable is used to enable verbose mode This pevents debug info to be show to the user...
Definition: CAS.php:311
$client
Definition: resume.php:9
const CAS_VERSION_3_0
CAS version 3.0.
Definition: CAS.php:82
$verbose
static setCacheTimesForAuthRecheck($n)
Set the times authentication will be cached before really accessing the CAS server in gateway mode: ...
Definition: CAS.php:986
static setCasAttributeParserCallback($function, array $additionalArgs=array())
Set a callback function to be run when receiving CAS attributes.
Definition: CAS.php:1009
static addRebroadcastNode($rebroadcastNodeUrl)
Add a pgtIou/pgtId and logoutRequest rebroadcast node.
Definition: CAS.php:1766
static allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
If you want your service to be proxied you have to enable it (default disabled) and define an accepab...
Definition: CAS.php:1724
static setFixedCallbackURL($url='')
Set the fixed URL that will be used by the CAS server to transmit the PGT.
Definition: CAS.php:1544
static getProxies()
Answer an array of proxies that are sitting in front of this application.
Definition: CAS.php:1747
const DEFAULT_ERROR
SAML Attributes.
Definition: CAS.php:142
$index
Definition: metadata.php:60
This interface defines methods that allow proxy-authenticated service handlers to interact with phpCA...
$service
Definition: login.php:15
static getAttributes()
Answer attributes about the authenticated user.
Definition: CAS.php:1194
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:638
static trace($str)
This method is used to log something in debug mode.
Definition: CAS.php:579
static getServiceURL()
Get the URL that is set as the CAS service parameter.
Definition: CAS.php:1585
static logoutWithRedirectServiceAndUrl($service, $url)
This method is used to logout from CAS.
Definition: CAS.php:1513
static log($str)
Logs a string in debug mode.
Definition: CAS.php:509
static checkAuthentication()
This method is called to check if the user is already authenticated locally or has a global cas sessi...
Definition: CAS.php:1073
static setHTMLFooter($footer)
This method sets the HTML footer used for all outputs.
Definition: CAS.php:753
static getProxiedService($type)
Answer a proxy-authenticated service handler.
Definition: CAS.php:864
$password
Definition: pwgen.php:17
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
foreach($_POST as $key=> $value) $res
static setServerLoginURL($url='')
Set the login URL of the CAS server.
Definition: CAS.php:1300
static setLang($lang)
This method is used to set the language used by phpCAS.
Definition: CAS.php:689
static setServerSamlValidateURL($url='')
Set the samlValidate URL of the CAS server.
Definition: CAS.php:1373
static setHTMLHeader($header)
This method sets the HTML header used for all outputs.
Definition: CAS.php:735
static initializeProxiedService(CAS_ProxiedService $proxiedService)
Initialize a proxied-service handler with the proxy-ticket it should use.
Definition: CAS.php:891
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
static setServerServiceValidateURL($url='')
Set the serviceValidate URL of the CAS server.
Definition: CAS.php:1326
const PHPCAS_LANG_ENGLISH
Definition: CAS.php:215
static proxy($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true)
phpCAS proxy initializer.
Definition: CAS.php:382
static isSessionAuthenticated()
Checks whether authenticated based on $_SESSION.
Definition: CAS.php:1161
static setSingleSignoutCallback($function, array $additionalArgs=array())
Set a callback function to be run when a single-signout request is received.
Definition: CAS.php:1056
static setPGTStorageDb($dsn_or_pdo, $username='', $password='', $table='', $driver_options=null)
This method is used to tell phpCAS to store the response of the CAS server to PGT requests in a datab...
Definition: CAS.php:811
const CAS_VERSION_2_0
Definition: CAS.php:78
static getVerbose()
Show is verbose mode is on.
Definition: CAS.php:496
$n
Definition: RandomTest.php:85
static setPostAuthenticateCallback($function, array $additionalArgs=array())
Set a callback function to be run when a user authenticates.
Definition: CAS.php:1035
static getVersion()
This method returns the phpCAS version.
Definition: CAS.php:714
static setExtraCurlOption($key, $value)
Change CURL options.
Definition: CAS.php:1679
static handleLogoutRequests($check_client=true, $allowed_clients=false)
Handle logout requests.
Definition: CAS.php:1272
static setServerProxyValidateURL($url='')
Set the proxyValidate URL of the CAS server.
Definition: CAS.php:1352
Create styles array
The data for the language used.
static logout($params="")
This method is used to logout from CAS.
Definition: CAS.php:1430
static setFixedServiceURL($url)
Set the fixed URL that will be set as the CAS service parameter.
Definition: CAS.php:1566
const DEFAULT_DEBUG_DIR
Definition: CAS.php:254
static setCasServerCACert($cert, $validate_cn=true)
Set the certificate of the CAS server CA and if the CN should be properly verified.
Definition: CAS.php:1620
static renewAuthentication()
This method is called to renew the authentication.
Definition: CAS.php:1119
static setVerbose($verbose)
Enable verbose errors messages in the website output This is a security relevant since internal statu...
Definition: CAS.php:481
static _validateProxyExists()
Checks of a proxy client aready exists.
Definition: CAS.php:1824
static isAuthenticated()
This method is called to check if the user is authenticated (previously or by tickets given in the UR...
Definition: CAS.php:1139
static logoutWithRedirectService($service)
This method is used to logout from CAS.
Definition: CAS.php:1463
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
Definition: CAS.php:591
static retrievePT($target_service, & $err_code, & $err_msg)
Retrieve a Proxy Ticket from the CAS server.
Definition: CAS.php:1600
static setDebug($filename='')
Set/unset debug mode.
Definition: CAS.php:439
static setPGTStorage($storage)
This method can be used to set a custom PGT storage object.
Definition: CAS.php:781
static setServerLogoutURL($url='')
Set the logout URL of the CAS server.
Definition: CAS.php:1408
const PHPCAS_VERSION(!defined('E_USER_DEPRECATED'))
phpCAS version.
Definition: CAS.php:64
$function
Definition: cas.php:28
$i
Definition: disco.tpl.php:19
The CAS_Client class is a client interface that provides CAS authentication to PHP applications...
Definition: Client.php:51
static getServerLogoutURL()
This method returns the URL to be used to login.
Definition: CAS.php:1393
static setPGTStorageFile($path='')
This method is used to tell phpCAS to store the response of the CAS server to PGT requests onto the f...
Definition: CAS.php:833
static setCasClient(\CAS_Client $client)
For testing purposes, use this method to set the client to a test double.
Definition: CAS.php:1836
$url
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static _validateClientExists()
Checks if a client already exists.
Definition: CAS.php:1810
if(empty($password)) $table
Definition: pwgen.php:24
This class defines Exceptions that should be thrown when the sequence of operations is invalid...
static setNoCasServerValidation()
Set no SSL validation for the CAS server.
Definition: CAS.php:1639
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
static addRebroadcastHeader($header)
This method is used to add header parameters when rebroadcasting pgtIou/pgtId or logoutRequest.
Definition: CAS.php:1789
static client($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true)
phpCAS client initializer.
Definition: CAS.php:338
This class defines Exceptions that should be thrown when the sequence of operations is invalid...
$key
Definition: croninfo.php:18
static $_PHPCAS_DEBUG
This variable is used to store phpCAS debug mode.
Definition: CAS.php:302
static hasAttributes()
Answer true if there are attributes for the authenticated user.
Definition: CAS.php:1213
static hasAttribute($key)
Answer true if an attribute exists for the authenticated user.
Definition: CAS.php:1233
static $_PHPCAS_CLIENT
Definition: CAS.php:287
static getServerLoginURL()
This method returns the URL to be used to login.
Definition: CAS.php:1285