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.5.1-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 define("PHPCAS_LANG_GERMAN",     'german');
00151 define("PHPCAS_LANG_JAPANESE",   'japanese');
00152 
00163 define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);
00164 
00166 // ------------------------------------------------------------------------
00167 //  MISC
00168 // ------------------------------------------------------------------------
00179 $PHPCAS_CLIENT  = null;
00180 
00187 $PHPCAS_INIT_CALL = array('done' => FALSE,
00188                           'file' => '?',
00189                           'line' => -1,
00190                           'method' => '?');
00191 
00198 $PHPCAS_AUTH_CHECK_CALL = array('done' => FALSE,
00199                                 'file' => '?',
00200                                 'line' => -1,
00201                                 'method' => '?',
00202                                 'result' => FALSE);
00203 
00209 $PHPCAS_DEBUG  = array('filename' => FALSE,
00210                        'indent' => 0,
00211                        'unique_id' => '');
00212 
00215 // ########################################################################
00216 //  CLIENT CLASS
00217 // ########################################################################
00218 
00219 // include client class
00220 include_once(dirname(__FILE__).'/client.php');
00221 
00222 // ########################################################################
00223 //  INTERFACE CLASS
00224 // ########################################################################
00225 
00240 class phpCAS
00241 {
00242 
00243   // ########################################################################
00244   //  INITIALIZATION
00245   // ########################################################################
00246 
00266   function client($server_version,
00267                   $server_hostname,
00268                   $server_port,
00269                   $server_uri,
00270                   $start_session = true)
00271     {
00272       global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
00273 
00274       phpCAS::traceBegin();
00275       if ( is_object($PHPCAS_CLIENT) ) {
00276         phpCAS::error($PHPCAS_INIT_CALL['method'].'() has already been called (at '.$PHPCAS_INIT_CALL['file'].':'.$PHPCAS_INIT_CALL['line'].')');
00277       }
00278       if ( gettype($server_version) != 'string' ) {
00279         phpCAS::error('type mismatched for parameter $server_version (should be `string\')');
00280       }
00281       if ( gettype($server_hostname) != 'string' ) {
00282         phpCAS::error('type mismatched for parameter $server_hostname (should be `string\')');
00283       }
00284       if ( gettype($server_port) != 'integer' ) {
00285         phpCAS::error('type mismatched for parameter $server_port (should be `integer\')');
00286       }
00287       if ( gettype($server_uri) != 'string' ) {
00288         phpCAS::error('type mismatched for parameter $server_uri (should be `string\')');
00289       }
00290 
00291       // store where the initialzer is called from
00292       $dbg = phpCAS::backtrace();
00293       $PHPCAS_INIT_CALL = array('done' => TRUE,
00294                                 'file' => $dbg[0]['file'],
00295                                 'line' => $dbg[0]['line'],
00296                                 'method' => __CLASS__.'::'.__FUNCTION__);
00297 
00298       // initialize the global object $PHPCAS_CLIENT
00299       $PHPCAS_CLIENT = new CASClient($server_version,FALSE/*proxy*/,$server_hostname,$server_port,$server_uri,$start_session);
00300       phpCAS::traceEnd();
00301     }
00302 
00317   function proxy($server_version,
00318                  $server_hostname,
00319                  $server_port,
00320                  $server_uri,
00321                  $start_session = true)
00322     {
00323       global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
00324 
00325       phpCAS::traceBegin();
00326       if ( is_object($PHPCAS_CLIENT) ) {
00327         phpCAS::error($PHPCAS_INIT_CALL['method'].'() has already been called (at '.$PHPCAS_INIT_CALL['file'].':'.$PHPCAS_INIT_CALL['line'].')');
00328       }
00329       if ( gettype($server_version) != 'string' ) {
00330         phpCAS::error('type mismatched for parameter $server_version (should be `string\')');
00331       }
00332       if ( gettype($server_hostname) != 'string' ) {
00333         phpCAS::error('type mismatched for parameter $server_hostname (should be `string\')');
00334       }
00335       if ( gettype($server_port) != 'integer' ) {
00336         phpCAS::error('type mismatched for parameter $server_port (should be `integer\')');
00337       }
00338       if ( gettype($server_uri) != 'string' ) {
00339         phpCAS::error('type mismatched for parameter $server_uri (should be `string\')');
00340       }
00341 
00342       // store where the initialzer is called from
00343       $dbg = phpCAS::backtrace();
00344       $PHPCAS_INIT_CALL = array('done' => TRUE,
00345                                 'file' => $dbg[0]['file'],
00346                                 'line' => $dbg[0]['line'],
00347                                 'method' => __CLASS__.'::'.__FUNCTION__);
00348 
00349       // initialize the global object $PHPCAS_CLIENT
00350       $PHPCAS_CLIENT = new CASClient($server_version,TRUE/*proxy*/,$server_hostname,$server_port,$server_uri,$start_session);
00351       phpCAS::traceEnd();
00352     }
00353 
00355   // ########################################################################
00356   //  DEBUGGING
00357   // ########################################################################
00358 
00369   function setDebug($filename='')
00370     {
00371       global $PHPCAS_DEBUG;
00372 
00373       if ( $filename != FALSE && gettype($filename) != 'string' ) {
00374         phpCAS::error('type mismatched for parameter $dbg (should be FALSE or the name of the log file)');
00375       }
00376 
00377       if ( empty($filename) ) {
00378         if ( preg_match('/^Win.*/',getenv('OS')) ) {
00379           if ( isset($_ENV['TMP']) ) {
00380             $debugDir = $_ENV['TMP'].'/';
00381           } else if ( isset($_ENV['TEMP']) ) {
00382             $debugDir = $_ENV['TEMP'].'/';
00383           } else {
00384             $debugDir = '';
00385           }
00386         } else {
00387           $debugDir = '/tmp/';
00388         }
00389         $filename = $debugDir . 'phpCAS.log';
00390       }
00391 
00392       if ( empty($PHPCAS_DEBUG['unique_id']) ) {
00393         $PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))),0,4);
00394       }
00395 
00396       $PHPCAS_DEBUG['filename'] = $filename;
00397 
00398       phpCAS::trace('START ******************');
00399     }
00400   
00411   function backtrace()
00412     {
00413       if ( function_exists('debug_backtrace') ) {
00414         return debug_backtrace();
00415       } else {
00416         // poor man's hack ... but it does work ...
00417         return array();
00418       }
00419     }
00420 
00428   function log($str)
00429     {
00430       $indent_str = ".";
00431       global $PHPCAS_DEBUG;
00432 
00433       if ( $PHPCAS_DEBUG['filename'] ) {
00434         for ($i=0;$i<$PHPCAS_DEBUG['indent'];$i++) {
00435           $indent_str .= '|    ';
00436         }
00437         error_log($PHPCAS_DEBUG['unique_id'].' '.$indent_str.$str."\n",3,$PHPCAS_DEBUG['filename']);
00438       }
00439 
00440     }
00441   
00450   function error($msg)
00451     {
00452       $dbg = phpCAS::backtrace();
00453       $function = '?';
00454       $file = '?';
00455       $line = '?';
00456       if ( is_array($dbg) ) {
00457         for ( $i=1; $i<sizeof($dbg); $i++) {
00458           if ( is_array($dbg[$i]) ) {
00459             if ( $dbg[$i]['class'] == __CLASS__ ) {
00460               $function = $dbg[$i]['function'];
00461               $file = $dbg[$i]['file'];
00462               $line = $dbg[$i]['line'];
00463             }
00464           }
00465         }
00466       }
00467       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";
00468       phpCAS::trace($msg);
00469       phpCAS::traceExit();
00470       exit();
00471     }
00472 
00476   function trace($str)
00477     {
00478       $dbg = phpCAS::backtrace();
00479       phpCAS::log($str.' ['.basename($dbg[1]['file']).':'.$dbg[1]['line'].']');
00480     }
00481 
00485   function traceBegin()
00486     {
00487       global $PHPCAS_DEBUG;
00488 
00489       $dbg = phpCAS::backtrace();
00490       $str = '=> ';
00491       if ( !empty($dbg[2]['class']) ) {
00492         $str .= $dbg[2]['class'].'::';
00493       }
00494       $str .= $dbg[2]['function'].'(';      
00495       if ( is_array($dbg[2]['args']) ) {
00496         foreach ($dbg[2]['args'] as $index => $arg) {
00497           if ( $index != 0 ) {
00498             $str .= ', ';
00499           }
00500           $str .= str_replace("\n","",var_export($arg,TRUE));
00501         }
00502       }
00503       $str .= ') ['.basename($dbg[2]['file']).':'.$dbg[2]['line'].']';
00504       phpCAS::log($str);
00505       $PHPCAS_DEBUG['indent'] ++;
00506     }
00507 
00513   function traceEnd($res='')
00514     {
00515       global $PHPCAS_DEBUG;
00516 
00517       $PHPCAS_DEBUG['indent'] --;
00518       $dbg = phpCAS::backtrace();
00519       $str = '';
00520       $str .= '<= '.str_replace("\n","",var_export($res,TRUE));
00521       phpCAS::log($str);
00522     }
00523 
00527   function traceExit()
00528     {
00529       global $PHPCAS_DEBUG;
00530 
00531       phpCAS::log('exit()');
00532       while ( $PHPCAS_DEBUG['indent'] > 0 ) {
00533         phpCAS::log('-');
00534         $PHPCAS_DEBUG['indent'] --;
00535       }
00536     }
00537 
00539   // ########################################################################
00540   //  INTERNATIONALIZATION
00541   // ########################################################################
00555   function setLang($lang)
00556     {
00557       global $PHPCAS_CLIENT;
00558       if ( !is_object($PHPCAS_CLIENT) ) {
00559         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00560       }
00561       if ( gettype($lang) != 'string' ) {
00562         phpCAS::error('type mismatched for parameter $lang (should be `string\')');
00563       }
00564       $PHPCAS_CLIENT->setLang($lang);
00565     }
00566 
00568   // ########################################################################
00569   //  VERSION
00570   // ########################################################################
00581   function getVersion()
00582     {
00583       return PHPCAS_VERSION;
00584     }
00585   
00587   // ########################################################################
00588   //  HTML OUTPUT
00589   // ########################################################################
00600   function setHTMLHeader($header)
00601     {
00602       global $PHPCAS_CLIENT;
00603       if ( !is_object($PHPCAS_CLIENT) ) {
00604         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00605       }
00606       if ( gettype($header) != 'string' ) {
00607         phpCAS::error('type mismatched for parameter $header (should be `string\')');
00608       }
00609       $PHPCAS_CLIENT->setHTMLHeader($header);
00610     }
00611 
00617   function setHTMLFooter($footer)
00618     {
00619       global $PHPCAS_CLIENT;
00620       if ( !is_object($PHPCAS_CLIENT) ) {
00621         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00622       }
00623       if ( gettype($footer) != 'string' ) {
00624         phpCAS::error('type mismatched for parameter $footer (should be `string\')');
00625       }
00626       $PHPCAS_CLIENT->setHTMLFooter($footer);
00627     }
00628 
00630   // ########################################################################
00631   //  PGT STORAGE
00632   // ########################################################################
00645   function setPGTStorageFile($format='',
00646                              $path='')
00647     {
00648       global $PHPCAS_CLIENT,$PHPCAS_AUTH_CHECK_CALL;
00649 
00650       phpCAS::traceBegin();
00651       if ( !is_object($PHPCAS_CLIENT) ) {
00652         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00653       }
00654       if ( !$PHPCAS_CLIENT->isProxy() ) {
00655         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00656       }
00657       if ( $PHPCAS_AUTH_CHECK_CALL['done'] ) {
00658         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'].')');
00659       }
00660       if ( gettype($format) != 'string' ) {
00661         phpCAS::error('type mismatched for parameter $format (should be `string\')');
00662       }
00663       if ( gettype($path) != 'string' ) {
00664         phpCAS::error('type mismatched for parameter $format (should be `string\')');
00665       }
00666       $PHPCAS_CLIENT->setPGTStorageFile($format,$path);
00667       phpCAS::traceEnd();
00668     }
00669   
00685   function setPGTStorageDB($user,
00686                            $password,
00687                            $database_type='',
00688                            $hostname='',
00689                            $port=0,
00690                            $database='',
00691                            $table='')
00692     {
00693       global $PHPCAS_CLIENT,$PHPCAS_AUTH_CHECK_CALL;
00694 
00695       phpCAS::traceBegin();
00696       if ( !is_object($PHPCAS_CLIENT) ) {
00697         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00698       }
00699       if ( !$PHPCAS_CLIENT->isProxy() ) {
00700         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00701       }
00702       if ( $PHPCAS_AUTH_CHECK_CALL['done'] ) {
00703         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'].')');
00704       }
00705       if ( gettype($user) != 'string' ) {
00706         phpCAS::error('type mismatched for parameter $user (should be `string\')');
00707       }
00708       if ( gettype($password) != 'string' ) {
00709         phpCAS::error('type mismatched for parameter $password (should be `string\')');
00710       }
00711       if ( gettype($database_type) != 'string' ) {
00712         phpCAS::error('type mismatched for parameter $database_type (should be `string\')');
00713       }
00714       if ( gettype($hostname) != 'string' ) {
00715         phpCAS::error('type mismatched for parameter $hostname (should be `string\')');
00716       }
00717       if ( gettype($port) != 'integer' ) {
00718         phpCAS::error('type mismatched for parameter $port (should be `integer\')');
00719       }
00720       if ( gettype($database) != 'string' ) {
00721         phpCAS::error('type mismatched for parameter $database (should be `string\')');
00722       }
00723       if ( gettype($table) != 'string' ) {
00724         phpCAS::error('type mismatched for parameter $table (should be `string\')');
00725       }
00726       $PHPCAS_CLIENT->setPGTStorageDB($this,$user,$password,$hostname,$port,$database,$table);
00727       phpCAS::traceEnd();
00728     }
00729   
00731   // ########################################################################
00732   // ACCESS TO EXTERNAL SERVICES
00733   // ########################################################################
00752   function serviceWeb($url,&$err_code,&$output)
00753     {
00754       global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00755 
00756       phpCAS::traceBegin();
00757       if ( !is_object($PHPCAS_CLIENT) ) {
00758         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00759       }
00760       if ( !$PHPCAS_CLIENT->isProxy() ) {
00761         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00762       }
00763       if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
00764         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()');
00765       }
00766       if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
00767         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');
00768       }
00769       if ( gettype($url) != 'string' ) {
00770         phpCAS::error('type mismatched for parameter $url (should be `string\')');
00771       }
00772       
00773       $res = $PHPCAS_CLIENT->serviceWeb($url,$err_code,$output);
00774 
00775       phpCAS::traceEnd($res);
00776       return $res;
00777     }
00778 
00795   function serviceMail($url,$flags,&$err_code,&$err_msg,&$pt)
00796     {
00797       global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00798 
00799       phpCAS::traceBegin();
00800       if ( !is_object($PHPCAS_CLIENT) ) {
00801         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00802       }
00803       if ( !$PHPCAS_CLIENT->isProxy() ) {
00804         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00805       }
00806       if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
00807         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()');
00808       }
00809       if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
00810         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');
00811       }
00812       if ( gettype($url) != 'string' ) {
00813         phpCAS::error('type mismatched for parameter $url (should be `string\')');
00814       }
00815       
00816       if ( gettype($flags) != 'integer' ) {
00817         phpCAS::error('type mismatched for parameter $flags (should be `integer\')');
00818       }
00819       
00820       $res = $PHPCAS_CLIENT->serviceMail($url,$flags,$err_code,$err_msg,$pt);
00821 
00822       phpCAS::traceEnd($res);
00823       return $res;
00824     }
00825 
00827   // ########################################################################
00828   //  AUTHENTICATION
00829   // ########################################################################
00843   function setCacheTimesForAuthRecheck($n)
00844     {
00845       global $PHPCAS_CLIENT;
00846       if ( !is_object($PHPCAS_CLIENT) ) {
00847         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00848       }
00849       if ( gettype($header) != 'integer' ) {
00850         phpCAS::error('type mismatched for parameter $header (should be `string\')');
00851       }
00852       $PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
00853     }
00854   
00859   function checkAuthentication()
00860     {
00861       global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00862 
00863       phpCAS::traceBegin();
00864       if ( !is_object($PHPCAS_CLIENT) ) {
00865         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00866       }
00867 
00868       $auth = $PHPCAS_CLIENT->checkAuthentication();
00869 
00870       // store where the authentication has been checked and the result
00871       $dbg = phpCAS::backtrace();
00872       $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,
00873                                       'file' => $dbg[0]['file'],
00874                                       'line' => $dbg[0]['line'],
00875                                       'method' => __CLASS__.'::'.__FUNCTION__,
00876                                       'result' => $auth );
00877       phpCAS::traceEnd($auth);
00878       return $auth; 
00879     }
00880   
00886   function forceAuthentication()
00887     {
00888       global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00889 
00890       phpCAS::traceBegin();
00891       if ( !is_object($PHPCAS_CLIENT) ) {
00892         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00893       }
00894       
00895       $auth = $PHPCAS_CLIENT->forceAuthentication();
00896 
00897       // store where the authentication has been checked and the result
00898       $dbg = phpCAS::backtrace();
00899       $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,
00900                                       'file' => $dbg[0]['file'],
00901                                       'line' => $dbg[0]['line'],
00902                                       'method' => __CLASS__.'::'.__FUNCTION__,
00903                                       'result' => $auth );
00904 
00905       if ( !$auth ) {
00906         phpCAS::trace('user is not authenticated, redirecting to the CAS server');
00907         $PHPCAS_CLIENT->forceAuthentication();
00908       } else {
00909         phpCAS::trace('no need to authenticate (user `'.phpCAS::getUser().'\' is already authenticated)');
00910       }
00911 
00912       phpCAS::traceEnd();
00913       return $auth; 
00914     }
00915   
00919   function authenticate()
00920     {
00921       phpCAS::error('this method is deprecated. You should use '.__CLASS__.'::forceAuthentication() instead');
00922     }
00923   
00930   function isAuthenticated()
00931     {
00932       global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00933 
00934       phpCAS::traceBegin();
00935       if ( !is_object($PHPCAS_CLIENT) ) {
00936         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00937       }
00938 
00939       // call the isAuthenticated method of the global $PHPCAS_CLIENT object
00940       $auth = $PHPCAS_CLIENT->isAuthenticated();
00941 
00942       // store where the authentication has been checked and the result
00943       $dbg = phpCAS::backtrace();
00944       $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,
00945                                      'file' => $dbg[0]['file'],
00946                                      'line' => $dbg[0]['line'],
00947                                      'method' => __CLASS__.'::'.__FUNCTION__,
00948                                      'result' => $auth );
00949       phpCAS::traceEnd($auth);
00950       return $auth;
00951     }
00952   
00959   function isSessionAuthenticated ()
00960         {
00961       global $PHPCAS_CLIENT;
00962       if ( !is_object($PHPCAS_CLIENT) ) {
00963         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00964       }
00965       return($PHPCAS_CLIENT->isSessionAuthenticated());
00966     }
00967 
00975   function getUser()
00976     {
00977       global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00978       if ( !is_object($PHPCAS_CLIENT) ) {
00979         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00980       }
00981       if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
00982         phpCAS::error('this method should only be called after '.__CLASS__.'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()');
00983       }
00984       if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
00985         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');
00986       }
00987       return $PHPCAS_CLIENT->getUser();
00988     }
00989 
00996   function getServerLoginURL()
00997     {
00998       global $PHPCAS_CLIENT;
00999       if ( !is_object($PHPCAS_CLIENT) ) {
01000         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01001       }
01002       return $PHPCAS_CLIENT->getServerLoginURL();
01003     }
01004 
01010   function setServerLoginURL($url='')
01011    {
01012      global $PHPCAS_CLIENT;
01013      phpCAS::traceBegin();
01014      if ( !is_object($PHPCAS_CLIENT) ) {
01015         phpCAS::error('this method should only be called after
01016 '.__CLASS__.'::client()');
01017      }
01018      if ( gettype($url) != 'string' ) {
01019         phpCAS::error('type mismatched for parameter $url (should be
01020 `string\')');
01021      }
01022      $PHPCAS_CLIENT->setServerLoginURL($url);
01023      phpCAS::traceEnd();
01024    }
01025 
01032   function getServerLogoutURL()
01033     {
01034       global $PHPCAS_CLIENT;
01035       if ( !is_object($PHPCAS_CLIENT) ) {
01036         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01037       }
01038       return $PHPCAS_CLIENT->getServerLogoutURL();
01039     }
01040 
01046   function setServerLogoutURL($url='')
01047    {
01048      global $PHPCAS_CLIENT;
01049      phpCAS::traceBegin();
01050      if ( !is_object($PHPCAS_CLIENT) ) {
01051         phpCAS::error('this method should only be called after
01052 '.__CLASS__.'::client()');
01053      }
01054      if ( gettype($url) != 'string' ) {
01055         phpCAS::error('type mismatched for parameter $url (should be
01056 `string\')');
01057      }
01058      $PHPCAS_CLIENT->setServerLogoutURL($url);
01059      phpCAS::traceEnd();
01060    }
01061 
01066   function logout($url = "")
01067     {
01068       global $PHPCAS_CLIENT;
01069 
01070       phpCAS::traceBegin();
01071       if ( !is_object($PHPCAS_CLIENT) ) {
01072         phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01073       }
01074       $PHPCAS_CLIENT->logout($url);
01075       // never reached
01076       phpCAS::traceEnd();
01077     }
01078 
01085   function setFixedCallbackURL($url='')
01086    {
01087      global $PHPCAS_CLIENT;
01088      phpCAS::traceBegin();
01089      if ( !is_object($PHPCAS_CLIENT) ) {
01090         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01091      }
01092      if ( !$PHPCAS_CLIENT->isProxy() ) {
01093         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01094      }
01095      if ( gettype($url) != 'string' ) {
01096         phpCAS::error('type mismatched for parameter $url (should be `string\')');
01097      }
01098      $PHPCAS_CLIENT->setCallbackURL($url);
01099      phpCAS::traceEnd();
01100    }
01101    
01108    function setFixedServiceURL($url)
01109    {
01110      global $PHPCAS_CLIENT;
01111      phpCAS::traceBegin();
01112      if ( !is_object($PHPCAS_CLIENT) ) {
01113          phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01114      }  
01115      if ( gettype($url) != 'string' ) {
01116         phpCAS::error('type mismatched for parameter $url (should be `string\')');
01117      }
01118      $PHPCAS_CLIENT->setURL($url);
01119      phpCAS::traceEnd();
01120    }
01121 
01125    function getServiceURL()
01126    {
01127      global $PHPCAS_CLIENT;
01128      if ( !is_object($PHPCAS_CLIENT) ) {
01129         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01130      }  
01131      return($PHPCAS_CLIENT->getURL());
01132    }
01133 
01137    function retrievePT($target_service,&$err_code,&$err_msg)
01138    {
01139      global $PHPCAS_CLIENT;
01140      if ( !is_object($PHPCAS_CLIENT) ) {
01141         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01142      }  
01143      if ( gettype($target_service) != 'string' ) {
01144         phpCAS::error('type mismatched for parameter $target_service(should be `string\')');
01145      }
01146      return($PHPCAS_CLIENT->retrievePT($target_service,$err_code,$err_msg));
01147    }
01150 }
01151 
01152 // ########################################################################
01153 // DOCUMENTATION
01154 // ########################################################################
01155 
01156 // ########################################################################
01157 //  MAIN PAGE
01158 
01168 // ########################################################################
01169 //  MODULES DEFINITION
01170 
01245 // ########################################################################
01246 //  EXAMPLES
01247 
01284 ?>

Generated on Wed Mar 14 14:55:56 2007 for phpCAS by  doxygen 1.5.0