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-to-php5.php');
00018 }
00019
00027
00028
00029
00030
00031
00032
00033
00034
00038 define('PHPCAS_VERSION','1.1.0RC7');
00039
00040
00041
00042
00051 define("CAS_VERSION_1_0",'1.0');
00055 define("CAS_VERSION_2_0",'2.0');
00056
00057
00058
00059
00060
00064 define("SAML_VERSION_1_1", 'S1');
00065
00069 define("SAML_XML_HEADER", '<?xml version="1.0" encoding="UTF-8"?>');
00070
00074 define ("SAML_SOAP_ENV", '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/>');
00075
00079 define ("SAML_SOAP_BODY", '<SOAP-ENV:Body>');
00080
00084 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">');
00085 define ("SAMLP_REQUEST_CLOSE", '</samlp:Request>');
00086
00090 define ("SAML_ASSERTION_ARTIFACT", '<samlp:AssertionArtifact>');
00091
00095 define ("SAML_ASSERTION_ARTIFACT_CLOSE", '</samlp:AssertionArtifact>');
00096
00100 define ("SAML_SOAP_BODY_CLOSE", '</SOAP-ENV:Body>');
00101
00105 define ("SAML_SOAP_ENV_CLOSE", '</SOAP-ENV:Envelope>');
00106
00110 define("SAML_ATTRIBUTES", 'SAMLATTRIBS');
00111
00112
00113
00119
00120
00121
00125 define("CAS_PGT_STORAGE_FILE_DEFAULT_PATH",'/tmp');
00129 define("CAS_PGT_STORAGE_FILE_FORMAT_PLAIN",'plain');
00133 define("CAS_PGT_STORAGE_FILE_FORMAT_XML",'xml');
00137 define("CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT",CAS_PGT_STORAGE_FILE_FORMAT_PLAIN);
00138
00139
00140
00144 define("CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE",'mysql');
00148 define("CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME",'localhost');
00152 define("CAS_PGT_STORAGE_DB_DEFAULT_PORT",'');
00156 define("CAS_PGT_STORAGE_DB_DEFAULT_DATABASE",'phpCAS');
00160 define("CAS_PGT_STORAGE_DB_DEFAULT_TABLE",'pgt');
00161
00163
00164
00165
00174 define("PHPCAS_SERVICE_OK",0);
00179 define("PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE",1);
00184 define("PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE",2);
00189 define("PHPCAS_SERVICE_PT_FAILURE",3);
00193 define("PHPCAS_SERVICE_NOT AVAILABLE",4);
00194
00196
00197
00198
00204 define("PHPCAS_LANG_ENGLISH", 'english');
00205 define("PHPCAS_LANG_FRENCH", 'french');
00206 define("PHPCAS_LANG_GREEK", 'greek');
00207 define("PHPCAS_LANG_GERMAN", 'german');
00208 define("PHPCAS_LANG_JAPANESE", 'japanese');
00209 define("PHPCAS_LANG_SPANISH", 'spanish');
00210 define("PHPCAS_LANG_CATALAN", 'catalan');
00211
00222 define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);
00223
00225
00226
00227
00236 define('DEFAULT_DEBUG_DIR','/tmp/');
00237
00239
00240
00241
00252 $GLOBALS['PHPCAS_CLIENT'] = null;
00253
00260 $GLOBALS['PHPCAS_INIT_CALL'] = array('done' => FALSE,
00261 'file' => '?',
00262 'line' => -1,
00263 'method' => '?');
00264
00271 $GLOBALS['PHPCAS_AUTH_CHECK_CALL'] = array('done' => FALSE,
00272 'file' => '?',
00273 'line' => -1,
00274 'method' => '?',
00275 'result' => FALSE);
00276
00282 $GLOBALS['PHPCAS_DEBUG'] = array('filename' => FALSE,
00283 'indent' => 0,
00284 'unique_id' => '');
00285
00288
00289
00290
00291
00292
00293 include_once(dirname(__FILE__).'/CAS/client.php');
00294
00295
00296
00297
00298
00313 class phpCAS
00314 {
00315
00316
00317
00318
00319
00339 function client($server_version,
00340 $server_hostname,
00341 $server_port,
00342 $server_uri,
00343 $start_session = true)
00344 {
00345 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
00346
00347 phpCAS::traceBegin();
00348 if ( is_object($PHPCAS_CLIENT) ) {
00349 phpCAS::error($PHPCAS_INIT_CALL['method'].'() has already been called (at '.$PHPCAS_INIT_CALL['file'].':'.$PHPCAS_INIT_CALL['line'].')');
00350 }
00351 if ( gettype($server_version) != 'string' ) {
00352 phpCAS::error('type mismatched for parameter $server_version (should be `string\')');
00353 }
00354 if ( gettype($server_hostname) != 'string' ) {
00355 phpCAS::error('type mismatched for parameter $server_hostname (should be `string\')');
00356 }
00357 if ( gettype($server_port) != 'integer' ) {
00358 phpCAS::error('type mismatched for parameter $server_port (should be `integer\')');
00359 }
00360 if ( gettype($server_uri) != 'string' ) {
00361 phpCAS::error('type mismatched for parameter $server_uri (should be `string\')');
00362 }
00363
00364
00365 $dbg = phpCAS::backtrace();
00366 $PHPCAS_INIT_CALL = array('done' => TRUE,
00367 'file' => $dbg[0]['file'],
00368 'line' => $dbg[0]['line'],
00369 'method' => __CLASS__.'::'.__FUNCTION__);
00370
00371
00372 $PHPCAS_CLIENT = new CASClient($server_version,FALSE,$server_hostname,$server_port,$server_uri,$start_session);
00373 phpCAS::traceEnd();
00374 }
00375
00390 function proxy($server_version,
00391 $server_hostname,
00392 $server_port,
00393 $server_uri,
00394 $start_session = true)
00395 {
00396 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
00397
00398 phpCAS::traceBegin();
00399 if ( is_object($PHPCAS_CLIENT) ) {
00400 phpCAS::error($PHPCAS_INIT_CALL['method'].'() has already been called (at '.$PHPCAS_INIT_CALL['file'].':'.$PHPCAS_INIT_CALL['line'].')');
00401 }
00402 if ( gettype($server_version) != 'string' ) {
00403 phpCAS::error('type mismatched for parameter $server_version (should be `string\')');
00404 }
00405 if ( gettype($server_hostname) != 'string' ) {
00406 phpCAS::error('type mismatched for parameter $server_hostname (should be `string\')');
00407 }
00408 if ( gettype($server_port) != 'integer' ) {
00409 phpCAS::error('type mismatched for parameter $server_port (should be `integer\')');
00410 }
00411 if ( gettype($server_uri) != 'string' ) {
00412 phpCAS::error('type mismatched for parameter $server_uri (should be `string\')');
00413 }
00414
00415
00416 $dbg = phpCAS::backtrace();
00417 $PHPCAS_INIT_CALL = array('done' => TRUE,
00418 'file' => $dbg[0]['file'],
00419 'line' => $dbg[0]['line'],
00420 'method' => __CLASS__.'::'.__FUNCTION__);
00421
00422
00423 $PHPCAS_CLIENT = new CASClient($server_version,TRUE,$server_hostname,$server_port,$server_uri,$start_session);
00424 phpCAS::traceEnd();
00425 }
00426
00428
00429
00430
00431
00442 function setDebug($filename='')
00443 {
00444 global $PHPCAS_DEBUG;
00445
00446 if ( $filename != FALSE && gettype($filename) != 'string' ) {
00447 phpCAS::error('type mismatched for parameter $dbg (should be FALSE or the name of the log file)');
00448 }
00449
00450 if ( empty($filename) ) {
00451 if ( preg_match('/^Win.*/',getenv('OS')) ) {
00452 if ( isset($_ENV['TMP']) ) {
00453 $debugDir = $_ENV['TMP'].'/';
00454 } else if ( isset($_ENV['TEMP']) ) {
00455 $debugDir = $_ENV['TEMP'].'/';
00456 } else {
00457 $debugDir = '';
00458 }
00459 } else {
00460 $debugDir = DEFAULT_DEBUG_DIR;
00461 }
00462 $filename = $debugDir . 'phpCAS.log';
00463 }
00464
00465 if ( empty($PHPCAS_DEBUG['unique_id']) ) {
00466 $PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))),0,4);
00467 }
00468
00469 $PHPCAS_DEBUG['filename'] = $filename;
00470
00471 phpCAS::trace('START ******************');
00472 }
00473
00484 function backtrace()
00485 {
00486 if ( function_exists('debug_backtrace') ) {
00487 return debug_backtrace();
00488 } else {
00489
00490 return array();
00491 }
00492 }
00493
00501 function log($str)
00502 {
00503 $indent_str = ".";
00504 global $PHPCAS_DEBUG;
00505
00506 if ( $PHPCAS_DEBUG['filename'] ) {
00507 for ($i=0;$i<$PHPCAS_DEBUG['indent'];$i++) {
00508 $indent_str .= '| ';
00509 }
00510 error_log($PHPCAS_DEBUG['unique_id'].' '.$indent_str.$str."\n",3,$PHPCAS_DEBUG['filename']);
00511 }
00512
00513 }
00514
00523 function error($msg)
00524 {
00525 $dbg = phpCAS::backtrace();
00526 $function = '?';
00527 $file = '?';
00528 $line = '?';
00529 if ( is_array($dbg) ) {
00530 for ( $i=1; $i<sizeof($dbg); $i++) {
00531 if ( is_array($dbg[$i]) ) {
00532 if ( $dbg[$i]['class'] == __CLASS__ ) {
00533 $function = $dbg[$i]['function'];
00534 $file = $dbg[$i]['file'];
00535 $line = $dbg[$i]['line'];
00536 }
00537 }
00538 }
00539 }
00540 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";
00541 phpCAS::trace($msg);
00542 phpCAS::traceExit();
00543 exit();
00544 }
00545
00549 function trace($str)
00550 {
00551 $dbg = phpCAS::backtrace();
00552 phpCAS::log($str.' ['.basename($dbg[1]['file']).':'.$dbg[1]['line'].']');
00553 }
00554
00558 function traceBegin()
00559 {
00560 global $PHPCAS_DEBUG;
00561
00562 $dbg = phpCAS::backtrace();
00563 $str = '=> ';
00564 if ( !empty($dbg[2]['class']) ) {
00565 $str .= $dbg[2]['class'].'::';
00566 }
00567 $str .= $dbg[2]['function'].'(';
00568 if ( is_array($dbg[2]['args']) ) {
00569 foreach ($dbg[2]['args'] as $index => $arg) {
00570 if ( $index != 0 ) {
00571 $str .= ', ';
00572 }
00573 $str .= str_replace("\n","",var_export($arg,TRUE));
00574 }
00575 }
00576 $str .= ') ['.basename($dbg[2]['file']).':'.$dbg[2]['line'].']';
00577 phpCAS::log($str);
00578 $PHPCAS_DEBUG['indent'] ++;
00579 }
00580
00586 function traceEnd($res='')
00587 {
00588 global $PHPCAS_DEBUG;
00589
00590 $PHPCAS_DEBUG['indent'] --;
00591 $dbg = phpCAS::backtrace();
00592 $str = '';
00593 $str .= '<= '.str_replace("\n","",var_export($res,TRUE));
00594 phpCAS::log($str);
00595 }
00596
00600 function traceExit()
00601 {
00602 global $PHPCAS_DEBUG;
00603
00604 phpCAS::log('exit()');
00605 while ( $PHPCAS_DEBUG['indent'] > 0 ) {
00606 phpCAS::log('-');
00607 $PHPCAS_DEBUG['indent'] --;
00608 }
00609 }
00610
00612
00613
00614
00628 function setLang($lang)
00629 {
00630 global $PHPCAS_CLIENT;
00631 if ( !is_object($PHPCAS_CLIENT) ) {
00632 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00633 }
00634 if ( gettype($lang) != 'string' ) {
00635 phpCAS::error('type mismatched for parameter $lang (should be `string\')');
00636 }
00637 $PHPCAS_CLIENT->setLang($lang);
00638 }
00639
00641
00642
00643
00654 function getVersion()
00655 {
00656 return PHPCAS_VERSION;
00657 }
00658
00660
00661
00662
00673 function setHTMLHeader($header)
00674 {
00675 global $PHPCAS_CLIENT;
00676 if ( !is_object($PHPCAS_CLIENT) ) {
00677 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00678 }
00679 if ( gettype($header) != 'string' ) {
00680 phpCAS::error('type mismatched for parameter $header (should be `string\')');
00681 }
00682 $PHPCAS_CLIENT->setHTMLHeader($header);
00683 }
00684
00690 function setHTMLFooter($footer)
00691 {
00692 global $PHPCAS_CLIENT;
00693 if ( !is_object($PHPCAS_CLIENT) ) {
00694 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00695 }
00696 if ( gettype($footer) != 'string' ) {
00697 phpCAS::error('type mismatched for parameter $footer (should be `string\')');
00698 }
00699 $PHPCAS_CLIENT->setHTMLFooter($footer);
00700 }
00701
00703
00704
00705
00718 function setPGTStorageFile($format='',
00719 $path='')
00720 {
00721 global $PHPCAS_CLIENT,$PHPCAS_AUTH_CHECK_CALL;
00722
00723 phpCAS::traceBegin();
00724 if ( !is_object($PHPCAS_CLIENT) ) {
00725 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00726 }
00727 if ( !$PHPCAS_CLIENT->isProxy() ) {
00728 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00729 }
00730 if ( $PHPCAS_AUTH_CHECK_CALL['done'] ) {
00731 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'].')');
00732 }
00733 if ( gettype($format) != 'string' ) {
00734 phpCAS::error('type mismatched for parameter $format (should be `string\')');
00735 }
00736 if ( gettype($path) != 'string' ) {
00737 phpCAS::error('type mismatched for parameter $format (should be `string\')');
00738 }
00739 $PHPCAS_CLIENT->setPGTStorageFile($format,$path);
00740 phpCAS::traceEnd();
00741 }
00742
00758 function setPGTStorageDB($user,
00759 $password,
00760 $database_type='',
00761 $hostname='',
00762 $port=0,
00763 $database='',
00764 $table='')
00765 {
00766 global $PHPCAS_CLIENT,$PHPCAS_AUTH_CHECK_CALL;
00767
00768 phpCAS::traceBegin();
00769 if ( !is_object($PHPCAS_CLIENT) ) {
00770 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00771 }
00772 if ( !$PHPCAS_CLIENT->isProxy() ) {
00773 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00774 }
00775 if ( $PHPCAS_AUTH_CHECK_CALL['done'] ) {
00776 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'].')');
00777 }
00778 if ( gettype($user) != 'string' ) {
00779 phpCAS::error('type mismatched for parameter $user (should be `string\')');
00780 }
00781 if ( gettype($password) != 'string' ) {
00782 phpCAS::error('type mismatched for parameter $password (should be `string\')');
00783 }
00784 if ( gettype($database_type) != 'string' ) {
00785 phpCAS::error('type mismatched for parameter $database_type (should be `string\')');
00786 }
00787 if ( gettype($hostname) != 'string' ) {
00788 phpCAS::error('type mismatched for parameter $hostname (should be `string\')');
00789 }
00790 if ( gettype($port) != 'integer' ) {
00791 phpCAS::error('type mismatched for parameter $port (should be `integer\')');
00792 }
00793 if ( gettype($database) != 'string' ) {
00794 phpCAS::error('type mismatched for parameter $database (should be `string\')');
00795 }
00796 if ( gettype($table) != 'string' ) {
00797 phpCAS::error('type mismatched for parameter $table (should be `string\')');
00798 }
00799 $PHPCAS_CLIENT->setPGTStorageDB($user,$password,$database_type,$hostname,$port,$database,$table);
00800 phpCAS::traceEnd();
00801 }
00802
00804
00805
00806
00825 function serviceWeb($url,&$err_code,&$output)
00826 {
00827 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00828
00829 phpCAS::traceBegin();
00830 if ( !is_object($PHPCAS_CLIENT) ) {
00831 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00832 }
00833 if ( !$PHPCAS_CLIENT->isProxy() ) {
00834 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00835 }
00836 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
00837 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()');
00838 }
00839 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
00840 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');
00841 }
00842 if ( gettype($url) != 'string' ) {
00843 phpCAS::error('type mismatched for parameter $url (should be `string\')');
00844 }
00845
00846 $res = $PHPCAS_CLIENT->serviceWeb($url,$err_code,$output);
00847
00848 phpCAS::traceEnd($res);
00849 return $res;
00850 }
00851
00869 function serviceMail($url,$service,$flags,&$err_code,&$err_msg,&$pt)
00870 {
00871 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00872
00873 phpCAS::traceBegin();
00874 if ( !is_object($PHPCAS_CLIENT) ) {
00875 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00876 }
00877 if ( !$PHPCAS_CLIENT->isProxy() ) {
00878 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
00879 }
00880 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
00881 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()');
00882 }
00883 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
00884 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');
00885 }
00886 if ( gettype($url) != 'string' ) {
00887 phpCAS::error('type mismatched for parameter $url (should be `string\')');
00888 }
00889
00890 if ( gettype($flags) != 'integer' ) {
00891 phpCAS::error('type mismatched for parameter $flags (should be `integer\')');
00892 }
00893
00894 $res = $PHPCAS_CLIENT->serviceMail($url,$service,$flags,$err_code,$err_msg,$pt);
00895
00896 phpCAS::traceEnd($res);
00897 return $res;
00898 }
00899
00901
00902
00903
00917 function setCacheTimesForAuthRecheck($n)
00918 {
00919 global $PHPCAS_CLIENT;
00920 if ( !is_object($PHPCAS_CLIENT) ) {
00921 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00922 }
00923 if ( gettype($n) != 'integer' ) {
00924 phpCAS::error('type mismatched for parameter $header (should be `string\')');
00925 }
00926 $PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
00927 }
00928
00933 function checkAuthentication()
00934 {
00935 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00936
00937 phpCAS::traceBegin();
00938 if ( !is_object($PHPCAS_CLIENT) ) {
00939 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00940 }
00941
00942 $auth = $PHPCAS_CLIENT->checkAuthentication();
00943
00944
00945 $dbg = phpCAS::backtrace();
00946 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,
00947 'file' => $dbg[0]['file'],
00948 'line' => $dbg[0]['line'],
00949 'method' => __CLASS__.'::'.__FUNCTION__,
00950 'result' => $auth );
00951 phpCAS::traceEnd($auth);
00952 return $auth;
00953 }
00954
00960 function forceAuthentication()
00961 {
00962 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00963
00964 phpCAS::traceBegin();
00965 if ( !is_object($PHPCAS_CLIENT) ) {
00966 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00967 }
00968
00969 $auth = $PHPCAS_CLIENT->forceAuthentication();
00970
00971
00972 $dbg = phpCAS::backtrace();
00973 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,
00974 'file' => $dbg[0]['file'],
00975 'line' => $dbg[0]['line'],
00976 'method' => __CLASS__.'::'.__FUNCTION__,
00977 'result' => $auth );
00978
00979 if ( !$auth ) {
00980 phpCAS::trace('user is not authenticated, redirecting to the CAS server');
00981 $PHPCAS_CLIENT->forceAuthentication();
00982 } else {
00983 phpCAS::trace('no need to authenticate (user `'.phpCAS::getUser().'\' is already authenticated)');
00984 }
00985
00986 phpCAS::traceEnd();
00987 return $auth;
00988 }
00989
00993 function renewAuthentication() {
00994 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00995
00996 phpCAS::traceBegin();
00997 if ( !is_object($PHPCAS_CLIENT) ) {
00998 phpCAS::error('this method should not be called before'.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
00999 }
01000
01001 // store where the authentication has been checked and the result
01002 $dbg = phpCAS::backtrace();
01003 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE, 'file' => $dbg[0]['file'], 'line' => $dbg[0]['line'], 'method' => __CLASS__.'::'.__FUNCTION__, 'result' => $auth );
01004
01005 $PHPCAS_CLIENT->renewAuthentication();
01006 phpCAS::traceEnd();
01007 }
01008
01012 function authenticate()
01013 {
01014 phpCAS::error('this method is deprecated. You should use '.__CLASS__.'::forceAuthentication() instead');
01015 }
01016
01023 function isAuthenticated()
01024 {
01025 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01026
01027 phpCAS::traceBegin();
01028 if ( !is_object($PHPCAS_CLIENT) ) {
01029 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01030 }
01031
01032 // call the isAuthenticated method of the global $PHPCAS_CLIENT object
01033 $auth = $PHPCAS_CLIENT->isAuthenticated();
01034
01035 // store where the authentication has been checked and the result
01036 $dbg = phpCAS::backtrace();
01037 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,
01038 'file' => $dbg[0]['file'],
01039 'line' => $dbg[0]['line'],
01040 'method' => __CLASS__.'::'.__FUNCTION__,
01041 'result' => $auth );
01042 phpCAS::traceEnd($auth);
01043 return $auth;
01044 }
01045
01052 function isSessionAuthenticated ()
01053 {
01054 global $PHPCAS_CLIENT;
01055 if ( !is_object($PHPCAS_CLIENT) ) {
01056 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01057 }
01058 return($PHPCAS_CLIENT->isSessionAuthenticated());
01059 }
01060
01068 function getUser()
01069 {
01070 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01071 if ( !is_object($PHPCAS_CLIENT) ) {
01072 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01073 }
01074 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
01075 phpCAS::error('this method should only be called after '.__CLASS__.'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()');
01076 }
01077 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
01078 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');
01079 }
01080 return $PHPCAS_CLIENT->getUser();
01081 }
01082
01090 function getAttributes()
01091 {
01092 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01093 if ( !is_object($PHPCAS_CLIENT) ) {
01094 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01095 }
01096 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
01097 phpCAS::error('this method should only be called after '.__CLASS__.'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()');
01098 }
01099 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
01100 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');
01101 }
01102 return $PHPCAS_CLIENT->getAttributes();
01103 }
01107 function handleLogoutRequests($check_client=true, $allowed_clients=false)
01108 {
01109 global $PHPCAS_CLIENT;
01110 if ( !is_object($PHPCAS_CLIENT) ) {
01111 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01112 }
01113 return($PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
01114 }
01115
01122 function getServerLoginURL()
01123 {
01124 global $PHPCAS_CLIENT;
01125 if ( !is_object($PHPCAS_CLIENT) ) {
01126 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01127 }
01128 return $PHPCAS_CLIENT->getServerLoginURL();
01129 }
01130
01136 function setServerLoginURL($url='')
01137 {
01138 global $PHPCAS_CLIENT;
01139 phpCAS::traceBegin();
01140 if ( !is_object($PHPCAS_CLIENT) ) {
01141 phpCAS::error('this method should only be called after
01142 '.__CLASS__.'::client()');
01143 }
01144 if ( gettype($url) != 'string' ) {
01145 phpCAS::error('type mismatched for parameter $url (should be
01146 `string\')');
01147 }
01148 $PHPCAS_CLIENT->setServerLoginURL($url);
01149 phpCAS::traceEnd();
01150 }
01151
01152
01158 function setServerServiceValidateURL($url='')
01159 {
01160 global $PHPCAS_CLIENT;
01161 phpCAS::traceBegin();
01162 if ( !is_object($PHPCAS_CLIENT) ) {
01163 phpCAS::error('this method should only be called after
01164 '.__CLASS__.'::client()');
01165 }
01166 if ( gettype($url) != 'string' ) {
01167 phpCAS::error('type mismatched for parameter $url (should be
01168 `string\')');
01169 }
01170 $PHPCAS_CLIENT->setServerServiceValidateURL($url);
01171 phpCAS::traceEnd();
01172 }
01173
01174
01180 function setServerProxyValidateURL($url='')
01181 {
01182 global $PHPCAS_CLIENT;
01183 phpCAS::traceBegin();
01184 if ( !is_object($PHPCAS_CLIENT) ) {
01185 phpCAS::error('this method should only be called after
01186 '.__CLASS__.'::client()');
01187 }
01188 if ( gettype($url) != 'string' ) {
01189 phpCAS::error('type mismatched for parameter $url (should be
01190 `string\')');
01191 }
01192 $PHPCAS_CLIENT->setServerProxyValidateURL($url);
01193 phpCAS::traceEnd();
01194 }
01195
01201 function setServerSamlValidateURL($url='')
01202 {
01203 global $PHPCAS_CLIENT;
01204 phpCAS::traceBegin();
01205 if ( !is_object($PHPCAS_CLIENT) ) {
01206 phpCAS::error('this method should only be called after
01207 '.__CLASS__.'::client()');
01208 }
01209 if ( gettype($url) != 'string' ) {
01210 phpCAS::error('type mismatched for parameter $url (should be
01211 `string\')');
01212 }
01213 $PHPCAS_CLIENT->setServerSamlValidateURL($url);
01214 phpCAS::traceEnd();
01215 }
01216
01223 function getServerLogoutURL()
01224 {
01225 global $PHPCAS_CLIENT;
01226 if ( !is_object($PHPCAS_CLIENT) ) {
01227 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
01228 }
01229 return $PHPCAS_CLIENT->getServerLogoutURL();
01230 }
01231
01237 function setServerLogoutURL($url='')
01238 {
01239 global $PHPCAS_CLIENT;
01240 phpCAS::traceBegin();
01241 if ( !is_object($PHPCAS_CLIENT) ) {
01242 phpCAS::error('this method should only be called after
01243 '.__CLASS__.'::client()');
01244 }
01245 if ( gettype($url) != 'string' ) {
01246 phpCAS::error('type mismatched for parameter $url (should be
01247 `string\')');
01248 }
01249 $PHPCAS_CLIENT->setServerLogoutURL($url);
01250 phpCAS::traceEnd();
01251 }
01252
01258 function logout($params = "") {
01259 global $PHPCAS_CLIENT;
01260 phpCAS::traceBegin();
01261 if (!is_object($PHPCAS_CLIENT)) {
01262 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01263 }
01264 $parsedParams = array();
01265 if ($params != "") {
01266 if (is_string($params)) {
01267 phpCAS::error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');
01268 }
01269 if (!is_array($params)) {
01270 phpCAS::error('type mismatched for parameter $params (should be `array\')');
01271 }
01272 foreach ($params as $key => $value) {
01273 if ($key != "service" && $key != "url") {
01274 phpCAS::error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');
01275 }
01276 $parsedParams[$key] = $value;
01277 }
01278 }
01279 $PHPCAS_CLIENT->logout($parsedParams);
01280
01281 phpCAS::traceEnd();
01282 }
01283
01288 function logoutWithRedirectService($service) {
01289 global $PHPCAS_CLIENT;
01290 phpCAS::traceBegin();
01291 if ( !is_object($PHPCAS_CLIENT) ) {
01292 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01293 }
01294 if (!is_string($service)) {
01295 phpCAS::error('type mismatched for parameter $service (should be `string\')');
01296 }
01297 $PHPCAS_CLIENT->logout(array("service" => $service));
01298
01299 phpCAS::traceEnd();
01300 }
01301
01306 function logoutWithUrl($url) {
01307 global $PHPCAS_CLIENT;
01308 phpCAS::traceBegin();
01309 if ( !is_object($PHPCAS_CLIENT) ) {
01310 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01311 }
01312 if (!is_string($url)) {
01313 phpCAS::error('type mismatched for parameter $url (should be `string\')');
01314 }
01315 $PHPCAS_CLIENT->logout(array("url" => $url));
01316
01317 phpCAS::traceEnd();
01318 }
01319
01325 function logoutWithRedirectServiceAndUrl($service, $url) {
01326 global $PHPCAS_CLIENT;
01327 phpCAS::traceBegin();
01328 if ( !is_object($PHPCAS_CLIENT) ) {
01329 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01330 }
01331 if (!is_string($service)) {
01332 phpCAS::error('type mismatched for parameter $service (should be `string\')');
01333 }
01334 if (!is_string($url)) {
01335 phpCAS::error('type mismatched for parameter $url (should be `string\')');
01336 }
01337 $PHPCAS_CLIENT->logout(array("service" => $service, "url" => $url));
01338
01339 phpCAS::traceEnd();
01340 }
01341
01348 function setFixedCallbackURL($url='')
01349 {
01350 global $PHPCAS_CLIENT;
01351 phpCAS::traceBegin();
01352 if ( !is_object($PHPCAS_CLIENT) ) {
01353 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01354 }
01355 if ( !$PHPCAS_CLIENT->isProxy() ) {
01356 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01357 }
01358 if ( gettype($url) != 'string' ) {
01359 phpCAS::error('type mismatched for parameter $url (should be `string\')');
01360 }
01361 $PHPCAS_CLIENT->setCallbackURL($url);
01362 phpCAS::traceEnd();
01363 }
01364
01371 function setFixedServiceURL($url)
01372 {
01373 global $PHPCAS_CLIENT;
01374 phpCAS::traceBegin();
01375 if ( !is_object($PHPCAS_CLIENT) ) {
01376 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01377 }
01378 if ( gettype($url) != 'string' ) {
01379 phpCAS::error('type mismatched for parameter $url (should be `string\')');
01380 }
01381 $PHPCAS_CLIENT->setURL($url);
01382 phpCAS::traceEnd();
01383 }
01384
01388 function getServiceURL()
01389 {
01390 global $PHPCAS_CLIENT;
01391 if ( !is_object($PHPCAS_CLIENT) ) {
01392 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01393 }
01394 return($PHPCAS_CLIENT->getURL());
01395 }
01396
01400 function retrievePT($target_service,&$err_code,&$err_msg)
01401 {
01402 global $PHPCAS_CLIENT;
01403 if ( !is_object($PHPCAS_CLIENT) ) {
01404 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
01405 }
01406 if ( gettype($target_service) != 'string' ) {
01407 phpCAS::error('type mismatched for parameter $target_service(should be `string\')');
01408 }
01409 return($PHPCAS_CLIENT->retrievePT($target_service,$err_code,$err_msg));
01410 }
01411
01417 function setCasServerCert($cert)
01418 {
01419 global $PHPCAS_CLIENT;
01420 phpCAS::traceBegin();
01421 if ( !is_object($PHPCAS_CLIENT) ) {
01422 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01423 }
01424 if ( gettype($cert) != 'string' ) {
01425 phpCAS::error('type mismatched for parameter $cert (should be `string\')');
01426 }
01427 $PHPCAS_CLIENT->setCasServerCert($cert);
01428 phpCAS::traceEnd();
01429 }
01430
01436 function setCasServerCACert($cert)
01437 {
01438 global $PHPCAS_CLIENT;
01439 phpCAS::traceBegin();
01440 if ( !is_object($PHPCAS_CLIENT) ) {
01441 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01442 }
01443 if ( gettype($cert) != 'string' ) {
01444 phpCAS::error('type mismatched for parameter $cert (should be `string\')');
01445 }
01446 $PHPCAS_CLIENT->setCasServerCACert($cert);
01447 phpCAS::traceEnd();
01448 }
01449
01453 function setNoCasServerValidation()
01454 {
01455 global $PHPCAS_CLIENT;
01456 phpCAS::traceBegin();
01457 if ( !is_object($PHPCAS_CLIENT) ) {
01458 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01459 }
01460 $PHPCAS_CLIENT->setNoCasServerValidation();
01461 phpCAS::traceEnd();
01462 }
01463
01472 function setExtraCurlOption($key, $value)
01473 {
01474 global $PHPCAS_CLIENT;
01475 phpCAS::traceBegin();
01476 if ( !is_object($PHPCAS_CLIENT) ) {
01477 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
01478 }
01479 $PHPCAS_CLIENT->setExtraCurlOption($key, $value);
01480 phpCAS::traceEnd();
01481 }
01482
01483 }
01484
01485
01486
01487
01488
01489
01490
01491
01499
01500
01501
01576
01577
01578
01615 ?>