ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
250  if (!empty($_ENV['TMP'])) {
251  return realpath($_ENV['TMP']);
252  }
253  if (!empty($_ENV['TMPDIR'])) {
254  return realpath($_ENV['TMPDIR']);
255  }
256  if (!empty($_ENV['TEMP'])) {
257  return realpath($_ENV['TEMP']);
258  }
259  return "/tmp";
260 }
261 define('DEFAULT_DEBUG_DIR', gettmpdir() . "/");
262 
265 // include the class autoloader
266 require_once dirname(__FILE__) . '/CAS/Autoload.php';
267 
285 class phpCAS
286 {
287 
294  private static $_PHPCAS_CLIENT;
295 
302  private static $_PHPCAS_INIT_CALL;
303 
309  private static $_PHPCAS_DEBUG;
310 
318  private static $_PHPCAS_VERBOSE = false;
319 
320 
321  // ########################################################################
322  // INITIALIZATION
323  // ########################################################################
324 
345  public static function client(
346  $server_version,
347  $server_hostname,
348  $server_port,
349  $server_uri,
350  $changeSessionID = true
351  ) {
353  if (is_object(self::$_PHPCAS_CLIENT)) {
354  phpCAS :: error(self::$_PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . self::$_PHPCAS_INIT_CALL['file'] . ':' . self::$_PHPCAS_INIT_CALL['line'] . ')');
355  }
356 
357  // store where the initializer is called from
358  $dbg = debug_backtrace();
359  self::$_PHPCAS_INIT_CALL = array(
360  'done' => true,
361  'file' => $dbg[0]['file'],
362  'line' => $dbg[0]['line'],
363  'method' => __CLASS__ . '::' . __FUNCTION__
364  );
365 
366  // initialize the object $_PHPCAS_CLIENT
367  try {
368  self::$_PHPCAS_CLIENT = new CAS_Client(
369  $server_version,
370  false,
371  $server_hostname,
372  $server_port,
373  $server_uri,
374  $changeSessionID
375  );
376  } catch (Exception $e) {
377  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
378  }
380  }
381 
397  public static function proxy(
398  $server_version,
399  $server_hostname,
400  $server_port,
401  $server_uri,
402  $changeSessionID = true
403  ) {
405  if (is_object(self::$_PHPCAS_CLIENT)) {
406  phpCAS :: error(self::$_PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . self::$_PHPCAS_INIT_CALL['file'] . ':' . self::$_PHPCAS_INIT_CALL['line'] . ')');
407  }
408 
409  // store where the initialzer is called from
410  $dbg = debug_backtrace();
411  self::$_PHPCAS_INIT_CALL = array(
412  'done' => true,
413  'file' => $dbg[0]['file'],
414  'line' => $dbg[0]['line'],
415  'method' => __CLASS__ . '::' . __FUNCTION__
416  );
417 
418  // initialize the object $_PHPCAS_CLIENT
419  try {
420  self::$_PHPCAS_CLIENT = new CAS_Client(
421  $server_version,
422  true,
423  $server_hostname,
424  $server_port,
425  $server_uri,
426  $changeSessionID
427  );
428  } catch (Exception $e) {
429  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
430  }
432  }
433 
439  public static function isInitialized()
440  {
441  return (is_object(self::$_PHPCAS_CLIENT));
442  }
443 
445  // ########################################################################
446  // DEBUGGING
447  // ########################################################################
448 
462  public static function setDebug($filename = '')
463  {
464  if ($filename != false && gettype($filename) != 'string') {
465  phpCAS :: error('type mismatched for parameter $dbg (should be false or the name of the log file)');
466  }
467  if ($filename === false) {
468  self::$_PHPCAS_DEBUG['filename'] = false;
469  } else {
470  if (empty($filename)) {
471  if (preg_match('/^Win.*/', getenv('OS'))) {
472  if (isset($_ENV['TMP'])) {
473  $debugDir = $_ENV['TMP'] . '/';
474  } else {
475  $debugDir = '';
476  }
477  } else {
478  $debugDir = DEFAULT_DEBUG_DIR;
479  }
480  $filename = $debugDir . 'phpCAS.log';
481  }
482 
483  if (empty(self::$_PHPCAS_DEBUG['unique_id'])) {
484  self::$_PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4);
485  }
486 
487  self::$_PHPCAS_DEBUG['filename'] = $filename;
488  self::$_PHPCAS_DEBUG['indent'] = 0;
489 
490  phpCAS :: trace('START (' . date("Y-m-d H:i:s") . ') phpCAS-' . PHPCAS_VERSION . ' ******************');
491  }
492  }
493 
503  public static function setVerbose($verbose)
504  {
505  if ($verbose === true) {
506  self::$_PHPCAS_VERBOSE = true;
507  } else {
508  self::$_PHPCAS_VERBOSE = false;
509  }
510  }
511 
512 
518  public static function getVerbose()
519  {
520  return self::$_PHPCAS_VERBOSE;
521  }
522 
531  public static function log($str)
532  {
533  $indent_str = ".";
534 
535 
536  if (!empty(self::$_PHPCAS_DEBUG['filename'])) {
537  // Check if file exists and modifiy file permissions to be only
538  // readable by the webserver
539  if (!file_exists(self::$_PHPCAS_DEBUG['filename'])) {
540  touch(self::$_PHPCAS_DEBUG['filename']);
541  // Chmod will fail on windows
542  @chmod(self::$_PHPCAS_DEBUG['filename'], 0600);
543  }
544  for ($i = 0; $i < self::$_PHPCAS_DEBUG['indent']; $i++) {
545  $indent_str .= '| ';
546  }
547  // allow for multiline output with proper identing. Usefull for
548  // dumping cas answers etc.
549  $str2 = str_replace("\n", "\n" . self::$_PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str, $str);
550  error_log(self::$_PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str . $str2 . "\n", 3, self::$_PHPCAS_DEBUG['filename']);
551  }
552  }
553 
563  public static function error($msg)
564  {
566  $dbg = debug_backtrace();
567  $function = '?';
568  $file = '?';
569  $line = '?';
570  if (is_array($dbg)) {
571  for ($i = 1; $i < sizeof($dbg); $i++) {
572  if (is_array($dbg[$i]) && isset($dbg[$i]['class'])) {
573  if ($dbg[$i]['class'] == __CLASS__) {
574  $function = $dbg[$i]['function'];
575  $file = $dbg[$i]['file'];
576  $line = $dbg[$i]['line'];
577  }
578  }
579  }
580  }
581  if (self::$_PHPCAS_VERBOSE) {
582  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";
583  } else {
584  echo "<br />\n<b>Error</b>: <font color=\"FF0000\"><b>" . DEFAULT_ERROR . "</b><br />\n";
585  }
586  phpCAS :: trace($msg . ' in ' . $file . 'on line ' . $line);
588 
589  throw new CAS_GracefullTerminationException(__CLASS__ . "::" . $function . '(): ' . $msg);
590  }
591 
599  public static function trace($str)
600  {
601  $dbg = debug_backtrace();
602  phpCAS :: log($str . ' [' . basename($dbg[0]['file']) . ':' . $dbg[0]['line'] . ']');
603  }
604 
611  public static function traceBegin()
612  {
613  $dbg = debug_backtrace();
614  $str = '=> ';
615  if (!empty($dbg[1]['class'])) {
616  $str .= $dbg[1]['class'] . '::';
617  }
618  $str .= $dbg[1]['function'] . '(';
619  if (is_array($dbg[1]['args'])) {
620  foreach ($dbg[1]['args'] as $index => $arg) {
621  if ($index != 0) {
622  $str .= ', ';
623  }
624  if (is_object($arg)) {
625  $str .= get_class($arg);
626  } else {
627  $str .= str_replace(array("\r\n", "\n", "\r"), "", var_export($arg, true));
628  }
629  }
630  }
631  if (isset($dbg[1]['file'])) {
632  $file = basename($dbg[1]['file']);
633  } else {
634  $file = 'unknown_file';
635  }
636  if (isset($dbg[1]['line'])) {
637  $line = $dbg[1]['line'];
638  } else {
639  $line = 'unknown_line';
640  }
641  $str .= ') [' . $file . ':' . $line . ']';
642  phpCAS :: log($str);
643  if (!isset(self::$_PHPCAS_DEBUG['indent'])) {
644  self::$_PHPCAS_DEBUG['indent'] = 0;
645  } else {
646  self::$_PHPCAS_DEBUG['indent']++;
647  }
648  }
649 
658  public static function traceEnd($res = '')
659  {
660  if (empty(self::$_PHPCAS_DEBUG['indent'])) {
661  self::$_PHPCAS_DEBUG['indent'] = 0;
662  } else {
663  self::$_PHPCAS_DEBUG['indent']--;
664  }
665  $dbg = debug_backtrace();
666  $str = '';
667  if (is_object($res)) {
668  $str .= '<= ' . get_class($res);
669  } else {
670  $str .= '<= ' . str_replace(array("\r\n", "\n", "\r"), "", var_export($res, true));
671  }
672 
673  phpCAS :: log($str);
674  }
675 
681  public static function traceExit()
682  {
683  phpCAS :: log('exit()');
684  while (self::$_PHPCAS_DEBUG['indent'] > 0) {
685  phpCAS :: log('-');
686  self::$_PHPCAS_DEBUG['indent']--;
687  }
688  }
689 
691  // ########################################################################
692  // INTERNATIONALIZATION
693  // ########################################################################
709  public static function setLang($lang)
710  {
712 
713  try {
714  self::$_PHPCAS_CLIENT->setLang($lang);
715  } catch (Exception $e) {
716  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
717  }
718  }
719 
721  // ########################################################################
722  // VERSION
723  // ########################################################################
734  public static function getVersion()
735  {
736  return PHPCAS_VERSION;
737  }
738 
740  // ########################################################################
741  // HTML OUTPUT
742  // ########################################################################
755  public static function setHTMLHeader($header)
756  {
758 
759  try {
760  self::$_PHPCAS_CLIENT->setHTMLHeader($header);
761  } catch (Exception $e) {
762  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
763  }
764  }
765 
773  public static function setHTMLFooter($footer)
774  {
776 
777  try {
778  self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
779  } catch (Exception $e) {
780  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
781  }
782  }
783 
785  // ########################################################################
786  // PGT STORAGE
787  // ########################################################################
801  public static function setPGTStorage($storage)
802  {
805 
806  try {
807  self::$_PHPCAS_CLIENT->setPGTStorage($storage);
808  } catch (Exception $e) {
809  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
810  }
812  }
813 
831  public static function setPGTStorageDb(
832  $dsn_or_pdo,
833  $username = '',
834  $password = '',
835  $table = '',
836  $driver_options = null
837  ) {
840 
841  try {
842  self::$_PHPCAS_CLIENT->setPGTStorageDb($dsn_or_pdo, $username, $password, $table, $driver_options);
843  } catch (Exception $e) {
844  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
845  }
847  }
848 
857  public static function setPGTStorageFile($path = '')
858  {
861 
862  try {
863  self::$_PHPCAS_CLIENT->setPGTStorageFile($path);
864  } catch (Exception $e) {
865  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
866  }
868  }
870  // ########################################################################
871  // ACCESS TO EXTERNAL SERVICES
872  // ########################################################################
888  public static function getProxiedService($type)
889  {
892 
893  try {
894  $res = self::$_PHPCAS_CLIENT->getProxiedService($type);
895  } catch (Exception $e) {
896  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
897  }
898 
900  return $res;
901  }
902 
915  public static function initializeProxiedService(CAS_ProxiedService $proxiedService)
916  {
918 
919  try {
920  self::$_PHPCAS_CLIENT->initializeProxiedService($proxiedService);
921  } catch (Exception $e) {
922  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
923  }
924  }
925 
941  public static function serviceWeb($url, &$err_code, &$output)
942  {
945 
946  try {
947  $res = self::$_PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
948  } catch (Exception $e) {
949  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
950  }
951 
953  return $res;
954  }
955 
975  public static function serviceMail($url, $service, $flags, &$err_code, &$err_msg, &$pt)
976  {
979 
980  try {
981  $res = self::$_PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
982  } catch (Exception $e) {
983  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
984  }
985 
987  return $res;
988  }
989 
991  // ########################################################################
992  // AUTHENTICATION
993  // ########################################################################
1010  public static function setCacheTimesForAuthRecheck($n)
1011  {
1013 
1014  try {
1015  self::$_PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
1016  } catch (Exception $e) {
1017  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1018  }
1019  }
1020 
1021 
1033  public static function setCasAttributeParserCallback($function, array $additionalArgs = array())
1034  {
1036 
1037  self::$_PHPCAS_CLIENT->setCasAttributeParserCallback($function, $additionalArgs);
1038  }
1039 
1059  public static function setPostAuthenticateCallback($function, array $additionalArgs = array())
1060  {
1062 
1063  self::$_PHPCAS_CLIENT->setPostAuthenticateCallback($function, $additionalArgs);
1064  }
1065 
1080  public static function setSingleSignoutCallback($function, array $additionalArgs = array())
1081  {
1083 
1084  self::$_PHPCAS_CLIENT->setSingleSignoutCallback($function, $additionalArgs);
1085  }
1086 
1097  public static function checkAuthentication()
1098  {
1101 
1102  $auth = self::$_PHPCAS_CLIENT->checkAuthentication();
1103 
1104  // store where the authentication has been checked and the result
1105  self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
1106 
1108  return $auth;
1109  }
1110 
1118  public static function forceAuthentication()
1119  {
1122  $auth = self::$_PHPCAS_CLIENT->forceAuthentication();
1123 
1124  // store where the authentication has been checked and the result
1125  self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
1126 
1127  /* if (!$auth) {
1128  phpCAS :: trace('user is not authenticated, redirecting to the CAS server');
1129  self::$_PHPCAS_CLIENT->forceAuthentication();
1130  } else {
1131  phpCAS :: trace('no need to authenticate (user `' . phpCAS :: getUser() . '\' is already authenticated)');
1132  }*/
1133 
1135  return $auth;
1136  }
1137 
1143  public static function renewAuthentication()
1144  {
1147 
1148  $auth = self::$_PHPCAS_CLIENT->renewAuthentication();
1149 
1150  // store where the authentication has been checked and the result
1151  self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
1152 
1153  //self::$_PHPCAS_CLIENT->renewAuthentication();
1155  }
1156 
1163  public static function isAuthenticated()
1164  {
1167 
1168  // call the isAuthenticated method of the $_PHPCAS_CLIENT object
1169  $auth = self::$_PHPCAS_CLIENT->isAuthenticated();
1170 
1171  // store where the authentication has been checked and the result
1172  self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
1173 
1175  return $auth;
1176  }
1177 
1185  public static function isSessionAuthenticated()
1186  {
1188 
1189  return (self::$_PHPCAS_CLIENT->isSessionAuthenticated());
1190  }
1191 
1199  public static function getUser()
1200  {
1202 
1203  try {
1204  return self::$_PHPCAS_CLIENT->getUser();
1205  } catch (Exception $e) {
1206  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1207  }
1208  }
1209 
1218  public static function getAttributes()
1219  {
1221 
1222  try {
1223  return self::$_PHPCAS_CLIENT->getAttributes();
1224  } catch (Exception $e) {
1225  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1226  }
1227  }
1228 
1237  public static function hasAttributes()
1238  {
1240 
1241  try {
1242  return self::$_PHPCAS_CLIENT->hasAttributes();
1243  } catch (Exception $e) {
1244  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1245  }
1246  }
1247 
1257  public static function hasAttribute($key)
1258  {
1260 
1261  try {
1262  return self::$_PHPCAS_CLIENT->hasAttribute($key);
1263  } catch (Exception $e) {
1264  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1265  }
1266  }
1267 
1277  public static function getAttribute($key)
1278  {
1280 
1281  try {
1282  return self::$_PHPCAS_CLIENT->getAttribute($key);
1283  } catch (Exception $e) {
1284  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1285  }
1286  }
1287 
1296  public static function handleLogoutRequests($check_client = true, $allowed_clients = false)
1297  {
1299 
1300  return (self::$_PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
1301  }
1302 
1309  public static function getServerLoginURL()
1310  {
1312 
1313  return self::$_PHPCAS_CLIENT->getServerLoginURL();
1314  }
1315 
1324  public static function setServerLoginURL($url = '')
1325  {
1328 
1329  try {
1330  self::$_PHPCAS_CLIENT->setServerLoginURL($url);
1331  } catch (Exception $e) {
1332  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1333  }
1334 
1336  }
1337 
1350  public static function setServerServiceValidateURL($url = '')
1351  {
1354 
1355  try {
1356  self::$_PHPCAS_CLIENT->setServerServiceValidateURL($url);
1357  } catch (Exception $e) {
1358  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1359  }
1360 
1362  }
1363 
1376  public static function setServerProxyValidateURL($url = '')
1377  {
1380 
1381  try {
1382  self::$_PHPCAS_CLIENT->setServerProxyValidateURL($url);
1383  } catch (Exception $e) {
1384  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1385  }
1386 
1388  }
1389 
1397  public static function setServerSamlValidateURL($url = '')
1398  {
1401 
1402  try {
1403  self::$_PHPCAS_CLIENT->setServerSamlValidateURL($url);
1404  } catch (Exception $e) {
1405  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1406  }
1407 
1409  }
1410 
1417  public static function getServerLogoutURL()
1418  {
1420 
1421  return self::$_PHPCAS_CLIENT->getServerLogoutURL();
1422  }
1423 
1432  public static function setServerLogoutURL($url = '')
1433  {
1436 
1437  try {
1438  self::$_PHPCAS_CLIENT->setServerLogoutURL($url);
1439  } catch (Exception $e) {
1440  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1441  }
1442 
1444  }
1445 
1454  public static function logout($params = "")
1455  {
1458 
1459  $parsedParams = array();
1460  if ($params != "") {
1461  if (is_string($params)) {
1462  phpCAS :: error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');
1463  }
1464  if (!is_array($params)) {
1465  phpCAS :: error('type mismatched for parameter $params (should be `array\')');
1466  }
1467  foreach ($params as $key => $value) {
1468  if ($key != "service" && $key != "url") {
1469  phpCAS :: error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');
1470  }
1471  $parsedParams[$key] = $value;
1472  }
1473  }
1474  self::$_PHPCAS_CLIENT->logout($parsedParams);
1475  // never reached
1477  }
1478 
1487  public static function logoutWithRedirectService($service)
1488  {
1491 
1492  if (!is_string($service)) {
1493  phpCAS :: error('type mismatched for parameter $service (should be `string\')');
1494  }
1495  self::$_PHPCAS_CLIENT->logout(array( "service" => $service ));
1496  // never reached
1498  }
1499 
1510  public static function logoutWithUrl($url)
1511  {
1512  trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
1514  if (!is_object(self::$_PHPCAS_CLIENT)) {
1515  phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
1516  }
1517  if (!is_string($url)) {
1518  phpCAS :: error('type mismatched for parameter $url (should be `string\')');
1519  }
1520  self::$_PHPCAS_CLIENT->logout(array( "url" => $url ));
1521  // never reached
1523  }
1524 
1537  public static function logoutWithRedirectServiceAndUrl($service, $url)
1538  {
1539  trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
1542 
1543  if (!is_string($service)) {
1544  phpCAS :: error('type mismatched for parameter $service (should be `string\')');
1545  }
1546  if (!is_string($url)) {
1547  phpCAS :: error('type mismatched for parameter $url (should be `string\')');
1548  }
1549  self::$_PHPCAS_CLIENT->logout(
1550  array(
1551  "service" => $service,
1552  "url" => $url
1553  )
1554  );
1555  // never reached
1557  }
1558 
1568  public static function setFixedCallbackURL($url = '')
1569  {
1572 
1573  try {
1574  self::$_PHPCAS_CLIENT->setCallbackURL($url);
1575  } catch (Exception $e) {
1576  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1577  }
1578 
1580  }
1581 
1590  public static function setFixedServiceURL($url)
1591  {
1594 
1595  try {
1596  self::$_PHPCAS_CLIENT->setURL($url);
1597  } catch (Exception $e) {
1598  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1599  }
1600 
1602  }
1603 
1609  public static function getServiceURL()
1610  {
1612  return (self::$_PHPCAS_CLIENT->getURL());
1613  }
1614 
1624  public static function retrievePT($target_service, &$err_code, &$err_msg)
1625  {
1627 
1628  try {
1629  return (self::$_PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
1630  } catch (Exception $e) {
1631  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1632  }
1633  }
1634 
1644  public static function setCasServerCACert($cert, $validate_cn = true)
1645  {
1648 
1649  try {
1650  self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
1651  } catch (Exception $e) {
1652  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1653  }
1654 
1656  }
1657 
1663  public static function setNoCasServerValidation()
1664  {
1667 
1668  phpCAS :: trace('You have configured no validation of the legitimacy of the cas server. This is not recommended for production use.');
1669  self::$_PHPCAS_CLIENT->setNoCasServerValidation();
1671  }
1672 
1673 
1683  public static function setNoClearTicketsFromUrl()
1684  {
1687 
1688  self::$_PHPCAS_CLIENT->setNoClearTicketsFromUrl();
1690  }
1691 
1703  public static function setExtraCurlOption($key, $value)
1704  {
1707 
1708  self::$_PHPCAS_CLIENT->setExtraCurlOption($key, $value);
1710  }
1711 
1748  public static function allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
1749  {
1752 
1753  if (self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_2_0
1754  && self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_3_0
1755  ) {
1756  phpCAS :: error('this method can only be used with the cas 2.0/3.0 protocols');
1757  }
1758  self::$_PHPCAS_CLIENT->getAllowedProxyChains()->allowProxyChain($proxy_chain);
1760  }
1761 
1771  public static function getProxies()
1772  {
1774 
1775  return(self::$_PHPCAS_CLIENT->getProxies());
1776  }
1777 
1778  // ########################################################################
1779  // PGTIOU/PGTID and logoutRequest rebroadcasting
1780  // ########################################################################
1781 
1790  public static function addRebroadcastNode($rebroadcastNodeUrl)
1791  {
1793  phpCAS::log('rebroadcastNodeUrl:' . $rebroadcastNodeUrl);
1795 
1796  try {
1797  self::$_PHPCAS_CLIENT->addRebroadcastNode($rebroadcastNodeUrl);
1798  } catch (Exception $e) {
1799  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1800  }
1801 
1802  phpCAS::traceEnd();
1803  }
1804 
1813  public static function addRebroadcastHeader($header)
1814  {
1817 
1818  try {
1819  self::$_PHPCAS_CLIENT->addRebroadcastHeader($header);
1820  } catch (Exception $e) {
1821  phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1822  }
1823 
1825  }
1826 
1834  private static function _validateClientExists()
1835  {
1836  if (!is_object(self::$_PHPCAS_CLIENT)) {
1838  }
1839  }
1840 
1848  private static function _validateProxyExists()
1849  {
1850  if (!is_object(self::$_PHPCAS_CLIENT)) {
1852  }
1853  }
1854 
1860  public static function setCasClient(\CAS_Client $client)
1861  {
1862  self::$_PHPCAS_CLIENT = $client;
1863  }
1864 }
1865 // ########################################################################
1866 // DOCUMENTATION
1867 // ########################################################################
1868 
1869 // ########################################################################
1870 // MAIN PAGE
1871 
1879 // ########################################################################
1880 // MODULES DEFINITION
1881 
1964 // ########################################################################
1965 // EXAMPLES
1966 
$path
Definition: aliased.php:25
static forceAuthentication()
This method is called to force authentication if the user was not already authenticated.
Definition: CAS.php:1118
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 logoutWithUrl($url)
This method is used to logout from CAS.
Definition: CAS.php:1510
static getUser()
This method returns the CAS user&#39;s login name.
Definition: CAS.php:1199
The phpCAS class is a simple container for the phpCAS library.
Definition: CAS.php:285
static getAttribute($key)
Answer an attribute for the authenticated user.
Definition: CAS.php:1277
$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:302
static setNoClearTicketsFromUrl()
Disable the removal of a CAS-Ticket from the URL when authenticating DISABLING POSES A SECURITY RISK:...
Definition: CAS.php:1683
static error($msg)
This method is used by interface methods to print an error and where the function was originally call...
Definition: CAS.php:563
static isInitialized()
Answer whether or not the client or proxy has been initialized.
Definition: CAS.php:439
static traceExit()
This method is used to indicate the end of the execution of the program.
Definition: CAS.php:681
static $_PHPCAS_VERBOSE
This variable is used to enable verbose mode This pevents debug info to be show to the user...
Definition: CAS.php:318
const CAS_VERSION_3_0
CAS version 3.0.
Definition: CAS.php:82
static serviceMail($url, $service, $flags, &$err_code, &$err_msg, &$pt)
This method is used to access an IMAP/POP3/NNTP service.
Definition: CAS.php:975
$verbose
static setCacheTimesForAuthRecheck($n)
Set the times authentication will be cached before really accessing the CAS server in gateway mode: ...
Definition: CAS.php:1010
static setCasAttributeParserCallback($function, array $additionalArgs=array())
Set a callback function to be run when receiving CAS attributes.
Definition: CAS.php:1033
static addRebroadcastNode($rebroadcastNodeUrl)
Add a pgtIou/pgtId and logoutRequest rebroadcast node.
Definition: CAS.php:1790
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:1748
static setFixedCallbackURL($url='')
Set the fixed URL that will be used by the CAS server to transmit the PGT.
Definition: CAS.php:1568
static getProxies()
Answer an array of proxies that are sitting in front of this application.
Definition: CAS.php:1771
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...
static proxy( $server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true)
phpCAS proxy initializer.
Definition: CAS.php:397
static getAttributes()
Answer attributes about the authenticated user.
Definition: CAS.php:1218
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
Definition: CAS.php:658
$auth
Definition: fileserver.php:48
static trace($str)
This method is used to log something in debug mode.
Definition: CAS.php:599
static retrievePT($target_service, &$err_code, &$err_msg)
Retrieve a Proxy Ticket from the CAS server.
Definition: CAS.php:1624
static getServiceURL()
Get the URL that is set as the CAS service parameter.
Definition: CAS.php:1609
static logoutWithRedirectServiceAndUrl($service, $url)
This method is used to logout from CAS.
Definition: CAS.php:1537
static log($str)
Logs a string in debug mode.
Definition: CAS.php:531
static serviceWeb($url, &$err_code, &$output)
This method is used to access an HTTP[S] service.
Definition: CAS.php:941
static checkAuthentication()
This method is called to check if the user is already authenticated locally or has a global cas sessi...
Definition: CAS.php:1097
static setHTMLFooter($footer)
This method sets the HTML footer used for all outputs.
Definition: CAS.php:773
static getProxiedService($type)
Answer a proxy-authenticated service handler.
Definition: CAS.php:888
foreach($_POST as $key=> $value) $res
static setServerLoginURL($url='')
Set the login URL of the CAS server.
Definition: CAS.php:1324
static setLang($lang)
This method is used to set the language used by phpCAS.
Definition: CAS.php:709
static setServerSamlValidateURL($url='')
Set the samlValidate URL of the CAS server.
Definition: CAS.php:1397
static client( $server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true)
phpCAS client initializer.
Definition: CAS.php:345
static setHTMLHeader($header)
This method sets the HTML header used for all outputs.
Definition: CAS.php:755
static initializeProxiedService(CAS_ProxiedService $proxiedService)
Initialize a proxied-service handler with the proxy-ticket it should use.
Definition: CAS.php:915
static setServerServiceValidateURL($url='')
Set the serviceValidate URL of the CAS server.
Definition: CAS.php:1350
const PHPCAS_LANG_ENGLISH
Definition: CAS.php:215
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:831
static isSessionAuthenticated()
Checks whether authenticated based on $_SESSION.
Definition: CAS.php:1185
static setSingleSignoutCallback($function, array $additionalArgs=array())
Set a callback function to be run when a single-signout request is received.
Definition: CAS.php:1080
const CAS_VERSION_2_0
Definition: CAS.php:78
static getVerbose()
Show is verbose mode is on.
Definition: CAS.php:518
$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:1059
static getVersion()
This method returns the phpCAS version.
Definition: CAS.php:734
static setExtraCurlOption($key, $value)
Change CURL options.
Definition: CAS.php:1703
static handleLogoutRequests($check_client=true, $allowed_clients=false)
Handle logout requests.
Definition: CAS.php:1296
static setServerProxyValidateURL($url='')
Set the proxyValidate URL of the CAS server.
Definition: CAS.php:1376
static logout($params="")
This method is used to logout from CAS.
Definition: CAS.php:1454
static setFixedServiceURL($url)
Set the fixed URL that will be set as the CAS service parameter.
Definition: CAS.php:1590
const DEFAULT_DEBUG_DIR
Definition: CAS.php:261
$filename
Definition: buildRTE.php:89
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:1644
static renewAuthentication()
This method is called to renew the authentication.
Definition: CAS.php:1143
static setVerbose($verbose)
Enable verbose errors messages in the website output This is a security relevant since internal statu...
Definition: CAS.php:503
static _validateProxyExists()
Checks of a proxy client aready exists.
Definition: CAS.php:1848
static isAuthenticated()
This method is called to check if the user is authenticated (previously or by tickets given in the UR...
Definition: CAS.php:1163
$password
Definition: cron.php:14
static logoutWithRedirectService($service)
This method is used to logout from CAS.
Definition: CAS.php:1487
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
Definition: CAS.php:611
static setDebug($filename='')
Set/unset debug mode.
Definition: CAS.php:462
static setPGTStorage($storage)
This method can be used to set a custom PGT storage object.
Definition: CAS.php:801
static setServerLogoutURL($url='')
Set the logout URL of the CAS server.
Definition: CAS.php:1432
const PHPCAS_VERSION(!defined('E_USER_DEPRECATED'))
phpCAS version.
Definition: CAS.php:64
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
$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:1417
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:857
static setCasClient(\CAS_Client $client)
For testing purposes, use this method to set the client to a test double.
Definition: CAS.php:1860
$url
static _validateClientExists()
Checks if a client already exists.
Definition: CAS.php:1834
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:1663
static addRebroadcastHeader($header)
This method is used to add header parameters when rebroadcasting pgtIou/pgtId or logoutRequest.
Definition: CAS.php:1813
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:309
static hasAttributes()
Answer true if there are attributes for the authenticated user.
Definition: CAS.php:1237
static hasAttribute($key)
Answer true if an attribute exists for the authenticated user.
Definition: CAS.php:1257
static $_PHPCAS_CLIENT
Definition: CAS.php:294
static getServerLoginURL()
This method returns the URL to be used to login.
Definition: CAS.php:1309