phpCAS version 1.3.6

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.6');
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 ) {
341 phpCAS :: traceBegin();
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 }
364 phpCAS :: traceEnd();
365 }
366
382 public static function proxy($server_version, $server_hostname,
383 $server_port, $server_uri, $changeSessionID = true
384 ) {
385 phpCAS :: traceBegin();
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 }
408 phpCAS :: traceEnd();
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 {
545 phpCAS :: traceBegin();
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 );
567 phpCAS :: traceEnd();
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 {
691 phpCAS::_validateClientExists();
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 {
737 phpCAS::_validateClientExists();
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 {
755 phpCAS::_validateClientExists();
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 {
783 phpCAS :: traceBegin();
784 phpCAS::_validateProxyExists();
785
786 try {
787 self::$_PHPCAS_CLIENT->setPGTStorage($storage);
788 } catch (Exception $e) {
789 phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
790 }
791 phpCAS :: traceEnd();
792 }
793
811 public static function setPGTStorageDb($dsn_or_pdo, $username='',
812 $password='', $table='', $driver_options=null
813 ) {
814 phpCAS :: traceBegin();
815 phpCAS::_validateProxyExists();
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 }
822 phpCAS :: traceEnd();
823 }
824
833 public static function setPGTStorageFile($path = '')
834 {
835 phpCAS :: traceBegin();
836 phpCAS::_validateProxyExists();
837
838 try {
839 self::$_PHPCAS_CLIENT->setPGTStorageFile($path);
840 } catch (Exception $e) {
841 phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
842 }
843 phpCAS :: traceEnd();
844 }
846 // ########################################################################
847 // ACCESS TO EXTERNAL SERVICES
848 // ########################################################################
864 public static function getProxiedService ($type)
865 {
866 phpCAS :: traceBegin();
867 phpCAS::_validateProxyExists();
868
869 try {
870 $res = self::$_PHPCAS_CLIENT->getProxiedService($type);
871 } catch (Exception $e) {
872 phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
873 }
874
875 phpCAS :: traceEnd();
876 return $res;
877 }
878
891 public static function initializeProxiedService (CAS_ProxiedService $proxiedService)
892 {
893 phpCAS::_validateProxyExists();
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 {
919 phpCAS :: traceBegin();
920 phpCAS::_validateProxyExists();
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
928 phpCAS :: traceEnd($res);
929 return $res;
930 }
931
951 public static function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
952 {
953 phpCAS :: traceBegin();
954 phpCAS::_validateProxyExists();
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
962 phpCAS :: traceEnd($res);
963 return $res;
964 }
965
967 // ########################################################################
968 // AUTHENTICATION
969 // ########################################################################
986 public static function setCacheTimesForAuthRecheck($n)
987 {
988 phpCAS::_validateClientExists();
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 {
1011 phpCAS::_validateClientExists();
1012
1013 self::$_PHPCAS_CLIENT->setCasAttributeParserCallback($function, $additionalArgs);
1014 }
1015
1035 public static function setPostAuthenticateCallback ($function, array $additionalArgs = array())
1036 {
1037 phpCAS::_validateClientExists();
1038
1039 self::$_PHPCAS_CLIENT->setPostAuthenticateCallback($function, $additionalArgs);
1040 }
1041
1056 public static function setSingleSignoutCallback ($function, array $additionalArgs = array())
1057 {
1058 phpCAS::_validateClientExists();
1059
1060 self::$_PHPCAS_CLIENT->setSingleSignoutCallback($function, $additionalArgs);
1061 }
1062
1073 public static function checkAuthentication()
1074 {
1075 phpCAS :: traceBegin();
1076 phpCAS::_validateClientExists();
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
1083 phpCAS :: traceEnd($auth);
1084 return $auth;
1085 }
1086
1094 public static function forceAuthentication()
1095 {
1096 phpCAS :: traceBegin();
1097 phpCAS::_validateClientExists();
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
1110 phpCAS :: traceEnd();
1111 return $auth;
1112 }
1113
1119 public static function renewAuthentication()
1120 {
1121 phpCAS :: traceBegin();
1122 phpCAS::_validateClientExists();
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();
1130 phpCAS :: traceEnd();
1131 }
1132
1139 public static function isAuthenticated()
1140 {
1141 phpCAS :: traceBegin();
1142 phpCAS::_validateClientExists();
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
1150 phpCAS :: traceEnd($auth);
1151 return $auth;
1152 }
1153
1161 public static function isSessionAuthenticated()
1162 {
1163 phpCAS::_validateClientExists();
1164
1165 return (self::$_PHPCAS_CLIENT->isSessionAuthenticated());
1166 }
1167
1175 public static function getUser()
1176 {
1177 phpCAS::_validateClientExists();
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 {
1196 phpCAS::_validateClientExists();
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 {
1215 phpCAS::_validateClientExists();
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 {
1235 phpCAS::_validateClientExists();
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 {
1255 phpCAS::_validateClientExists();
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 {
1274 phpCAS::_validateClientExists();
1275
1276 return (self::$_PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
1277 }
1278
1285 public static function getServerLoginURL()
1286 {
1287 phpCAS::_validateClientExists();
1288
1289 return self::$_PHPCAS_CLIENT->getServerLoginURL();
1290 }
1291
1300 public static function setServerLoginURL($url = '')
1301 {
1302 phpCAS :: traceBegin();
1303 phpCAS::_validateClientExists();
1304
1305 try {
1306 self::$_PHPCAS_CLIENT->setServerLoginURL($url);
1307 } catch (Exception $e) {
1308 phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1309 }
1310
1311 phpCAS :: traceEnd();
1312 }
1313
1326 public static function setServerServiceValidateURL($url = '')
1327 {
1328 phpCAS :: traceBegin();
1329 phpCAS::_validateClientExists();
1330
1331 try {
1332 self::$_PHPCAS_CLIENT->setServerServiceValidateURL($url);
1333 } catch (Exception $e) {
1334 phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1335 }
1336
1337 phpCAS :: traceEnd();
1338 }
1339
1352 public static function setServerProxyValidateURL($url = '')
1353 {
1354 phpCAS :: traceBegin();
1355 phpCAS::_validateClientExists();
1356
1357 try {
1358 self::$_PHPCAS_CLIENT->setServerProxyValidateURL($url);
1359 } catch (Exception $e) {
1360 phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1361 }
1362
1363 phpCAS :: traceEnd();
1364 }
1365
1373 public static function setServerSamlValidateURL($url = '')
1374 {
1375 phpCAS :: traceBegin();
1376 phpCAS::_validateClientExists();
1377
1378 try {
1379 self::$_PHPCAS_CLIENT->setServerSamlValidateURL($url);
1380 } catch (Exception $e) {
1381 phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1382 }
1383
1384 phpCAS :: traceEnd();
1385 }
1386
1393 public static function getServerLogoutURL()
1394 {
1395 phpCAS::_validateClientExists();
1396
1397 return self::$_PHPCAS_CLIENT->getServerLogoutURL();
1398 }
1399
1408 public static function setServerLogoutURL($url = '')
1409 {
1410 phpCAS :: traceBegin();
1411 phpCAS::_validateClientExists();
1412
1413 try {
1414 self::$_PHPCAS_CLIENT->setServerLogoutURL($url);
1415 } catch (Exception $e) {
1416 phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1417 }
1418
1419 phpCAS :: traceEnd();
1420 }
1421
1430 public static function logout($params = "")
1431 {
1432 phpCAS :: traceBegin();
1433 phpCAS::_validateClientExists();
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
1452 phpCAS :: traceEnd();
1453 }
1454
1463 public static function logoutWithRedirectService($service)
1464 {
1465 phpCAS :: traceBegin();
1466 phpCAS::_validateClientExists();
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
1473 phpCAS :: traceEnd();
1474 }
1475
1486 public static function logoutWithUrl($url)
1487 {
1488 trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
1489 phpCAS :: traceBegin();
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
1498 phpCAS :: traceEnd();
1499 }
1500
1513 public static function logoutWithRedirectServiceAndUrl($service, $url)
1514 {
1515 trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
1516 phpCAS :: traceBegin();
1517 phpCAS::_validateClientExists();
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
1532 phpCAS :: traceEnd();
1533 }
1534
1544 public static function setFixedCallbackURL($url = '')
1545 {
1546 phpCAS :: traceBegin();
1547 phpCAS::_validateProxyExists();
1548
1549 try {
1550 self::$_PHPCAS_CLIENT->setCallbackURL($url);
1551 } catch (Exception $e) {
1552 phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1553 }
1554
1555 phpCAS :: traceEnd();
1556 }
1557
1566 public static function setFixedServiceURL($url)
1567 {
1568 phpCAS :: traceBegin();
1569 phpCAS::_validateProxyExists();
1570
1571 try {
1572 self::$_PHPCAS_CLIENT->setURL($url);
1573 } catch (Exception $e) {
1574 phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1575 }
1576
1577 phpCAS :: traceEnd();
1578 }
1579
1585 public static function getServiceURL()
1586 {
1587 phpCAS::_validateProxyExists();
1588 return (self::$_PHPCAS_CLIENT->getURL());
1589 }
1590
1600 public static function retrievePT($target_service, & $err_code, & $err_msg)
1601 {
1602 phpCAS::_validateProxyExists();
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 {
1622 phpCAS :: traceBegin();
1623 phpCAS::_validateClientExists();
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
1631 phpCAS :: traceEnd();
1632 }
1633
1639 public static function setNoCasServerValidation()
1640 {
1641 phpCAS :: traceBegin();
1642 phpCAS::_validateClientExists();
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();
1646 phpCAS :: traceEnd();
1647 }
1648
1649
1659 public static function setNoClearTicketsFromUrl()
1660 {
1661 phpCAS :: traceBegin();
1662 phpCAS::_validateClientExists();
1663
1664 self::$_PHPCAS_CLIENT->setNoClearTicketsFromUrl();
1665 phpCAS :: traceEnd();
1666 }
1667
1679 public static function setExtraCurlOption($key, $value)
1680 {
1681 phpCAS :: traceBegin();
1682 phpCAS::_validateClientExists();
1683
1684 self::$_PHPCAS_CLIENT->setExtraCurlOption($key, $value);
1685 phpCAS :: traceEnd();
1686 }
1687
1702 public static function setSessionIdSalt($salt) {
1703 phpCAS :: traceBegin();
1704 phpCAS::_validateClientExists();
1705 self::$_PHPCAS_CLIENT->setSessionIdSalt($salt);
1706 phpCAS :: traceEnd();
1707 }
1708
1745 public static function allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
1746 {
1747 phpCAS :: traceBegin();
1748 phpCAS::_validateClientExists();
1749
1750 if (self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_2_0
1751 && self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_3_0
1752 ) {
1753 phpCAS :: error('this method can only be used with the cas 2.0/3.0 protocols');
1754 }
1755 self::$_PHPCAS_CLIENT->getAllowedProxyChains()->allowProxyChain($proxy_chain);
1756 phpCAS :: traceEnd();
1757 }
1758
1768 public static function getProxies ()
1769 {
1770 phpCAS::_validateProxyExists();
1771
1772 return(self::$_PHPCAS_CLIENT->getProxies());
1773 }
1774
1775 // ########################################################################
1776 // PGTIOU/PGTID and logoutRequest rebroadcasting
1777 // ########################################################################
1778
1787 public static function addRebroadcastNode($rebroadcastNodeUrl)
1788 {
1789 phpCAS::traceBegin();
1790 phpCAS::log('rebroadcastNodeUrl:'.$rebroadcastNodeUrl);
1791 phpCAS::_validateClientExists();
1792
1793 try {
1794 self::$_PHPCAS_CLIENT->addRebroadcastNode($rebroadcastNodeUrl);
1795 } catch (Exception $e) {
1796 phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1797 }
1798
1799 phpCAS::traceEnd();
1800 }
1801
1810 public static function addRebroadcastHeader($header)
1811 {
1812 phpCAS :: traceBegin();
1813 phpCAS::_validateClientExists();
1814
1815 try {
1816 self::$_PHPCAS_CLIENT->addRebroadcastHeader($header);
1817 } catch (Exception $e) {
1818 phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
1819 }
1820
1821 phpCAS :: traceEnd();
1822 }
1823
1831 private static function _validateClientExists()
1832 {
1833 if (!is_object(self::$_PHPCAS_CLIENT)) {
1834 throw new CAS_OutOfSequenceBeforeClientException();
1835 }
1836 }
1837
1845 private static function _validateProxyExists()
1846 {
1847 if (!is_object(self::$_PHPCAS_CLIENT)) {
1848 throw new CAS_OutOfSequenceBeforeProxyException();
1849 }
1850 }
1851
1857 public static function setCasClient(\CAS_Client $client)
1858 {
1859 self::$_PHPCAS_CLIENT = $client;
1860 }
1861 }
1862 // ########################################################################
1863 // DOCUMENTATION
1864 // ########################################################################
1865
1866 // ########################################################################
1867 // MAIN PAGE
1868
1876 // ########################################################################
1877 // MODULES DEFINITION
1878
1961 // ########################################################################
1962 // EXAMPLES
1963
2015 ?>
phpCAS\forceAuthentication
static forceAuthentication()
Definition: CAS.php:1094
phpCAS\serviceMail
static serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
Definition: CAS.php:951
gettmpdir
gettmpdir()
Definition: CAS.php:248
CAS_ProxyChain_Interface
Definition: Interface.php:41
phpCAS\serviceWeb
static serviceWeb($url, & $err_code, & $output)
Definition: CAS.php:917
phpCAS\logoutWithUrl
static logoutWithUrl($url)
Definition: CAS.php:1486
phpCAS\getUser
static getUser()
Definition: CAS.php:1175
phpCAS
Definition: CAS.php:278
phpCAS\getAttribute
static getAttribute($key)
Definition: CAS.php:1253
phpCAS\$_PHPCAS_INIT_CALL
static $_PHPCAS_INIT_CALL
Definition: CAS.php:295
phpCAS\setNoClearTicketsFromUrl
static setNoClearTicketsFromUrl()
Definition: CAS.php:1659
phpCAS\error
static error($msg)
Definition: CAS.php:543
phpCAS\isInitialized
static isInitialized()
Definition: CAS.php:416
phpCAS\traceExit
static traceExit()
Definition: CAS.php:661
phpCAS\$_PHPCAS_VERBOSE
static $_PHPCAS_VERBOSE
Definition: CAS.php:311
CAS_VERSION_3_0
const CAS_VERSION_3_0
Definition: CAS.php:82
phpCAS\setCacheTimesForAuthRecheck
static setCacheTimesForAuthRecheck($n)
Definition: CAS.php:986
PHPCAS_VERSION
const PHPCAS_VERSION(!defined('E_USER_DEPRECATED'))
Definition: CAS.php:64
phpCAS\setCasAttributeParserCallback
static setCasAttributeParserCallback($function, array $additionalArgs=array())
Definition: CAS.php:1009
phpCAS\addRebroadcastNode
static addRebroadcastNode($rebroadcastNodeUrl)
Definition: CAS.php:1787
phpCAS\allowProxyChain
static allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
Definition: CAS.php:1745
phpCAS\setFixedCallbackURL
static setFixedCallbackURL($url='')
Definition: CAS.php:1544
phpCAS\getProxies
static getProxies()
Definition: CAS.php:1768
DEFAULT_ERROR
const DEFAULT_ERROR
Definition: CAS.php:142
CAS_ProxiedService
Definition: ProxiedService.php:47
phpCAS\getAttributes
static getAttributes()
Definition: CAS.php:1194
phpCAS\traceEnd
static traceEnd($res='')
Definition: CAS.php:638
phpCAS\trace
static trace($str)
Definition: CAS.php:579
phpCAS\getServiceURL
static getServiceURL()
Definition: CAS.php:1585
phpCAS\logoutWithRedirectServiceAndUrl
static logoutWithRedirectServiceAndUrl($service, $url)
Definition: CAS.php:1513
phpCAS\log
static log($str)
Definition: CAS.php:509
phpCAS\checkAuthentication
static checkAuthentication()
Definition: CAS.php:1073
phpCAS\setHTMLFooter
static setHTMLFooter($footer)
Definition: CAS.php:753
phpCAS\getProxiedService
static getProxiedService($type)
Definition: CAS.php:864
phpCAS\setServerLoginURL
static setServerLoginURL($url='')
Definition: CAS.php:1300
phpCAS\setLang
static setLang($lang)
Definition: CAS.php:689
phpCAS\setServerSamlValidateURL
static setServerSamlValidateURL($url='')
Definition: CAS.php:1373
phpCAS\setSessionIdSalt
static setSessionIdSalt($salt)
Definition: CAS.php:1702
$client
$client
Definition: create_pgt_storage_db_table.php:30
phpCAS\setHTMLHeader
static setHTMLHeader($header)
Definition: CAS.php:735
phpCAS\initializeProxiedService
static initializeProxiedService(CAS_ProxiedService $proxiedService)
Definition: CAS.php:891
phpCAS\setServerServiceValidateURL
static setServerServiceValidateURL($url='')
Definition: CAS.php:1326
PHPCAS_LANG_ENGLISH
const PHPCAS_LANG_ENGLISH
Definition: CAS.php:215
phpCAS\proxy
static proxy($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true)
Definition: CAS.php:382
phpCAS\isSessionAuthenticated
static isSessionAuthenticated()
Definition: CAS.php:1161
phpCAS\setSingleSignoutCallback
static setSingleSignoutCallback($function, array $additionalArgs=array())
Definition: CAS.php:1056
$driver_options
$driver_options
Definition: config.example.php:59
phpCAS\setPGTStorageDb
static setPGTStorageDb($dsn_or_pdo, $username='', $password='', $table='', $driver_options=null)
Definition: CAS.php:811
CAS_GracefullTerminationException
Definition: GracefullTerminationException.php:43
CAS_VERSION_2_0
const CAS_VERSION_2_0
Definition: CAS.php:78
phpCAS\getVerbose
static getVerbose()
Definition: CAS.php:496
phpCAS\setPostAuthenticateCallback
static setPostAuthenticateCallback($function, array $additionalArgs=array())
Definition: CAS.php:1035
phpCAS\getVersion
static getVersion()
Definition: CAS.php:714
phpCAS\setExtraCurlOption
static setExtraCurlOption($key, $value)
Definition: CAS.php:1679
phpCAS\handleLogoutRequests
static handleLogoutRequests($check_client=true, $allowed_clients=false)
Definition: CAS.php:1272
phpCAS\setServerProxyValidateURL
static setServerProxyValidateURL($url='')
Definition: CAS.php:1352
phpCAS\logout
static logout($params="")
Definition: CAS.php:1430
phpCAS\setFixedServiceURL
static setFixedServiceURL($url)
Definition: CAS.php:1566
DEFAULT_DEBUG_DIR
const DEFAULT_DEBUG_DIR
Definition: CAS.php:254
phpCAS\setCasServerCACert
static setCasServerCACert($cert, $validate_cn=true)
Definition: CAS.php:1620
phpCAS\renewAuthentication
static renewAuthentication()
Definition: CAS.php:1119
phpCAS\setVerbose
static setVerbose($verbose)
Definition: CAS.php:481
phpCAS\_validateProxyExists
static _validateProxyExists()
Definition: CAS.php:1845
phpCAS\isAuthenticated
static isAuthenticated()
Definition: CAS.php:1139
phpCAS\logoutWithRedirectService
static logoutWithRedirectService($service)
Definition: CAS.php:1463
phpCAS\traceBegin
static traceBegin()
Definition: CAS.php:591
phpCAS\retrievePT
static retrievePT($target_service, & $err_code, & $err_msg)
Definition: CAS.php:1600
phpCAS\setDebug
static setDebug($filename='')
Definition: CAS.php:439
phpCAS\setPGTStorage
static setPGTStorage($storage)
Definition: CAS.php:781
phpCAS\setServerLogoutURL
static setServerLogoutURL($url='')
Definition: CAS.php:1408
CAS_Client
Definition: Client.php:51
phpCAS\getServerLogoutURL
static getServerLogoutURL()
Definition: CAS.php:1393
phpCAS\setPGTStorageFile
static setPGTStorageFile($path='')
Definition: CAS.php:833
phpCAS\setCasClient
static setCasClient(\CAS_Client $client)
Definition: CAS.php:1857
$auth
if(isset($_REQUEST['logout'])) if(isset($_REQUEST['login'])) $auth
Definition: example_gateway.php:47
phpCAS\_validateClientExists
static _validateClientExists()
Definition: CAS.php:1831
CAS_OutOfSequenceBeforeProxyException
Definition: OutOfSequenceBeforeProxyException.php:43
phpCAS\setNoCasServerValidation
static setNoCasServerValidation()
Definition: CAS.php:1639
phpCAS\addRebroadcastHeader
static addRebroadcastHeader($header)
Definition: CAS.php:1810
phpCAS\client
static client($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true)
Definition: CAS.php:338
CAS_OutOfSequenceBeforeClientException
Definition: OutOfSequenceBeforeClientException.php:43
phpCAS\$_PHPCAS_DEBUG
static $_PHPCAS_DEBUG
Definition: CAS.php:302
phpCAS\hasAttributes
static hasAttributes()
Definition: CAS.php:1213
phpCAS\hasAttribute
static hasAttribute($key)
Definition: CAS.php:1233
phpCAS\$_PHPCAS_CLIENT
static $_PHPCAS_CLIENT
Definition: CAS.php:287
phpCAS\getServerLoginURL
static getServerLoginURL()
Definition: CAS.php:1285