Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages | Examples

CAS/CAS.php

Go to the documentation of this file.
00001 <?php 00002 00003 // commented in 0.4.22-RC2 for Sylvain Derosiaux 00004 // error_reporting(E_ALL ^ E_NOTICE); 00005 00006 // 00007 // hack by Vangelis Haniotakis to handle the absence of $_SERVER['REQUEST_URI'] in IIS 00008 // 00009 if (!$_SERVER['REQUEST_URI']) { 00010 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']; 00011 } 00012 00013 // 00014 // another one by Vangelis Haniotakis also to make phpCAS work with PHP5 00015 // 00016 if (version_compare(PHP_VERSION,'5','>=')) { 00017 require_once(dirname(__FILE__).'/domxml-php4-php5.php'); 00018 } 00019 00027 // ######################################################################## 00028 // CONSTANTS 00029 // ######################################################################## 00030 00031 // ------------------------------------------------------------------------ 00032 // CAS VERSIONS 00033 // ------------------------------------------------------------------------ 00034 00038 define('PHPCAS_VERSION','0.4.23-1'); 00039 00040 // ------------------------------------------------------------------------ 00041 // CAS VERSIONS 00042 // ------------------------------------------------------------------------ 00051 define("CAS_VERSION_1_0",'1.0'); 00055 define("CAS_VERSION_2_0",'2.0'); 00056 00062 // ------------------------------------------------------------------------ 00063 // FILE PGT STORAGE 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 // DATABASE PGT STORAGE 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 // SERVICE ACCESS ERRORS 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 // LANGUAGES 00141 // ------------------------------------------------------------------------ 00147 define("PHPCAS_LANG_ENGLISH", 'english'); 00148 define("PHPCAS_LANG_FRENCH", 'french'); 00149 define("PHPCAS_LANG_GREEK", 'greek'); 00150 00161 define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH); 00162 00164 // ------------------------------------------------------------------------ 00165 // MISC 00166 // ------------------------------------------------------------------------ 00177 $PHPCAS_CLIENT = null; 00178 00185 $PHPCAS_INIT_CALL = array('done' => FALSE, 00186 'file' => '?', 00187 'line' => -1, 00188 'method' => '?'); 00189 00196 $PHPCAS_AUTH_CHECK_CALL = array('done' => FALSE, 00197 'file' => '?', 00198 'line' => -1, 00199 'method' => '?', 00200 'result' => FALSE); 00201 00207 $PHPCAS_DEBUG = array('filename' => FALSE, 00208 'indent' => 0, 00209 'unique_id' => ''); 00210 00213 // ######################################################################## 00214 // CLIENT CLASS 00215 // ######################################################################## 00216 00217 // include client class 00218 include_once(dirname(__FILE__).'/client.php'); 00219 00220 // ######################################################################## 00221 // INTERFACE CLASS 00222 // ######################################################################## 00223 00238 class phpCAS 00239 { 00240 00241 // ######################################################################## 00242 // INITIALIZATION 00243 // ######################################################################## 00244 00264 function client($server_version, 00265 $server_hostname, 00266 $server_port, 00267 $server_uri, 00268 $start_session = true) 00269 { 00270 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL; 00271 00272 phpCAS::traceBegin(); 00273 if ( is_object($PHPCAS_CLIENT) ) { 00274 phpCAS::error($PHPCAS_INIT_CALL['method'].'() has already been called (at '.$PHPCAS_INIT_CALL['file'].':'.$PHPCAS_INIT_CALL['line'].')'); 00275 } 00276 if ( gettype($server_version) != 'string' ) { 00277 phpCAS::error('type mismatched for parameter $server_version (should be `string\')'); 00278 } 00279 if ( gettype($server_hostname) != 'string' ) { 00280 phpCAS::error('type mismatched for parameter $server_hostname (should be `string\')'); 00281 } 00282 if ( gettype($server_port) != 'integer' ) { 00283 phpCAS::error('type mismatched for parameter $server_port (should be `integer\')'); 00284 } 00285 if ( gettype($server_uri) != 'string' ) { 00286 phpCAS::error('type mismatched for parameter $server_uri (should be `string\')'); 00287 } 00288 00289 // store where the initialzer is called from 00290 $dbg = phpCAS::backtrace(); 00291 $PHPCAS_INIT_CALL = array('done' => TRUE, 00292 'file' => $dbg[0]['file'], 00293 'line' => $dbg[0]['line'], 00294 'method' => __CLASS__.'::'.__FUNCTION__); 00295 00296 // initialize the global object $PHPCAS_CLIENT 00297 $PHPCAS_CLIENT = new CASClient($server_version,FALSE/*proxy*/,$server_hostname,$server_port,$server_uri,$start_session); 00298 phpCAS::traceEnd(); 00299 } 00300 00315 function proxy($server_version, 00316 $server_hostname, 00317 $server_port, 00318 $server_uri, 00319 $start_session = true) 00320 { 00321 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL; 00322 00323 phpCAS::traceBegin(); 00324 if ( is_object($PHPCAS_CLIENT) ) { 00325 phpCAS::error($PHPCAS_INIT_CALL['method'].'() has already been called (at '.$PHPCAS_INIT_CALL['file'].':'.$PHPCAS_INIT_CALL['line'].')'); 00326 } 00327 if ( gettype($server_version) != 'string' ) { 00328 phpCAS::error('type mismatched for parameter $server_version (should be `string\')'); 00329 } 00330 if ( gettype($server_hostname) != 'string' ) { 00331 phpCAS::error('type mismatched for parameter $server_hostname (should be `string\')'); 00332 } 00333 if ( gettype($server_port) != 'integer' ) { 00334 phpCAS::error('type mismatched for parameter $server_port (should be `integer\')'); 00335 } 00336 if ( gettype($server_uri) != 'string' ) { 00337 phpCAS::error('type mismatched for parameter $server_uri (should be `string\')'); 00338 } 00339 00340 // store where the initialzer is called from 00341 $dbg = phpCAS::backtrace(); 00342 $PHPCAS_INIT_CALL = array('done' => TRUE, 00343 'file' => $dbg[0]['file'], 00344 'line' => $dbg[0]['line'], 00345 'method' => __CLASS__.'::'.__FUNCTION__); 00346 00347 // initialize the global object $PHPCAS_CLIENT 00348 $PHPCAS_CLIENT = new CASClient($server_version,TRUE/*proxy*/,$server_hostname,$server_port,$server_uri,$start_session); 00349 phpCAS::traceEnd(); 00350 } 00351 00353 // ######################################################################## 00354 // DEBUGGING 00355 // ######################################################################## 00356 00367 function setDebug($filename='') 00368 { 00369 global $PHPCAS_DEBUG; 00370 00371 if ( $filename != FALSE && gettype($filename) != 'string' ) { 00372 phpCAS::error('type mismatched for parameter $dbg (should be FALSE or the name of the log file)'); 00373 } 00374 00375 if ( empty($filename) ) { 00376 if ( preg_match('/^Win.*/',getenv('OS')) ) { 00377 if ( isset($_ENV['TMP']) ) { 00378 $debugDir = $_ENV['TMP'].'/'; 00379 } else if ( isset($_ENV['TEMP']) ) { 00380 $debugDir = $_ENV['TEMP'].'/'; 00381 } else { 00382 $debugDir = ''; 00383 } 00384 } else { 00385 $debugDir = '/tmp/'; 00386 } 00387 $filename = $debugDir . 'phpCAS.log'; 00388 } 00389 00390 if ( empty($PHPCAS_DEBUG['unique_id']) ) { 00391 $PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))),0,4); 00392 } 00393 00394 $PHPCAS_DEBUG['filename'] = $filename; 00395 00396 phpCAS::trace('START ******************'); 00397 } 00398 00409 function backtrace() 00410 { 00411 if ( function_exists('debug_backtrace') ) { 00412 return debug_backtrace(); 00413 } else { 00414 // poor man's hack ... but it does work ... 00415 return array(); 00416 } 00417 } 00418 00426 function log($str) 00427 { 00428 $indent_str = "."; 00429 global $PHPCAS_DEBUG; 00430 00431 if ( $PHPCAS_DEBUG['filename'] ) { 00432 for ($i=0;$i<$PHPCAS_DEBUG['indent'];$i++) { 00433 $indent_str .= '| '; 00434 } 00435 error_log($PHPCAS_DEBUG['unique_id'].' '.$indent_str.$str."\n",3,$PHPCAS_DEBUG['filename']); 00436 } 00437 00438 } 00439 00448 function error($msg) 00449 { 00450 $dbg = phpCAS::backtrace(); 00451 $function = '?'; 00452 $file = '?'; 00453 $line = '?'; 00454 if ( is_array($dbg) ) { 00455 for ( $i=1; $i<sizeof($dbg); $i++) { 00456 if ( is_array($dbg[$i]) ) { 00457 if ( $dbg[$i]['class'] == __CLASS__ ) { 00458 $function = $dbg[$i]['function']; 00459 $file = $dbg[$i]['file']; 00460 $line = $dbg[$i]['line']; 00461 } 00462 } 00463 } 00464 } 00465 echo "<br />\n<b>phpCAS error</b>: <font color=\"FF0000\"><b>".__CLASS__."::".$function.'(): '.htmlentities($msg,ENT_QUOTES,'ISO-8859-1')."</b></font> in <b>".$file."</b> on line <b>".$line."</b><br />\n"; 00466 phpCAS::trace($msg); 00467 phpCAS::traceExit(); 00468 exit(); 00469 } 00470 00474 function trace($str) 00475 { 00476 $dbg = phpCAS::backtrace(); 00477 phpCAS::log($str.' ['.basename($dbg[1]['file']).':'.$dbg[1]['line'].']'); 00478 } 00479 00483 function traceBegin() 00484 { 00485 global $PHPCAS_DEBUG; 00486 00487 $dbg = phpCAS::backtrace(); 00488 $str = '=> '; 00489 if ( !empty($dbg[2]['class']) ) { 00490 $str .= $dbg[2]['class'].'::'; 00491 } 00492 $str .= $dbg[2]['function'].'('; 00493 if ( is_array($dbg[2]['args']) ) { 00494 foreach ($dbg[2]['args'] as $index => $arg) { 00495 if ( $index != 0 ) { 00496 $str .= ', '; 00497 } 00498 $str .= str_replace("\n","",var_export($arg,TRUE)); 00499 } 00500 } 00501 $str .= ') ['.basename($dbg[2]['file']).':'.$dbg[2]['line'].']'; 00502 phpCAS::log($str); 00503 $PHPCAS_DEBUG['indent'] ++; 00504 } 00505 00511 function traceEnd($res='') 00512 { 00513 global $PHPCAS_DEBUG; 00514 00515 $PHPCAS_DEBUG['indent'] --; 00516 $dbg = phpCAS::backtrace(); 00517 $str = ''; 00518 $str .= '<= '.str_replace("\n","",var_export($res,TRUE)); 00519 phpCAS::log($str); 00520 } 00521 00525 function traceExit() 00526 { 00527 global $PHPCAS_DEBUG; 00528 00529 phpCAS::log('exit()'); 00530 while ( $PHPCAS_DEBUG['indent'] > 0 ) { 00531 phpCAS::log('-'); 00532 $PHPCAS_DEBUG['indent'] --; 00533 } 00534 } 00535 00537 // ######################################################################## 00538 // INTERNATIONALIZATION 00539 // ######################################################################## 00553 function setLang($lang) 00554 { 00555 global $PHPCAS_CLIENT; 00556 if ( !is_object($PHPCAS_CLIENT) ) { 00557 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()'); 00558 } 00559 if ( gettype($lang) != 'string' ) { 00560 phpCAS::error('type mismatched for parameter $lang (should be `string\')'); 00561 } 00562 $PHPCAS_CLIENT->setLang($lang); 00563 } 00564 00566 // ######################################################################## 00567 // VERSION 00568 // ######################################################################## 00579 function getVersion() 00580 { 00581 return PHPCAS_VERSION; 00582 } 00583 00585 // ######################################################################## 00586 // HTML OUTPUT 00587 // ######################################################################## 00598 function setHTMLHeader($header) 00599 { 00600 global $PHPCAS_CLIENT; 00601 if ( !is_object($PHPCAS_CLIENT) ) { 00602 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()'); 00603 } 00604 if ( gettype($header) != 'string' ) { 00605 phpCAS::error('type mismatched for parameter $header (should be `string\')'); 00606 } 00607 $PHPCAS_CLIENT->setHTMLHeader($header); 00608 } 00609 00615 function setHTMLFooter($footer) 00616 { 00617 global $PHPCAS_CLIENT; 00618 if ( !is_object($PHPCAS_CLIENT) ) { 00619 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()'); 00620 } 00621 if ( gettype($footer) != 'string' ) { 00622 phpCAS::error('type mismatched for parameter $footer (should be `string\')'); 00623 } 00624 $PHPCAS_CLIENT->setHTMLHeader($header); 00625 } 00626 00628 // ######################################################################## 00629 // PGT STORAGE 00630 // ######################################################################## 00643 function setPGTStorageFile($format='', 00644 $path='') 00645 { 00646 global $PHPCAS_CLIENT,$PHPCAS_AUTH_CHECK_CALL; 00647 00648 phpCAS::traceBegin(); 00649 if ( !is_object($PHPCAS_CLIENT) ) { 00650 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 00651 } 00652 if ( !$PHPCAS_CLIENT->isProxy() ) { 00653 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 00654 } 00655 if ( $PHPCAS_AUTH_CHECK_CALL['done'] ) { 00656 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'].')'); 00657 } 00658 if ( gettype($format) != 'string' ) { 00659 phpCAS::error('type mismatched for parameter $format (should be `string\')'); 00660 } 00661 if ( gettype($path) != 'string' ) { 00662 phpCAS::error('type mismatched for parameter $format (should be `string\')'); 00663 } 00664 $PHPCAS_CLIENT->setPGTStorageFile($format,$path); 00665 phpCAS::traceEnd(); 00666 } 00667 00683 function setPGTStorageDB($user, 00684 $password, 00685 $database_type='', 00686 $hostname='', 00687 $port=0, 00688 $database='', 00689 $table='') 00690 { 00691 global $PHPCAS_CLIENT,$PHPCAS_AUTH_CHECK_CALL; 00692 00693 phpCAS::traceBegin(); 00694 if ( !is_object($PHPCAS_CLIENT) ) { 00695 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 00696 } 00697 if ( !$PHPCAS_CLIENT->isProxy() ) { 00698 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 00699 } 00700 if ( $PHPCAS_AUTH_CHECK_CALL['done'] ) { 00701 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'].')'); 00702 } 00703 if ( gettype($user) != 'string' ) { 00704 phpCAS::error('type mismatched for parameter $user (should be `string\')'); 00705 } 00706 if ( gettype($password) != 'string' ) { 00707 phpCAS::error('type mismatched for parameter $password (should be `string\')'); 00708 } 00709 if ( gettype($database_type) != 'string' ) { 00710 phpCAS::error('type mismatched for parameter $database_type (should be `string\')'); 00711 } 00712 if ( gettype($hostname) != 'string' ) { 00713 phpCAS::error('type mismatched for parameter $hostname (should be `string\')'); 00714 } 00715 if ( gettype($port) != 'integer' ) { 00716 phpCAS::error('type mismatched for parameter $port (should be `integer\')'); 00717 } 00718 if ( gettype($database) != 'string' ) { 00719 phpCAS::error('type mismatched for parameter $database (should be `string\')'); 00720 } 00721 if ( gettype($table) != 'string' ) { 00722 phpCAS::error('type mismatched for parameter $table (should be `string\')'); 00723 } 00724 $PHPCAS_CLIENT->setPGTStorageDB($this,$user,$password,$hostname,$port,$database,$table); 00725 phpCAS::traceEnd(); 00726 } 00727 00729 // ######################################################################## 00730 // ACCESS TO EXTERNAL SERVICES 00731 // ######################################################################## 00750 function serviceWeb($url,&$err_code,&$output) 00751 { 00752 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; 00753 00754 phpCAS::traceBegin(); 00755 if ( !is_object($PHPCAS_CLIENT) ) { 00756 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 00757 } 00758 if ( !$PHPCAS_CLIENT->isProxy() ) { 00759 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 00760 } 00761 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) { 00762 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()'); 00763 } 00764 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) { 00765 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'); 00766 } 00767 if ( gettype($url) != 'string' ) { 00768 phpCAS::error('type mismatched for parameter $url (should be `string\')'); 00769 } 00770 00771 $res = $PHPCAS_CLIENT->serviceWeb($url,$err_code,$output); 00772 00773 phpCAS::traceEnd($res); 00774 return $res; 00775 } 00776 00793 function serviceMail($url,$flags,&$err_code,&$err_msg,&$pt) 00794 { 00795 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; 00796 00797 phpCAS::traceBegin(); 00798 if ( !is_object($PHPCAS_CLIENT) ) { 00799 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 00800 } 00801 if ( !$PHPCAS_CLIENT->isProxy() ) { 00802 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 00803 } 00804 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) { 00805 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()'); 00806 } 00807 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) { 00808 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'); 00809 } 00810 if ( gettype($url) != 'string' ) { 00811 phpCAS::error('type mismatched for parameter $url (should be `string\')'); 00812 } 00813 00814 if ( gettype($flags) != 'integer' ) { 00815 phpCAS::error('type mismatched for parameter $flags (should be `integer\')'); 00816 } 00817 00818 $res = $PHPCAS_CLIENT->serviceMail($url,$flags,$err_code,$err_msg,$pt); 00819 00820 phpCAS::traceEnd($res); 00821 return $res; 00822 } 00823 00825 // ######################################################################## 00826 // AUTHENTICATION 00827 // ######################################################################## 00837 function checkAuthentication() 00838 { 00839 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; 00840 00841 phpCAS::traceBegin(); 00842 if ( !is_object($PHPCAS_CLIENT) ) { 00843 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()'); 00844 } 00845 00846 $auth = $PHPCAS_CLIENT->checkAuthentication(); 00847 00848 // store where the authentication has been checked and the result 00849 $dbg = phpCAS::backtrace(); 00850 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE, 00851 'file' => $dbg[0]['file'], 00852 'line' => $dbg[0]['line'], 00853 'method' => __CLASS__.'::'.__FUNCTION__, 00854 'result' => $auth ); 00855 phpCAS::traceEnd($auth); 00856 return $auth; 00857 } 00858 00864 function forceAuthentication() 00865 { 00866 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; 00867 00868 phpCAS::traceBegin(); 00869 if ( !is_object($PHPCAS_CLIENT) ) { 00870 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()'); 00871 } 00872 00873 $auth = $PHPCAS_CLIENT->forceAuthentication(); 00874 00875 // store where the authentication has been checked and the result 00876 $dbg = phpCAS::backtrace(); 00877 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE, 00878 'file' => $dbg[0]['file'], 00879 'line' => $dbg[0]['line'], 00880 'method' => __CLASS__.'::'.__FUNCTION__, 00881 'result' => $auth ); 00882 00883 if ( !$auth ) { 00884 phpCAS::trace('user is not authenticated, redirecting to the CAS server'); 00885 $PHPCAS_CLIENT->forceAuthentication(); 00886 } else { 00887 phpCAS::trace('no need to authenticate (user `'.phpCAS::getUser().'\' is already authenticated)'); 00888 } 00889 00890 phpCAS::traceEnd(); 00891 return $auth; 00892 } 00893 00897 function authenticate() 00898 { 00899 phpCAS::error('this method is deprecated. You should use '.__CLASS__.'::forceAuthentication() instead'); 00900 } 00901 00905 function isAuthenticated() 00906 { 00907 phpCAS::error('this method is deprecated. You should use '.__CLASS__.'::forceAuthentication() instead'); 00908 } 00909 00916 function isSessionAuthenticated () 00917 { 00918 global $PHPCAS_CLIENT; 00919 if ( !is_object($PHPCAS_CLIENT) ) { 00920 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()'); 00921 } 00922 return($PHPCAS_CLIENT->isSessionAuthenticated()); 00923 } 00924 00932 function getUser() 00933 { 00934 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; 00935 if ( !is_object($PHPCAS_CLIENT) ) { 00936 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()'); 00937 } 00938 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) { 00939 phpCAS::error('this method should only be called after '.__CLASS__.'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()'); 00940 } 00941 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) { 00942 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'); 00943 } 00944 return $PHPCAS_CLIENT->getUser(); 00945 } 00946 00953 function getServerLoginURL() 00954 { 00955 global $PHPCAS_CLIENT; 00956 if ( !is_object($PHPCAS_CLIENT) ) { 00957 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()'); 00958 } 00959 return $PHPCAS_CLIENT->getServerLoginURL(); 00960 } 00961 00967 function setServerLoginURL($url='') 00968 { 00969 global $PHPCAS_CLIENT; 00970 phpCAS::traceBegin(); 00971 if ( !is_object($PHPCAS_CLIENT) ) { 00972 phpCAS::error('this method should only be called after 00973 '.__CLASS__.'::client()'); 00974 } 00975 if ( gettype($url) != 'string' ) { 00976 phpCAS::error('type mismatched for parameter $url (should be 00977 `string\')'); 00978 } 00979 $PHPCAS_CLIENT->setServerLoginURL($url); 00980 phpCAS::traceEnd(); 00981 } 00982 00989 function getServerLogoutURL() 00990 { 00991 global $PHPCAS_CLIENT; 00992 if ( !is_object($PHPCAS_CLIENT) ) { 00993 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()'); 00994 } 00995 return $PHPCAS_CLIENT->getServerLogoutURL(); 00996 } 00997 01003 function setServerLogoutURL($url='') 01004 { 01005 global $PHPCAS_CLIENT; 01006 phpCAS::traceBegin(); 01007 if ( !is_object($PHPCAS_CLIENT) ) { 01008 phpCAS::error('this method should only be called after 01009 '.__CLASS__.'::client()'); 01010 } 01011 if ( gettype($url) != 'string' ) { 01012 phpCAS::error('type mismatched for parameter $url (should be 01013 `string\')'); 01014 } 01015 $PHPCAS_CLIENT->setServerLogoutURL($url); 01016 phpCAS::traceEnd(); 01017 } 01018 01023 function logout($url = "") 01024 { 01025 global $PHPCAS_CLIENT; 01026 01027 phpCAS::traceBegin(); 01028 if ( !is_object($PHPCAS_CLIENT) ) { 01029 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()'); 01030 } 01031 $PHPCAS_CLIENT->logout($url); 01032 // never reached 01033 phpCAS::traceEnd(); 01034 } 01035 01042 function setFixedCallbackURL($url='') 01043 { 01044 global $PHPCAS_CLIENT; 01045 phpCAS::traceBegin(); 01046 if ( !is_object($PHPCAS_CLIENT) ) { 01047 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 01048 } 01049 if ( !$PHPCAS_CLIENT->isProxy() ) { 01050 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 01051 } 01052 if ( gettype($url) != 'string' ) { 01053 phpCAS::error('type mismatched for parameter $url (should be `string\')'); 01054 } 01055 $PHPCAS_CLIENT->setCallbackURL($url); 01056 phpCAS::traceEnd(); 01057 } 01058 01065 function setFixedServiceURL($url) 01066 { 01067 global $PHPCAS_CLIENT; 01068 phpCAS::traceBegin(); 01069 if ( !is_object($PHPCAS_CLIENT) ) { 01070 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 01071 } 01072 if ( gettype($url) != 'string' ) { 01073 phpCAS::error('type mismatched for parameter $url (should be `string\')'); 01074 } 01075 $PHPCAS_CLIENT->setURL($url); 01076 phpCAS::traceEnd(); 01077 } 01078 01082 function getServiceURL() 01083 { 01084 global $PHPCAS_CLIENT; 01085 if ( !is_object($PHPCAS_CLIENT) ) { 01086 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 01087 } 01088 return($PHPCAS_CLIENT->getURL()); 01089 } 01090 01094 function retrievePT($target_service,&$err_code,&$err_msg) 01095 { 01096 global $PHPCAS_CLIENT; 01097 if ( !is_object($PHPCAS_CLIENT) ) { 01098 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()'); 01099 } 01100 if ( gettype($target_service) != 'string' ) { 01101 phpCAS::error('type mismatched for parameter $target_service(should be `string\')'); 01102 } 01103 return($PHPCAS_CLIENT->retrievePT($target_service,$err_code,$err_msg)); 01104 } 01107 } 01108 01109 // ######################################################################## 01110 // DOCUMENTATION 01111 // ######################################################################## 01112 01113 // ######################################################################## 01114 // MAIN PAGE 01115 01125 // ######################################################################## 01126 // MODULES DEFINITION 01127 01202 // ######################################################################## 01203 // EXAMPLES 01204 01241 ?>

Generated on Thu Aug 17 02:03:21 2006 for phpCAS by doxygen 1.3.7