00001 <?php
00002
00039
00040
00041
00042
00043 if (php_sapi_name() != 'cli') {
00044 if (!isset($_SERVER['REQUEST_URI'])) {
00045 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
00046 }
00047 }
00048
00049
00050 if (!defined('E_USER_DEPRECATED')) {
00051 define('E_USER_DEPRECATED', E_USER_NOTICE);
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00066 define('PHPCAS_VERSION', '1.3.2');
00067
00076 define("CAS_VERSION_1_0", '1.0');
00080 define("CAS_VERSION_2_0", '2.0');
00081
00082
00083
00084
00085
00089 define("SAML_VERSION_1_1", 'S1');
00090
00094 define("SAML_XML_HEADER", '<?xml version="1.0" encoding="UTF-8"?>');
00095
00099 define("SAML_SOAP_ENV", '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/>');
00100
00104 define("SAML_SOAP_BODY", '<SOAP-ENV:Body>');
00105
00109 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">');
00110 define("SAMLP_REQUEST_CLOSE", '</samlp:Request>');
00111
00115 define("SAML_ASSERTION_ARTIFACT", '<samlp:AssertionArtifact>');
00116
00120 define("SAML_ASSERTION_ARTIFACT_CLOSE", '</samlp:AssertionArtifact>');
00121
00125 define("SAML_SOAP_BODY_CLOSE", '</SOAP-ENV:Body>');
00126
00130 define("SAML_SOAP_ENV_CLOSE", '</SOAP-ENV:Envelope>');
00131
00135 define("SAML_ATTRIBUTES", 'SAMLATTRIBS');
00136
00142
00143
00144
00148 define("CAS_PGT_STORAGE_FILE_DEFAULT_PATH", session_save_path());
00150
00151
00152
00161 define("PHPCAS_SERVICE_OK", 0);
00166 define("PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE", 1);
00171 define("PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE", 2);
00176 define("PHPCAS_SERVICE_PT_FAILURE", 3);
00180 define("PHPCAS_SERVICE_NOT_AVAILABLE", 4);
00181
00182
00183
00184
00188 define("PHPCAS_PROXIED_SERVICE_HTTP_GET", 'CAS_ProxiedService_Http_Get');
00192 define("PHPCAS_PROXIED_SERVICE_HTTP_POST", 'CAS_ProxiedService_Http_Post');
00196 define("PHPCAS_PROXIED_SERVICE_IMAP", 'CAS_ProxiedService_Imap');
00197
00198
00200
00201
00202
00208 define("PHPCAS_LANG_ENGLISH", 'CAS_Languages_English');
00209 define("PHPCAS_LANG_FRENCH", 'CAS_Languages_French');
00210 define("PHPCAS_LANG_GREEK", 'CAS_Languages_Greek');
00211 define("PHPCAS_LANG_GERMAN", 'CAS_Languages_German');
00212 define("PHPCAS_LANG_JAPANESE", 'CAS_Languages_Japanese');
00213 define("PHPCAS_LANG_SPANISH", 'CAS_Languages_Spanish');
00214 define("PHPCAS_LANG_CATALAN", 'CAS_Languages_Catalan');
00215
00226 define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);
00227
00229
00230
00231
00240 define('DEFAULT_DEBUG_DIR', '/tmp/');
00241
00244
00245 require_once dirname(__FILE__) . '/CAS/Autoload.php';
00246
00264 class phpCAS
00265 {
00266
00272 private static $_PHPCAS_CLIENT;
00273
00280 private static $_PHPCAS_INIT_CALL;
00281
00287 private static $_PHPCAS_DEBUG;
00288
00289
00290
00291
00292
00293
00314 public static function client($server_version, $server_hostname,
00315 $server_port, $server_uri, $changeSessionID = true
00316 ) {
00317 phpCAS :: traceBegin();
00318 if (is_object(self::$_PHPCAS_CLIENT)) {
00319 phpCAS :: error(self::$_PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . self::$_PHPCAS_INIT_CALL['file'] . ':' . self::$_PHPCAS_INIT_CALL['line'] . ')');
00320 }
00321 if (gettype($server_version) != 'string') {
00322 phpCAS :: error('type mismatched for parameter $server_version (should be `string\')');
00323 }
00324 if (gettype($server_hostname) != 'string') {
00325 phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')');
00326 }
00327 if (gettype($server_port) != 'integer') {
00328 phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')');
00329 }
00330 if (gettype($server_uri) != 'string') {
00331 phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')');
00332 }
00333
00334
00335 $dbg = debug_backtrace();
00336 self::$_PHPCAS_INIT_CALL = array (
00337 'done' => true,
00338 'file' => $dbg[0]['file'],
00339 'line' => $dbg[0]['line'],
00340 'method' => __CLASS__ . '::' . __FUNCTION__
00341 );
00342
00343
00344 self::$_PHPCAS_CLIENT = new CAS_Client(
00345 $server_version, false, $server_hostname, $server_port, $server_uri,
00346 $changeSessionID
00347 );
00348 phpCAS :: traceEnd();
00349 }
00350
00366 public static function proxy($server_version, $server_hostname,
00367 $server_port, $server_uri, $changeSessionID = true
00368 ) {
00369 phpCAS :: traceBegin();
00370 if (is_object(self::$_PHPCAS_CLIENT)) {
00371 phpCAS :: error(self::$_PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . self::$_PHPCAS_INIT_CALL['file'] . ':' . self::$_PHPCAS_INIT_CALL['line'] . ')');
00372 }
00373 if (gettype($server_version) != 'string') {
00374 phpCAS :: error('type mismatched for parameter $server_version (should be `string\')');
00375 }
00376 if (gettype($server_hostname) != 'string') {
00377 phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')');
00378 }
00379 if (gettype($server_port) != 'integer') {
00380 phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')');
00381 }
00382 if (gettype($server_uri) != 'string') {
00383 phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')');
00384 }
00385
00386
00387 $dbg = debug_backtrace();
00388 self::$_PHPCAS_INIT_CALL = array (
00389 'done' => true,
00390 'file' => $dbg[0]['file'],
00391 'line' => $dbg[0]['line'],
00392 'method' => __CLASS__ . '::' . __FUNCTION__
00393 );
00394
00395
00396 self::$_PHPCAS_CLIENT = new CAS_Client(
00397 $server_version, true, $server_hostname, $server_port, $server_uri,
00398 $changeSessionID
00399 );
00400 phpCAS :: traceEnd();
00401 }
00402
00404
00405
00406
00407
00421 public static function setDebug($filename = '')
00422 {
00423 if ($filename != false && gettype($filename) != 'string') {
00424 phpCAS :: error('type mismatched for parameter $dbg (should be false or the name of the log file)');
00425 }
00426 if ($filename === false) {
00427 self::$_PHPCAS_DEBUG['filename'] = false;
00428
00429 } else {
00430 if (empty ($filename)) {
00431 if (preg_match('/^Win.*/', getenv('OS'))) {
00432 if (isset ($_ENV['TMP'])) {
00433 $debugDir = $_ENV['TMP'] . '/';
00434 } else {
00435 $debugDir = '';
00436 }
00437 } else {
00438 $debugDir = DEFAULT_DEBUG_DIR;
00439 }
00440 $filename = $debugDir . 'phpCAS.log';
00441 }
00442
00443 if (empty (self::$_PHPCAS_DEBUG['unique_id'])) {
00444 self::$_PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4);
00445 }
00446
00447 self::$_PHPCAS_DEBUG['filename'] = $filename;
00448 self::$_PHPCAS_DEBUG['indent'] = 0;
00449
00450 phpCAS :: trace('START phpCAS-' . PHPCAS_VERSION . ' ******************');
00451 }
00452 }
00453
00454
00463 public static function log($str)
00464 {
00465 $indent_str = ".";
00466
00467
00468 if (!empty(self::$_PHPCAS_DEBUG['filename'])) {
00469
00470
00471 if (!file_exists(self::$_PHPCAS_DEBUG['filename'])) {
00472 touch(self::$_PHPCAS_DEBUG['filename']);
00473
00474 @chmod(self::$_PHPCAS_DEBUG['filename'], 0600);
00475 }
00476 for ($i = 0; $i < self::$_PHPCAS_DEBUG['indent']; $i++) {
00477
00478 $indent_str .= '| ';
00479 }
00480
00481
00482 $str2 = str_replace("\n", "\n" . self::$_PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str, $str);
00483 error_log(self::$_PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str . $str2 . "\n", 3, self::$_PHPCAS_DEBUG['filename']);
00484 }
00485
00486 }
00487
00497 public static function error($msg)
00498 {
00499 $dbg = debug_backtrace();
00500 $function = '?';
00501 $file = '?';
00502 $line = '?';
00503 if (is_array($dbg)) {
00504 for ($i = 1; $i < sizeof($dbg); $i++) {
00505 if (is_array($dbg[$i]) && isset($dbg[$i]['class']) ) {
00506 if ($dbg[$i]['class'] == __CLASS__) {
00507 $function = $dbg[$i]['function'];
00508 $file = $dbg[$i]['file'];
00509 $line = $dbg[$i]['line'];
00510 }
00511 }
00512 }
00513 }
00514 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";
00515 phpCAS :: trace($msg);
00516 phpCAS :: traceEnd();
00517
00518 throw new CAS_GracefullTerminationException(__CLASS__ . "::" . $function . '(): ' . $msg);
00519 }
00520
00528 public static function trace($str)
00529 {
00530 $dbg = debug_backtrace();
00531 phpCAS :: log($str . ' [' . basename($dbg[0]['file']) . ':' . $dbg[0]['line'] . ']');
00532 }
00533
00539 public static function traceBegin()
00540 {
00541 $dbg = debug_backtrace();
00542 $str = '=> ';
00543 if (!empty ($dbg[1]['class'])) {
00544 $str .= $dbg[1]['class'] . '::';
00545 }
00546 $str .= $dbg[1]['function'] . '(';
00547 if (is_array($dbg[1]['args'])) {
00548 foreach ($dbg[1]['args'] as $index => $arg) {
00549 if ($index != 0) {
00550 $str .= ', ';
00551 }
00552 if (is_object($arg)) {
00553 $str .= get_class($arg);
00554 } else {
00555 $str .= str_replace(array("\r\n", "\n", "\r"), "", var_export($arg, true));
00556 }
00557 }
00558 }
00559 if (isset($dbg[1]['file'])) {
00560 $file = basename($dbg[1]['file']);
00561 } else {
00562 $file = 'unknown_file';
00563 }
00564 if (isset($dbg[1]['line'])) {
00565 $line = $dbg[1]['line'];
00566 } else {
00567 $line = 'unknown_line';
00568 }
00569 $str .= ') [' . $file . ':' . $line . ']';
00570 phpCAS :: log($str);
00571 if (!isset(self::$_PHPCAS_DEBUG['indent'])) {
00572 self::$_PHPCAS_DEBUG['indent'] = 0;
00573 } else {
00574 self::$_PHPCAS_DEBUG['indent']++;
00575 }
00576 }
00577
00586 public static function traceEnd($res = '')
00587 {
00588 if (empty(self::$_PHPCAS_DEBUG['indent'])) {
00589 self::$_PHPCAS_DEBUG['indent'] = 0;
00590 } else {
00591 self::$_PHPCAS_DEBUG['indent']--;
00592 }
00593 $dbg = debug_backtrace();
00594 $str = '';
00595 if (is_object($res)) {
00596 $str .= '<= ' . get_class($res);
00597 } else {
00598 $str .= '<= ' . str_replace(array("\r\n", "\n", "\r"), "", var_export($res, true));
00599 }
00600
00601 phpCAS :: log($str);
00602 }
00603
00609 public static function traceExit()
00610 {
00611 phpCAS :: log('exit()');
00612 while (self::$_PHPCAS_DEBUG['indent'] > 0) {
00613 phpCAS :: log('-');
00614 self::$_PHPCAS_DEBUG['indent']--;
00615 }
00616 }
00617
00619
00620
00621
00637 public static function setLang($lang)
00638 {
00639 if (!is_object(self::$_PHPCAS_CLIENT)) {
00640 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00641 }
00642 if (gettype($lang) != 'string') {
00643 phpCAS :: error('type mismatched for parameter $lang (should be `string\')');
00644 }
00645 self::$_PHPCAS_CLIENT->setLang($lang);
00646 }
00647
00649
00650
00651
00662 public static function getVersion()
00663 {
00664 return PHPCAS_VERSION;
00665 }
00666
00668
00669
00670
00683 public static function setHTMLHeader($header)
00684 {
00685 if (!is_object(self::$_PHPCAS_CLIENT)) {
00686 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00687 }
00688 if (gettype($header) != 'string') {
00689 phpCAS :: error('type mismatched for parameter $header (should be `string\')');
00690 }
00691 self::$_PHPCAS_CLIENT->setHTMLHeader($header);
00692 }
00693
00701 public static function setHTMLFooter($footer)
00702 {
00703 if (!is_object(self::$_PHPCAS_CLIENT)) {
00704 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00705 }
00706 if (gettype($footer) != 'string') {
00707 phpCAS :: error('type mismatched for parameter $footer (should be `string\')');
00708 }
00709 self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
00710 }
00711
00713
00714
00715
00729 public static function setPGTStorage($storage)
00730 {
00731 phpCAS :: traceBegin();
00732 if (!is_object(self::$_PHPCAS_CLIENT)) {
00733 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00734 }
00735 if (!self::$_PHPCAS_CLIENT->isProxy()) {
00736 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00737 }
00738 if (self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
00739 phpCAS :: error('this method should only be called before ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() (called at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ')');
00740 }
00741 if ( !($storage instanceof CAS_PGTStorage) ) {
00742 phpCAS :: error('type mismatched for parameter $storage (should be a CAS_PGTStorage `object\')');
00743 }
00744 self::$_PHPCAS_CLIENT->setPGTStorage($storage);
00745 phpCAS :: traceEnd();
00746 }
00747
00765 public static function setPGTStorageDb($dsn_or_pdo, $username='',
00766 $password='', $table='', $driver_options=null
00767 ) {
00768 phpCAS :: traceBegin();
00769 if (!is_object(self::$_PHPCAS_CLIENT)) {
00770 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00771 }
00772 if (!self::$_PHPCAS_CLIENT->isProxy()) {
00773 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00774 }
00775 if (self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
00776 phpCAS :: error('this method should only be called before ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() (called at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ')');
00777 }
00778 if (gettype($username) != 'string') {
00779 phpCAS :: error('type mismatched for parameter $username (should be `string\')');
00780 }
00781 if (gettype($password) != 'string') {
00782 phpCAS :: error('type mismatched for parameter $password (should be `string\')');
00783 }
00784 if (gettype($table) != 'string') {
00785 phpCAS :: error('type mismatched for parameter $table (should be `string\')');
00786 }
00787 self::$_PHPCAS_CLIENT->setPGTStorageDb($dsn_or_pdo, $username, $password, $table, $driver_options);
00788 phpCAS :: traceEnd();
00789 }
00790
00799 public static function setPGTStorageFile($path = '')
00800 {
00801 phpCAS :: traceBegin();
00802 if (!is_object(self::$_PHPCAS_CLIENT)) {
00803 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00804 }
00805 if (!self::$_PHPCAS_CLIENT->isProxy()) {
00806 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00807 }
00808 if (self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
00809 phpCAS :: error('this method should only be called before ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() (called at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ')');
00810 }
00811 if (gettype($path) != 'string') {
00812 phpCAS :: error('type mismatched for parameter $path (should be `string\')');
00813 }
00814 self::$_PHPCAS_CLIENT->setPGTStorageFile($path);
00815 phpCAS :: traceEnd();
00816 }
00818
00819
00820
00836 public static function getProxiedService ($type)
00837 {
00838 phpCAS :: traceBegin();
00839 if (!is_object(self::$_PHPCAS_CLIENT)) {
00840 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00841 }
00842 if (!self::$_PHPCAS_CLIENT->isProxy()) {
00843 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00844 }
00845 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
00846 phpCAS :: error('this method should only be called after the programmer is sure the user has been authenticated (by calling ' . __CLASS__ . '::checkAuthentication() or ' . __CLASS__ . '::forceAuthentication()');
00847 }
00848 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
00849 phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
00850 }
00851 if (gettype($type) != 'string') {
00852 phpCAS :: error('type mismatched for parameter $type (should be `string\')');
00853 }
00854
00855 $res = self::$_PHPCAS_CLIENT->getProxiedService($type);
00856
00857 phpCAS :: traceEnd();
00858 return $res;
00859 }
00860
00873 public static function initializeProxiedService (CAS_ProxiedService $proxiedService)
00874 {
00875 if (!is_object(self::$_PHPCAS_CLIENT)) {
00876 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00877 }
00878 if (!self::$_PHPCAS_CLIENT->isProxy()) {
00879 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00880 }
00881 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
00882 phpCAS :: error('this method should only be called after the programmer is sure the user has been authenticated (by calling ' . __CLASS__ . '::checkAuthentication() or ' . __CLASS__ . '::forceAuthentication()');
00883 }
00884 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
00885 phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
00886 }
00887
00888 self::$_PHPCAS_CLIENT->initializeProxiedService($proxiedService);
00889 }
00890
00906 public static function serviceWeb($url, & $err_code, & $output)
00907 {
00908 phpCAS :: traceBegin();
00909 if (!is_object(self::$_PHPCAS_CLIENT)) {
00910 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00911 }
00912 if (!self::$_PHPCAS_CLIENT->isProxy()) {
00913 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00914 }
00915 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
00916 phpCAS :: error('this method should only be called after the programmer is sure the user has been authenticated (by calling ' . __CLASS__ . '::checkAuthentication() or ' . __CLASS__ . '::forceAuthentication()');
00917 }
00918 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
00919 phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
00920 }
00921 if (gettype($url) != 'string') {
00922 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
00923 }
00924
00925 $res = self::$_PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
00926
00927 phpCAS :: traceEnd($res);
00928 return $res;
00929 }
00930
00950 public static function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
00951 {
00952 phpCAS :: traceBegin();
00953 if (!is_object(self::$_PHPCAS_CLIENT)) {
00954 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00955 }
00956 if (!self::$_PHPCAS_CLIENT->isProxy()) {
00957 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00958 }
00959 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
00960 phpCAS :: error('this method should only be called after the programmer is sure the user has been authenticated (by calling ' . __CLASS__ . '::checkAuthentication() or ' . __CLASS__ . '::forceAuthentication()');
00961 }
00962 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
00963 phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
00964 }
00965 if (gettype($url) != 'string') {
00966 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
00967 }
00968
00969 if (gettype($flags) != 'integer') {
00970 phpCAS :: error('type mismatched for parameter $flags (should be `integer\')');
00971 }
00972
00973 $res = self::$_PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
00974
00975 phpCAS :: traceEnd($res);
00976 return $res;
00977 }
00978
00980
00981
00982
00999 public static function setCacheTimesForAuthRecheck($n)
01000 {
01001 if (!is_object(self::$_PHPCAS_CLIENT)) {
01002 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01003 }
01004 if (gettype($n) != 'integer') {
01005 phpCAS :: error('type mismatched for parameter $n (should be `integer\')');
01006 }
01007 self::$_PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
01008 }
01009
01029 public static function setPostAuthenticateCallback ($function, array $additionalArgs = array())
01030 {
01031 if (!is_object(self::$_PHPCAS_CLIENT)) {
01032 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01033 }
01034
01035 self::$_PHPCAS_CLIENT->setPostAuthenticateCallback($function, $additionalArgs);
01036 }
01037
01052 public static function setSingleSignoutCallback ($function, array $additionalArgs = array())
01053 {
01054 if (!is_object(self::$_PHPCAS_CLIENT)) {
01055 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01056 }
01057
01058 self::$_PHPCAS_CLIENT->setSingleSignoutCallback($function, $additionalArgs);
01059 }
01060
01071 public static function checkAuthentication()
01072 {
01073 phpCAS :: traceBegin();
01074 if (!is_object(self::$_PHPCAS_CLIENT)) {
01075 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01076 }
01077
01078 $auth = self::$_PHPCAS_CLIENT->checkAuthentication();
01079
01080
01081 self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
01082
01083 phpCAS :: traceEnd($auth);
01084 return $auth;
01085 }
01086
01094 public static function forceAuthentication()
01095 {
01096 phpCAS :: traceBegin();
01097 if (!is_object(self::$_PHPCAS_CLIENT)) {
01098 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01099 }
01100
01101 $auth = self::$_PHPCAS_CLIENT->forceAuthentication();
01102
01103
01104 self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
01105
01106
01107
01108
01109
01110
01111
01112
01113 phpCAS :: traceEnd();
01114 return $auth;
01115 }
01116
01122 public static function renewAuthentication()
01123 {
01124 phpCAS :: traceBegin();
01125 if (!is_object(self::$_PHPCAS_CLIENT)) {
01126 phpCAS :: error('this method should not be called before' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01127 }
01128 $auth = self::$_PHPCAS_CLIENT->renewAuthentication();
01129
01130
01131 self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
01132
01133
01134 phpCAS :: traceEnd();
01135 }
01136
01143 public static function isAuthenticated()
01144 {
01145 phpCAS :: traceBegin();
01146 if (!is_object(self::$_PHPCAS_CLIENT)) {
01147 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01148 }
01149
01150
01151 $auth = self::$_PHPCAS_CLIENT->isAuthenticated();
01152
01153
01154 self::$_PHPCAS_CLIENT->markAuthenticationCall($auth);
01155
01156 phpCAS :: traceEnd($auth);
01157 return $auth;
01158 }
01159
01167 public static function isSessionAuthenticated()
01168 {
01169 if (!is_object(self::$_PHPCAS_CLIENT)) {
01170 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01171 }
01172 return (self::$_PHPCAS_CLIENT->isSessionAuthenticated());
01173 }
01174
01182 public static function getUser()
01183 {
01184 if (!is_object(self::$_PHPCAS_CLIENT)) {
01185 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01186 }
01187 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
01188 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01189 }
01190 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
01191 phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
01192 }
01193 return self::$_PHPCAS_CLIENT->getUser();
01194 }
01195
01204 public static function getAttributes()
01205 {
01206 if (!is_object(self::$_PHPCAS_CLIENT)) {
01207 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01208 }
01209 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
01210 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01211 }
01212 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
01213 phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
01214 }
01215 return self::$_PHPCAS_CLIENT->getAttributes();
01216 }
01217
01226 public static function hasAttributes()
01227 {
01228 if (!is_object(self::$_PHPCAS_CLIENT)) {
01229 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01230 }
01231 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
01232 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01233 }
01234 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
01235 phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
01236 }
01237 return self::$_PHPCAS_CLIENT->hasAttributes();
01238 }
01239
01249 public static function hasAttribute($key)
01250 {
01251 if (!is_object(self::$_PHPCAS_CLIENT)) {
01252 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01253 }
01254 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
01255 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01256 }
01257 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
01258 phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
01259 }
01260 return self::$_PHPCAS_CLIENT->hasAttribute($key);
01261 }
01262
01272 public static function getAttribute($key)
01273 {
01274 if (!is_object(self::$_PHPCAS_CLIENT)) {
01275 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01276 }
01277 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCalled()) {
01278 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01279 }
01280 if (!self::$_PHPCAS_CLIENT->wasAuthenticationCallSuccessful()) {
01281 phpCAS :: error('authentication was checked (by ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerMethod() . '() at ' . self::$_PHPCAS_CLIENT->getAuthenticationCallerFile() . ':' . self::$_PHPCAS_CLIENT->getAuthenticationCallerLine() . ') but the method returned false');
01282 }
01283 return self::$_PHPCAS_CLIENT->getAttribute($key);
01284 }
01285
01294 public static function handleLogoutRequests($check_client = true, $allowed_clients = false)
01295 {
01296 if (!is_object(self::$_PHPCAS_CLIENT)) {
01297 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01298 }
01299 return (self::$_PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
01300 }
01301
01308 public static function getServerLoginURL()
01309 {
01310 if (!is_object(self::$_PHPCAS_CLIENT)) {
01311 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01312 }
01313 return self::$_PHPCAS_CLIENT->getServerLoginURL();
01314 }
01315
01324 public static function setServerLoginURL($url = '')
01325 {
01326 phpCAS :: traceBegin();
01327 if (!is_object(self::$_PHPCAS_CLIENT)) {
01328 phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
01329 }
01330 if (gettype($url) != 'string') {
01331 phpCAS :: error('type mismatched for parameter $url (should be `string`)');
01332 }
01333 self::$_PHPCAS_CLIENT->setServerLoginURL($url);
01334 phpCAS :: traceEnd();
01335 }
01336
01345 public static function setServerServiceValidateURL($url = '')
01346 {
01347 phpCAS :: traceBegin();
01348 if (!is_object(self::$_PHPCAS_CLIENT)) {
01349 phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
01350 }
01351 if (gettype($url) != 'string') {
01352 phpCAS :: error('type mismatched for parameter $url (should be `string`)');
01353 }
01354 self::$_PHPCAS_CLIENT->setServerServiceValidateURL($url);
01355 phpCAS :: traceEnd();
01356 }
01357
01366 public static function setServerProxyValidateURL($url = '')
01367 {
01368 phpCAS :: traceBegin();
01369 if (!is_object(self::$_PHPCAS_CLIENT)) {
01370 phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
01371 }
01372 if (gettype($url) != 'string') {
01373 phpCAS :: error('type mismatched for parameter $url (should be `string`)');
01374 }
01375 self::$_PHPCAS_CLIENT->setServerProxyValidateURL($url);
01376 phpCAS :: traceEnd();
01377 }
01378
01386 public static function setServerSamlValidateURL($url = '')
01387 {
01388 phpCAS :: traceBegin();
01389 if (!is_object(self::$_PHPCAS_CLIENT)) {
01390 phpCAS :: error('this method should only be called after' . __CLASS__ . '::client()');
01391 }
01392 if (gettype($url) != 'string') {
01393 phpCAS :: error('type mismatched for parameter $url (should be`string\')');
01394 }
01395 self::$_PHPCAS_CLIENT->setServerSamlValidateURL($url);
01396 phpCAS :: traceEnd();
01397 }
01398
01405 public static function getServerLogoutURL()
01406 {
01407 if (!is_object(self::$_PHPCAS_CLIENT)) {
01408 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01409 }
01410 return self::$_PHPCAS_CLIENT->getServerLogoutURL();
01411 }
01412
01421 public static function setServerLogoutURL($url = '')
01422 {
01423 phpCAS :: traceBegin();
01424 if (!is_object(self::$_PHPCAS_CLIENT)) {
01425 phpCAS :: error(
01426 'this method should only be called after' . __CLASS__ . '::client()'
01427 );
01428 }
01429 if (gettype($url) != 'string') {
01430 phpCAS :: error(
01431 'type mismatched for parameter $url (should be `string`)'
01432 );
01433 }
01434 self::$_PHPCAS_CLIENT->setServerLogoutURL($url);
01435 phpCAS :: traceEnd();
01436 }
01437
01446 public static function logout($params = "")
01447 {
01448 phpCAS :: traceBegin();
01449 if (!is_object(self::$_PHPCAS_CLIENT)) {
01450 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01451 }
01452 $parsedParams = array ();
01453 if ($params != "") {
01454 if (is_string($params)) {
01455 phpCAS :: error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');
01456 }
01457 if (!is_array($params)) {
01458 phpCAS :: error('type mismatched for parameter $params (should be `array\')');
01459 }
01460 foreach ($params as $key => $value) {
01461 if ($key != "service" && $key != "url") {
01462 phpCAS :: error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');
01463 }
01464 $parsedParams[$key] = $value;
01465 }
01466 }
01467 self::$_PHPCAS_CLIENT->logout($parsedParams);
01468
01469 phpCAS :: traceEnd();
01470 }
01471
01480 public static function logoutWithRedirectService($service)
01481 {
01482 phpCAS :: traceBegin();
01483 if (!is_object(self::$_PHPCAS_CLIENT)) {
01484 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01485 }
01486 if (!is_string($service)) {
01487 phpCAS :: error('type mismatched for parameter $service (should be `string\')');
01488 }
01489 self::$_PHPCAS_CLIENT->logout(array ( "service" => $service ));
01490
01491 phpCAS :: traceEnd();
01492 }
01493
01504 public static function logoutWithUrl($url)
01505 {
01506 trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
01507 phpCAS :: traceBegin();
01508 if (!is_object(self::$_PHPCAS_CLIENT)) {
01509 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01510 }
01511 if (!is_string($url)) {
01512 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01513 }
01514 self::$_PHPCAS_CLIENT->logout(array ( "url" => $url ));
01515
01516 phpCAS :: traceEnd();
01517 }
01518
01531 public static function logoutWithRedirectServiceAndUrl($service, $url)
01532 {
01533 trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
01534 phpCAS :: traceBegin();
01535 if (!is_object(self::$_PHPCAS_CLIENT)) {
01536 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01537 }
01538 if (!is_string($service)) {
01539 phpCAS :: error('type mismatched for parameter $service (should be `string\')');
01540 }
01541 if (!is_string($url)) {
01542 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01543 }
01544 self::$_PHPCAS_CLIENT->logout(
01545 array (
01546 "service" => $service,
01547 "url" => $url
01548 )
01549 );
01550
01551 phpCAS :: traceEnd();
01552 }
01553
01563 public static function setFixedCallbackURL($url = '')
01564 {
01565 phpCAS :: traceBegin();
01566 if (!is_object(self::$_PHPCAS_CLIENT)) {
01567 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01568 }
01569 if (!self::$_PHPCAS_CLIENT->isProxy()) {
01570 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01571 }
01572 if (gettype($url) != 'string') {
01573 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01574 }
01575 self::$_PHPCAS_CLIENT->setCallbackURL($url);
01576 phpCAS :: traceEnd();
01577 }
01578
01587 public static function setFixedServiceURL($url)
01588 {
01589 phpCAS :: traceBegin();
01590 if (!is_object(self::$_PHPCAS_CLIENT)) {
01591 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01592 }
01593 if (gettype($url) != 'string') {
01594 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01595 }
01596 self::$_PHPCAS_CLIENT->setURL($url);
01597 phpCAS :: traceEnd();
01598 }
01599
01605 public static function getServiceURL()
01606 {
01607 if (!is_object(self::$_PHPCAS_CLIENT)) {
01608 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01609 }
01610 return (self::$_PHPCAS_CLIENT->getURL());
01611 }
01612
01622 public static function retrievePT($target_service, & $err_code, & $err_msg)
01623 {
01624 if (!is_object(self::$_PHPCAS_CLIENT)) {
01625 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01626 }
01627 if (gettype($target_service) != 'string') {
01628 phpCAS :: error('type mismatched for parameter $target_service(should be `string\')');
01629 }
01630 return (self::$_PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
01631 }
01632
01642 public static function setCasServerCACert($cert, $validate_cn = true)
01643 {
01644 phpCAS :: traceBegin();
01645 if (!is_object(self::$_PHPCAS_CLIENT)) {
01646 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01647 }
01648 if (gettype($cert) != 'string') {
01649 phpCAS :: error('type mismatched for parameter $cert (should be `string\')');
01650 }
01651 if (gettype($validate_cn) != 'boolean') {
01652 phpCAS :: error('type mismatched for parameter $validate_cn (should be `boolean\')');
01653 }
01654 self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
01655 phpCAS :: traceEnd();
01656 }
01657
01663 public static function setNoCasServerValidation()
01664 {
01665 phpCAS :: traceBegin();
01666 if (!is_object(self::$_PHPCAS_CLIENT)) {
01667 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01668 }
01669 phpCAS :: trace('You have configured no validation of the legitimacy of the cas server. This is not recommended for production use.');
01670 self::$_PHPCAS_CLIENT->setNoCasServerValidation();
01671 phpCAS :: traceEnd();
01672 }
01673
01674
01684 public static function setNoClearTicketsFromUrl()
01685 {
01686 phpCAS :: traceBegin();
01687 if (!is_object(self::$_PHPCAS_CLIENT)) {
01688 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01689 }
01690 self::$_PHPCAS_CLIENT->setNoClearTicketsFromUrl();
01691 phpCAS :: traceEnd();
01692 }
01693
01705 public static function setExtraCurlOption($key, $value)
01706 {
01707 phpCAS :: traceBegin();
01708 if (!is_object(self::$_PHPCAS_CLIENT)) {
01709 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01710 }
01711 self::$_PHPCAS_CLIENT->setExtraCurlOption($key, $value);
01712 phpCAS :: traceEnd();
01713 }
01714
01751 public static function allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
01752 {
01753 phpCAS :: traceBegin();
01754 if (!is_object(self::$_PHPCAS_CLIENT)) {
01755 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01756 }
01757 if (self::$_PHPCAS_CLIENT->getServerVersion() !== CAS_VERSION_2_0) {
01758 phpCAS :: error('this method can only be used with the cas 2.0 protool');
01759 }
01760 self::$_PHPCAS_CLIENT->getAllowedProxyChains()->allowProxyChain($proxy_chain);
01761 phpCAS :: traceEnd();
01762 }
01763
01773 public static function getProxies ()
01774 {
01775 if ( !is_object(self::$_PHPCAS_CLIENT) ) {
01776 phpCAS::error('this method should only be called after '.__CLASS__.'::client()');
01777 }
01778
01779 return(self::$_PHPCAS_CLIENT->getProxies());
01780 }
01781
01782
01783
01784
01785
01794 public static function addRebroadcastNode($rebroadcastNodeUrl)
01795 {
01796 phpCAS::traceBegin();
01797 phpCAS::log('rebroadcastNodeUrl:'.$rebroadcastNodeUrl);
01798 if (!is_object(self::$_PHPCAS_CLIENT)) {
01799 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01800 }
01801 if ( !(bool)preg_match("/^(http|https):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i", $rebroadcastNodeUrl)) {
01802 phpCAS::error('type mismatched for parameter $rebroadcastNodeUrl (should be `url\')');
01803 }
01804 self::$_PHPCAS_CLIENT->addRebroadcastNode($rebroadcastNodeUrl);
01805 phpCAS::traceEnd();
01806 }
01807
01816 public static function addRebroadcastHeader($header)
01817 {
01818 phpCAS :: traceBegin();
01819 if (!is_object(self::$_PHPCAS_CLIENT)) {
01820 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01821 }
01822 self::$_PHPCAS_CLIENT->addRebroadcastHeader($header);
01823 phpCAS :: traceEnd();
01824 }
01825 }
01826
01827
01828
01829
01830
01831
01832
01833
01841
01842
01843
01926
01927
01928
01980 ?>