00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009 if (!$_SERVER['REQUEST_URI']) {
00010 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];
00011 }
00012
00013
00014
00015
00016 if (version_compare(PHP_VERSION,'5','>=')) {
00017 require_once(dirname(__FILE__).'/CAS/domxml-php4-php5.php');
00018 }
00019
00027
00028
00029
00030
00031
00032
00033
00034
00038 define('PHPCAS_VERSION','1.0.1');
00039
00040
00041
00042
00051 define("CAS_VERSION_1_0",'1.0');
00055 define("CAS_VERSION_2_0",'2.0');
00056
00062
00063
00064
00068 define("CAS_PGT_STORAGE_FILE_DEFAULT_PATH",'/tmp');
00072 define("CAS_PGT_STORAGE_FILE_FORMAT_PLAIN",'plain');
00076 define("CAS_PGT_STORAGE_FILE_FORMAT_XML",'xml');
00080 define("CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT",CAS_PGT_STORAGE_FILE_FORMAT_PLAIN);
00081
00082
00083
00087 define("CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE",'mysql');
00091 define("CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME",'localhost');
00095 define("CAS_PGT_STORAGE_DB_DEFAULT_PORT",'');
00099 define("CAS_PGT_STORAGE_DB_DEFAULT_DATABASE",'phpCAS');
00103 define("CAS_PGT_STORAGE_DB_DEFAULT_TABLE",'pgt');
00104
00106
00107
00108
00117 define("PHPCAS_SERVICE_OK",0);
00122 define("PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE",1);
00127 define("PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE",2);
00132 define("PHPCAS_SERVICE_PT_FAILURE",3);
00136 define("PHPCAS_SERVICE_NOT AVAILABLE",4);
00137
00139
00140
00141
00147 define("PHPCAS_LANG_ENGLISH", 'english');
00148 define("PHPCAS_LANG_FRENCH", 'french');
00149 define("PHPCAS_LANG_GREEK", 'greek');
00150 define("PHPCAS_LANG_GERMAN", 'german');
00151 define("PHPCAS_LANG_JAPANESE", 'japanese');
00152 define("PHPCAS_LANG_SPANISH", 'spanish');
00153 define("PHPCAS_LANG_CATALAN", 'catalan');
00154
00165 define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);
00166
00168
00169
00170
00179 define('DEFAULT_DEBUG_DIR','/tmp/');
00180
00182
00183
00184
00195 $GLOBALS['PHPCAS_CLIENT'] = null;
00196
00203 $GLOBALS['PHPCAS_INIT_CALL'] = array('done' => FALSE,
00204 'file' => '?',
00205 'line' => -1,
00206 'method' => '?');
00207
00214 $GLOBALS['PHPCAS_AUTH_CHECK_CALL'] = array('done' => FALSE,
00215 'file' => '?',
00216 'line' => -1,
00217 'method' => '?',
00218 'result' => FALSE);
00219
00225 $GLOBALS['PHPCAS_DEBUG'] = array('filename' => FALSE,
00226 'indent' => 0,
00227 'unique_id' => '');
00228
00231
00232
00233
00234
00235
00236 include_once(dirname(__FILE__).'/CAS/client.php');
00237
00238
00239
00240
00241
00256 class phpCAS
00257 {
00258
00259
00260
00261
00262
00282 function client($server_version,
00283 $server_hostname,
00284 $server_port,
00285 $server_uri,
00286 $start_session = true)
00287 {
00288 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
00289
00290 phpCAS::traceBegin();
00291 if ( is_object($PHPCAS_CLIENT) ) {
00292 phpCAS::error($PHPCAS_INIT_CALL['method'].'() has already been called (at '.$PHPCAS_INIT_CALL['file'].':'.$PHPCAS_INIT_CALL['line'].')');
00293 }
00294 if ( gettype($server_version) != 'string' ) {
00295 phpCAS::error('type mismatched for parameter $server_version (should be `string\')');
00296 }
00297 if ( gettype($server_hostname) != 'string' ) {
00298 phpCAS::error('type mismatched for parameter $server_hostname (should be `string\')');
00299 }
00300 if ( gettype($server_port) != 'integer' ) {
00301 phpCAS::error('type mismatched for parameter $server_port (should be `integer\')');
00302 }
00303 if ( gettype($server_uri) != 'string' ) {
00304 phpCAS::error('type mismatched for parameter $server_uri (should be `string\')');
00305 }
00306
00307
00308 $dbg = phpCAS::backtrace();
00309 $PHPCAS_INIT_CALL = array('done' => TRUE,
00310 'file' => $dbg[0]['file'],
00311 'line' => $dbg[0]['line'],
00312 'method' => __CLASS__.'::'.__FUNCTION__);
00313
00314
00315 $PHPCAS_CLIENT = new CASClient($server_version,FALSE,$server_hostname,$server_port,$server_uri,$start_session);
00316 phpCAS::traceEnd();
00317 }
00318
00333 function proxy($server_version,
00334 $server_hostname,
00335 $server_port,
00336 $server_uri,
00337 $start_session = true)
00338 {
00339 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
00340
00341 phpCAS::traceBegin();
00342 if ( is_object($PHPCAS_CLIENT) ) {
00343 phpCAS::error($PHPCAS_INIT_CALL['method'].'() has already been called (at '.$PHPCAS_INIT_CALL['file'].':'.$PHPCAS_INIT_CALL['line'].')');
00344 }
00345 if ( gettype($server_version) != 'string' ) {
00346 phpCAS::error('type mismatched for parameter $server_version (should be `string\')');
00347 }
00348 if ( gettype($server_hostname) != 'string' ) {
00349 phpCAS::error('type mismatched for parameter $server_hostname (should be `string\')');
00350 }
00351 if ( gettype($server_port) != 'integer' ) {
00352 phpCAS::error('type mismatched for parameter $server_port (should be `integer\')');
00353 }
00354 if ( gettype($server_uri) != 'string' ) {
00355 phpCAS::error('type mismatched for parameter $server_uri (should be `string\')');
00356 }
00357
00358
00359 $dbg = phpCAS::backtrace();
00360 $PHPCAS_INIT_CALL = array('done' => TRUE,
00361 'file' => $dbg[0]['file'],
00362 'line' => $dbg[0]['line'],
00363 'method' => __CLASS__.'::'.__FUNCTION__);
00364
00365
00366 $PHPCAS_CLIENT = new CASClient($server_version,TRUE,$server_hostname,$server_port,$server_uri,$start_session);
00367 phpCAS::traceEnd();
00368 }
00369
00371
00372
00373
00374
00385 function setDebug($filename='')
00386 {
00387 global $PHPCAS_DEBUG;
00388
00389 if ( $filename != FALSE && gettype($filename) != 'string' ) {
00390 phpCAS::error('type mismatched for parameter $dbg (should be FALSE or the name of the log file)');
00391 }
00392
00393 if ( empty($filename) ) {
00394 if ( preg_match('/^Win.*/',getenv('OS')) ) {
00395 if ( isset($_ENV['TMP']) ) {
00396 $debugDir = $_ENV['TMP'].'/';
00397 } else if ( isset($_ENV['TEMP']) ) {
00398 $debugDir = $_ENV['TEMP'].'/';
00399 } else {
00400 $debugDir = '';
00401 }
00402 } else {
00403 $debugDir = DEFAULT_DEBUG_DIR;
00404 }
00405 $filename = $debugDir . 'phpCAS.log';
00406 }
00407
00408 if ( empty($PHPCAS_DEBUG['unique_id']) ) {
00409 $PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))),0,4);
00410 }
00411
00412 $PHPCAS_DEBUG['filename'] = $filename;
00413
00414 phpCAS::trace('START ******************');
00415 }
00416
00427 function backtrace()
00428 {
00429 if ( function_exists('debug_backtrace') ) {
00430 return debug_backtrace();
00431 } else {
00432
00433 return array();
00434 }
00435 }
00436
00444 function log($str)
00445 {
00446 $indent_str = ".";
00447 global $PHPCAS_DEBUG;
00448
00449 if ( $PHPCAS_DEBUG['filename'] ) {
00450 for ($i=0;$i<$PHPCAS_DEBUG['indent'];$i++) {
00451 $indent_str .= '| ';
00452 }
00453 error_log($PHPCAS_DEBUG['unique_id'].' '.$indent_str.$str."\n",3,$PHPCAS_DEBUG['filename']);
00454 }
00455
00456 }
00457
00466 function error($msg)
00467 {
00468 $dbg = phpCAS::backtrace();
00469 $function = '?';
00470 $file = '?';
00471 $line = '?';
00472 if ( is_array($dbg) ) {
00473 for ( $i=1; $i<sizeof($dbg); $i++) {
00474 if ( is_array($dbg[$i]) ) {
00475 if ( $dbg[$i]['class'] == __CLASS__ ) {
00476 $function = $dbg[$i]['function'];
00477 $file = $dbg[$i]['file'];
00478 $line = $dbg[$i]['line'];
00479 }
00480 }
00481 }
00482 }
00483 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";
00484 phpCAS::trace($msg);
00485 phpCAS::traceExit();
00486 exit();
00487 }
00488
00492 function trace($str)
00493 {
00494 $dbg = phpCAS::backtrace();
00495 phpCAS::log($str.' ['.basename($dbg[1]['file']).':'.$dbg[1]['line'].']');
00496 }
00497
00501 function traceBegin()
00502 {
00503 global $PHPCAS_DEBUG;
00504
00505 $dbg = phpCAS::backtrace();
00506 $str = '=> ';
00507 if ( !empty($dbg[2]['class']) ) {
00508 $str .= $dbg[2]['class'].'::';
00509 }
00510 $str .= $dbg[2]['function'].'(';
00511 if ( is_array($dbg[2]['args']) ) {
00512 foreach ($dbg[2]['args'] as $index => $arg) {
00513 if ( $index != 0 ) {
00514 $str .= ', ';
00515 }
00516 $str .= str_replace("\n","",var_export($arg,TRUE));
00517 }
00518 }
00519 $str .= ') ['.basename($dbg[2]['file']).':'.$dbg[2]['line'].']';
00520 phpCAS::log($str);
00521 $PHPCAS_DEBUG['indent'] ++;
00522 }
00523
00529 function traceEnd($res='')
00530 {
00531 global $PHPCAS_DEBUG;
00532
00533 $PHPCAS_DEBUG['indent'] --;
00534 $dbg = phpCAS::backtrace();
00535 $str = '';
00536 $str .= '<= '.str_replace("\n","",var_export($res,TRUE));
00537 phpCAS::log($str);
00538 }
00539
00543 function traceExit()
00544 {
00545 global $PHPCAS_DEBUG;
00546
00547 phpCAS::log('exit()');
00548 while ( $PHPCAS_DEBUG['indent'] > 0 ) {
00549 phpCAS::log('-');
00550 $PHPCAS_DEBUG['indent'] --;
00551 }
00552 }
00553
00555
00556
00557
00571 function setLang($lang)
00572 {
00573 global $PHPCAS_CLIENT;
00574 if ( !is_object($PHPCAS_CLIENT) ) {
00575 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00576 }
00577 if ( gettype($lang) != 'string' ) {
00578 phpCAS::error('type mismatched for parameter $lang (should be `string\')');
00579 }
00580 $PHPCAS_CLIENT->setLang($lang);
00581 }
00582
00584
00585
00586
00597 function getVersion()
00598 {
00599 return PHPCAS_VERSION;
00600 }
00601
00603
00604
00605
00616 function setHTMLHeader($header)
00617 {
00618 global $PHPCAS_CLIENT;
00619 if ( !is_object($PHPCAS_CLIENT) ) {
00620 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00621 }
00622 if ( gettype($header) != 'string' ) {
00623 phpCAS::error('type mismatched for parameter $header (should be `string\')');
00624 }
00625 $PHPCAS_CLIENT->setHTMLHeader($header);
00626 }
00627
00633 function setHTMLFooter($footer)
00634 {
00635 global $PHPCAS_CLIENT;
00636 if ( !is_object($PHPCAS_CLIENT) ) {
00637 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00638 }
00639 if ( gettype($footer) != 'string' ) {
00640 phpCAS::error('type mismatched for parameter $footer (should be `string\')');
00641 }
00642 $PHPCAS_CLIENT->setHTMLFooter($footer);
00643 }
00644
00646
00647
00648
00661 function setPGTStorageFile($format='',
00662 $path='')
00663 {
00664 global $PHPCAS_CLIENT,$PHPCAS_AUTH_CHECK_CALL;
00665
00666 phpCAS::traceBegin();
00667 if ( !is_object($PHPCAS_CLIENT) ) {
00668 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00669 }
00670 if ( !$PHPCAS_CLIENT->isProxy() ) {
00671 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00672 }
00673 if ( $PHPCAS_AUTH_CHECK_CALL['done'] ) {
00674 phpCAS::error('this method should only be called before '.$PHPCAS_AUTH_CHECK_CALL['method'].'() (called at '.$PHPCAS_AUTH_CHECK_CALL['file'].':'.$PHPCAS_AUTH_CHECK_CALL['line'].')');
00675 }
00676 if ( gettype($format) != 'string' ) {
00677 phpCAS::error('type mismatched for parameter $format (should be `string\')');
00678 }
00679 if ( gettype($path) != 'string' ) {
00680 phpCAS::error('type mismatched for parameter $format (should be `string\')');
00681 }
00682 $PHPCAS_CLIENT->setPGTStorageFile($format,$path);
00683 phpCAS::traceEnd();
00684 }
00685
00701 function setPGTStorageDB($user,
00702 $password,
00703 $database_type='',
00704 $hostname='',
00705 $port=0,
00706 $database='',
00707 $table='')
00708 {
00709 global $PHPCAS_CLIENT,$PHPCAS_AUTH_CHECK_CALL;
00710
00711 phpCAS::traceBegin();
00712 if ( !is_object($PHPCAS_CLIENT) ) {
00713 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00714 }
00715 if ( !$PHPCAS_CLIENT->isProxy() ) {
00716 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00717 }
00718 if ( $PHPCAS_AUTH_CHECK_CALL['done'] ) {
00719 phpCAS::error('this method should only be called before '.$PHPCAS_AUTH_CHECK_CALL['method'].'() (called at '.$PHPCAS_AUTH_CHECK_CALL['file'].':'.$PHPCAS_AUTH_CHECK_CALL['line'].')');
00720 }
00721 if ( gettype($user) != 'string' ) {
00722 phpCAS::error('type mismatched for parameter $user (should be `string\')');
00723 }
00724 if ( gettype($password) != 'string' ) {
00725 phpCAS::error('type mismatched for parameter $password (should be `string\')');
00726 }
00727 if ( gettype($database_type) != 'string' ) {
00728 phpCAS::error('type mismatched for parameter $database_type (should be `string\')');
00729 }
00730 if ( gettype($hostname) != 'string' ) {
00731 phpCAS::error('type mismatched for parameter $hostname (should be `string\')');
00732 }
00733 if ( gettype($port) != 'integer' ) {
00734 phpCAS::error('type mismatched for parameter $port (should be `integer\')');
00735 }
00736 if ( gettype($database) != 'string' ) {
00737 phpCAS::error('type mismatched for parameter $database (should be `string\')');
00738 }
00739 if ( gettype($table) != 'string' ) {
00740 phpCAS::error('type mismatched for parameter $table (should be `string\')');
00741 }
00742 $PHPCAS_CLIENT->setPGTStorageDB($this,$user,$password,$hostname,$port,$database,$table);
00743 phpCAS::traceEnd();
00744 }
00745
00747
00748
00749
00768 function serviceWeb($url,&$err_code,&$output)
00769 {
00770 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00771
00772 phpCAS::traceBegin();
00773 if ( !is_object($PHPCAS_CLIENT) ) {
00774 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00775 }
00776 if ( !$PHPCAS_CLIENT->isProxy() ) {
00777 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00778 }
00779 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
00780 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()');
00781 }
00782 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
00783 phpCAS::error('authentication was checked (by '.$PHPCAS_AUTH_CHECK_CALL['method'].'() at '.$PHPCAS_AUTH_CHECK_CALL['file'].':'.$PHPCAS_AUTH_CHECK_CALL['line'].') but the method returned FALSE');
00784 }
00785 if ( gettype($url) != 'string' ) {
00786 phpCAS::error('type mismatched for parameter $url (should be `string\')');
00787 }
00788
00789 $res = $PHPCAS_CLIENT->serviceWeb($url,$err_code,$output);
00790
00791 phpCAS::traceEnd($res);
00792 return $res;
00793 }
00794
00811 function serviceMail($url,$flags,&$err_code,&$err_msg,&$pt)
00812 {
00813 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00814
00815 phpCAS::traceBegin();
00816 if ( !is_object($PHPCAS_CLIENT) ) {
00817 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00818 }
00819 if ( !$PHPCAS_CLIENT->isProxy() ) {
00820 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00821 }
00822 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
00823 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()');
00824 }
00825 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
00826 phpCAS::error('authentication was checked (by '.$PHPCAS_AUTH_CHECK_CALL['method'].'() at '.$PHPCAS_AUTH_CHECK_CALL['file'].':'.$PHPCAS_AUTH_CHECK_CALL['line'].') but the method returned FALSE');
00827 }
00828 if ( gettype($url) != 'string' ) {
00829 phpCAS::error('type mismatched for parameter $url (should be `string\')');
00830 }
00831
00832 if ( gettype($flags) != 'integer' ) {
00833 phpCAS::error('type mismatched for parameter $flags (should be `integer\')');
00834 }
00835
00836 $res = $PHPCAS_CLIENT->serviceMail($url,$flags,$err_code,$err_msg,$pt);
00837
00838 phpCAS::traceEnd($res);
00839 return $res;
00840 }
00841
00843
00844
00845
00859 function setCacheTimesForAuthRecheck($n)
00860 {
00861 global $PHPCAS_CLIENT;
00862 if ( !is_object($PHPCAS_CLIENT) ) {
00863 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00864 }
00865 if ( gettype($n) != 'integer' ) {
00866 phpCAS::error('type mismatched for parameter $header (should be `string\')');
00867 }
00868 $PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
00869 }
00870
00875 function checkAuthentication()
00876 {
00877 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00878
00879 phpCAS::traceBegin();
00880 if ( !is_object($PHPCAS_CLIENT) ) {
00881 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00882 }
00883
00884 $auth = $PHPCAS_CLIENT->checkAuthentication();
00885
00886
00887 $dbg = phpCAS::backtrace();
00888 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,
00889 'file' => $dbg[0]['file'],
00890 'line' => $dbg[0]['line'],
00891 'method' => __CLASS__.'::'.__FUNCTION__,
00892 'result' => $auth );
00893 phpCAS::traceEnd($auth);
00894 return $auth;
00895 }
00896
00902 function forceAuthentication()
00903 {
00904 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00905
00906 phpCAS::traceBegin();
00907 if ( !is_object($PHPCAS_CLIENT) ) {
00908 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00909 }
00910
00911 $auth = $PHPCAS_CLIENT->forceAuthentication();
00912
00913
00914 $dbg = phpCAS::backtrace();
00915 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,
00916 'file' => $dbg[0]['file'],
00917 'line' => $dbg[0]['line'],
00918 'method' => __CLASS__.'::'.__FUNCTION__,
00919 'result' => $auth );
00920
00921 if ( !$auth ) {
00922 phpCAS::trace('user is not authenticated, redirecting to the CAS server');
00923 $PHPCAS_CLIENT->forceAuthentication();
00924 } else {
00925 phpCAS::trace('no need to authenticate (user `'.phpCAS::getUser().'\' is already authenticated)');
00926 }
00927
00928 phpCAS::traceEnd();
00929 return $auth;
00930 }
00931
00935 function renewAuthentication() {
00936 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00937
00938 phpCAS::traceBegin();
00939 if ( !is_object($PHPCAS_CLIENT) ) {
00940 phpCAS::error('this method should not be called before'.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00941 }
00942
00943 // store where the authentication has been checked and the result
00944 $dbg = phpCAS::backtrace();
00945 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE, 'file' => $dbg[0]['file'], 'line' => $dbg[0]['line'], 'method' => __CLASS__.'::'.__FUNCTION__, 'result' => $auth );
00946
00947 $PHPCAS_CLIENT->renewAuthentication();
00948 phpCAS::traceEnd();
00949 }
00950
00954 function authenticate()
00955 {
00956 phpCAS::error('this method is deprecated. You should use '.__CLASS__.'::forceAuthentication() instead');
00957 }
00958
00965 function isAuthenticated()
00966 {
00967 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00968
00969 phpCAS::traceBegin();
00970 if ( !is_object($PHPCAS_CLIENT) ) {
00971 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00972 }
00973
00974 // call the isAuthenticated method of the global $PHPCAS_CLIENT object
00975 $auth = $PHPCAS_CLIENT->isAuthenticated();
00976
00977 // store where the authentication has been checked and the result
00978 $dbg = phpCAS::backtrace();
00979 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,
00980 'file' => $dbg[0]['file'],
00981 'line' => $dbg[0]['line'],
00982 'method' => __CLASS__.'::'.__FUNCTION__,
00983 'result' => $auth );
00984 phpCAS::traceEnd($auth);
00985 return $auth;
00986 }
00987
00994 function isSessionAuthenticated ()
00995 {
00996 global $PHPCAS_CLIENT;
00997 if ( !is_object($PHPCAS_CLIENT) ) {
00998 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00999 }
01000 return($PHPCAS_CLIENT->isSessionAuthenticated());
01001 }
01002
01010 function getUser()
01011 {
01012 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01013 if ( !is_object($PHPCAS_CLIENT) ) {
01014 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01015 }
01016 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
01017 phpCAS::error('this method should only be called after '.__CLASS__.'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()');
01018 }
01019 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
01020 phpCAS::error('authentication was checked (by '.$PHPCAS_AUTH_CHECK_CALL['method'].'() at '.$PHPCAS_AUTH_CHECK_CALL['file'].':'.$PHPCAS_AUTH_CHECK_CALL['line'].') but the method returned FALSE');
01021 }
01022 return $PHPCAS_CLIENT->getUser();
01023 }
01024
01028 function handleLogoutRequests($check_client=true, $allowed_clients=false)
01029 {
01030 global $PHPCAS_CLIENT;
01031 if ( !is_object($PHPCAS_CLIENT) ) {
01032 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01033 }
01034 return($PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
01035 }
01036
01043 function getServerLoginURL()
01044 {
01045 global $PHPCAS_CLIENT;
01046 if ( !is_object($PHPCAS_CLIENT) ) {
01047 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01048 }
01049 return $PHPCAS_CLIENT->getServerLoginURL();
01050 }
01051
01057 function setServerLoginURL($url='')
01058 {
01059 global $PHPCAS_CLIENT;
01060 phpCAS::traceBegin();
01061 if ( !is_object($PHPCAS_CLIENT) ) {
01062 phpCAS::error('this method should only be called after
01063 '.__CLASS__.'::client()');
01064 }
01065 if ( gettype($url) != 'string' ) {
01066 phpCAS::error('type mismatched for parameter $url (should be
01067 `string\')');
01068 }
01069 $PHPCAS_CLIENT->setServerLoginURL($url);
01070 phpCAS::traceEnd();
01071 }
01072
01079 function getServerLogoutURL()
01080 {
01081 global $PHPCAS_CLIENT;
01082 if ( !is_object($PHPCAS_CLIENT) ) {
01083 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01084 }
01085 return $PHPCAS_CLIENT->getServerLogoutURL();
01086 }
01087
01093 function setServerLogoutURL($url='')
01094 {
01095 global $PHPCAS_CLIENT;
01096 phpCAS::traceBegin();
01097 if ( !is_object($PHPCAS_CLIENT) ) {
01098 phpCAS::error('this method should only be called after
01099 '.__CLASS__.'::client()');
01100 }
01101 if ( gettype($url) != 'string' ) {
01102 phpCAS::error('type mismatched for parameter $url (should be
01103 `string\')');
01104 }
01105 $PHPCAS_CLIENT->setServerLogoutURL($url);
01106 phpCAS::traceEnd();
01107 }
01108
01114 function logout($params = "") {
01115 global $PHPCAS_CLIENT;
01116 phpCAS::traceBegin();
01117 if (!is_object($PHPCAS_CLIENT)) {
01118 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01119 }
01120 $parsedParams = array();
01121 if ($params != "") {
01122 if (is_string($params)) {
01123 phpCAS::error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');
01124 }
01125 if (!is_array($params)) {
01126 phpCAS::error('type mismatched for parameter $params (should be `array\')');
01127 }
01128 foreach ($params as $key => $value) {
01129 if ($key != "service" && $key != "url") {
01130 phpCAS::error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');
01131 }
01132 $parsedParams[$key] = $value;
01133 }
01134 }
01135 $PHPCAS_CLIENT->logout($parsedParams);
01136
01137 phpCAS::traceEnd();
01138 }
01139
01144 function logoutWithRedirectService($service) {
01145 global $PHPCAS_CLIENT;
01146 phpCAS::traceBegin();
01147 if ( !is_object($PHPCAS_CLIENT) ) {
01148 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01149 }
01150 if (!is_string($service)) {
01151 phpCAS::error('type mismatched for parameter $service (should be `string\')');
01152 }
01153 $PHPCAS_CLIENT->logout(array("service" => $service));
01154
01155 phpCAS::traceEnd();
01156 }
01157
01162 function logoutWithUrl($url) {
01163 global $PHPCAS_CLIENT;
01164 phpCAS::traceBegin();
01165 if ( !is_object($PHPCAS_CLIENT) ) {
01166 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01167 }
01168 if (!is_string($url)) {
01169 phpCAS::error('type mismatched for parameter $url (should be `string\')');
01170 }
01171 $PHPCAS_CLIENT->logout(array("url" => $url));
01172
01173 phpCAS::traceEnd();
01174 }
01175
01181 function logoutWithRedirectServiceAndUrl($service, $url) {
01182 global $PHPCAS_CLIENT;
01183 phpCAS::traceBegin();
01184 if ( !is_object($PHPCAS_CLIENT) ) {
01185 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01186 }
01187 if (!is_string($service)) {
01188 phpCAS::error('type mismatched for parameter $service (should be `string\')');
01189 }
01190 if (!is_string($url)) {
01191 phpCAS::error('type mismatched for parameter $url (should be `string\')');
01192 }
01193 $PHPCAS_CLIENT->logout(array("service" => $service, "url" => $url));
01194
01195 phpCAS::traceEnd();
01196 }
01197
01204 function setFixedCallbackURL($url='')
01205 {
01206 global $PHPCAS_CLIENT;
01207 phpCAS::traceBegin();
01208 if ( !is_object($PHPCAS_CLIENT) ) {
01209 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01210 }
01211 if ( !$PHPCAS_CLIENT->isProxy() ) {
01212 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01213 }
01214 if ( gettype($url) != 'string' ) {
01215 phpCAS::error('type mismatched for parameter $url (should be `string\')');
01216 }
01217 $PHPCAS_CLIENT->setCallbackURL($url);
01218 phpCAS::traceEnd();
01219 }
01220
01227 function setFixedServiceURL($url)
01228 {
01229 global $PHPCAS_CLIENT;
01230 phpCAS::traceBegin();
01231 if ( !is_object($PHPCAS_CLIENT) ) {
01232 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01233 }
01234 if ( gettype($url) != 'string' ) {
01235 phpCAS::error('type mismatched for parameter $url (should be `string\')');
01236 }
01237 $PHPCAS_CLIENT->setURL($url);
01238 phpCAS::traceEnd();
01239 }
01240
01244 function getServiceURL()
01245 {
01246 global $PHPCAS_CLIENT;
01247 if ( !is_object($PHPCAS_CLIENT) ) {
01248 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01249 }
01250 return($PHPCAS_CLIENT->getURL());
01251 }
01252
01256 function retrievePT($target_service,&$err_code,&$err_msg)
01257 {
01258 global $PHPCAS_CLIENT;
01259 if ( !is_object($PHPCAS_CLIENT) ) {
01260 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01261 }
01262 if ( gettype($target_service) != 'string' ) {
01263 phpCAS::error('type mismatched for parameter $target_service(should be `string\')');
01264 }
01265 return($PHPCAS_CLIENT->retrievePT($target_service,$err_code,$err_msg));
01266 }
01267
01273 function setCasServerCert($cert)
01274 {
01275 global $PHPCAS_CLIENT;
01276 phpCAS::traceBegin();
01277 if ( !is_object($PHPCAS_CLIENT) ) {
01278 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01279 }
01280 if ( gettype($cert) != 'string' ) {
01281 phpCAS::error('type mismatched for parameter $cert (should be `string\')');
01282 }
01283 $PHPCAS_CLIENT->setCasServerCert($cert);
01284 phpCAS::traceEnd();
01285 }
01286
01292 function setCasServerCACert($cert)
01293 {
01294 global $PHPCAS_CLIENT;
01295 phpCAS::traceBegin();
01296 if ( !is_object($PHPCAS_CLIENT) ) {
01297 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01298 }
01299 if ( gettype($cert) != 'string' ) {
01300 phpCAS::error('type mismatched for parameter $cert (should be `string\')');
01301 }
01302 $PHPCAS_CLIENT->setCasServerCACert($cert);
01303 phpCAS::traceEnd();
01304 }
01305
01309 function setNoCasServerValidation()
01310 {
01311 global $PHPCAS_CLIENT;
01312 phpCAS::traceBegin();
01313 if ( !is_object($PHPCAS_CLIENT) ) {
01314 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01315 }
01316 $PHPCAS_CLIENT->setNoCasServerValidation();
01317 phpCAS::traceEnd();
01318 }
01319
01328 function setExtraCurlOption($key, $value)
01329 {
01330 global $PHPCAS_CLIENT;
01331 phpCAS::traceBegin();
01332 if ( !is_object($PHPCAS_CLIENT) ) {
01333 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01334 }
01335 $PHPCAS_CLIENT->setExtraCurlOption($key, $value);
01336 phpCAS::traceEnd();
01337 }
01338
01339 }
01340
01341
01342
01343
01344
01345
01346
01347
01355
01356
01357
01432
01433
01434
01471 ?>