00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 if (php_sapi_name() != 'cli') {
00037 if (!isset($_SERVER['REQUEST_URI'])) {
00038 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
00039 }
00040 }
00041
00042
00043 if (!defined('E_USER_DEPRECATED')){
00044 define('E_USER_DEPRECATED', 16384);
00045 }
00046
00054
00055
00056
00057
00058
00059
00060
00061
00065 define('PHPCAS_VERSION', '1.2.1');
00066
00067
00068
00069
00078 define("CAS_VERSION_1_0", '1.0');
00082 define("CAS_VERSION_2_0", '2.0');
00083
00084
00085
00086
00087
00091 define("SAML_VERSION_1_1", 'S1');
00092
00096 define("SAML_XML_HEADER", '<?xml version="1.0" encoding="UTF-8"?>');
00097
00101 define("SAML_SOAP_ENV", '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/>');
00102
00106 define("SAML_SOAP_BODY", '<SOAP-ENV:Body>');
00107
00111 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">');
00112 define("SAMLP_REQUEST_CLOSE", '</samlp:Request>');
00113
00117 define("SAML_ASSERTION_ARTIFACT", '<samlp:AssertionArtifact>');
00118
00122 define("SAML_ASSERTION_ARTIFACT_CLOSE", '</samlp:AssertionArtifact>');
00123
00127 define("SAML_SOAP_BODY_CLOSE", '</SOAP-ENV:Body>');
00128
00132 define("SAML_SOAP_ENV_CLOSE", '</SOAP-ENV:Envelope>');
00133
00137 define("SAML_ATTRIBUTES", 'SAMLATTRIBS');
00138
00144
00145
00146
00150 define("CAS_PGT_STORAGE_FILE_DEFAULT_PATH", '/tmp');
00154 define("CAS_PGT_STORAGE_FILE_FORMAT_PLAIN", 'plain');
00158 define("CAS_PGT_STORAGE_FILE_FORMAT_XML", 'xml');
00162 define("CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT", CAS_PGT_STORAGE_FILE_FORMAT_PLAIN);
00164
00165
00166
00175 define("PHPCAS_SERVICE_OK", 0);
00180 define("PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE", 1);
00185 define("PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE", 2);
00190 define("PHPCAS_SERVICE_PT_FAILURE", 3);
00194 define("PHPCAS_SERVICE_NOT_AVAILABLE", 4);
00195
00197
00198
00199
00205 define("PHPCAS_LANG_ENGLISH", 'english');
00206 define("PHPCAS_LANG_FRENCH", 'french');
00207 define("PHPCAS_LANG_GREEK", 'greek');
00208 define("PHPCAS_LANG_GERMAN", 'german');
00209 define("PHPCAS_LANG_JAPANESE", 'japanese');
00210 define("PHPCAS_LANG_SPANISH", 'spanish');
00211 define("PHPCAS_LANG_CATALAN", 'catalan');
00212
00223 define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);
00224
00226
00227
00228
00237 define('DEFAULT_DEBUG_DIR', '/tmp/');
00238
00240
00241
00242
00253 $GLOBALS['PHPCAS_CLIENT'] = null;
00254
00261 $GLOBALS['PHPCAS_INIT_CALL'] = array (
00262 'done' => FALSE,
00263 'file' => '?',
00264 'line' => -1,
00265 'method' => '?'
00266 );
00267
00274 $GLOBALS['PHPCAS_AUTH_CHECK_CALL'] = array (
00275 'done' => FALSE,
00276 'file' => '?',
00277 'line' => -1,
00278 'method' => '?',
00279 'result' => FALSE
00280 );
00281
00287 $GLOBALS['PHPCAS_DEBUG'] = array (
00288 'filename' => FALSE,
00289 'indent' => 0,
00290 'unique_id' => ''
00291 );
00292
00295
00296
00297
00298
00299
00300 include_once (dirname(__FILE__) . '/CAS/client.php');
00301
00302
00303
00304
00305
00318 class phpCAS {
00319
00320
00321
00322
00323
00343 public static function client($server_version, $server_hostname, $server_port, $server_uri, $start_session = true) {
00344 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
00345
00346 phpCAS :: traceBegin();
00347 if (is_object($PHPCAS_CLIENT)) {
00348 phpCAS :: error($PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . $PHPCAS_INIT_CALL['file'] . ':' . $PHPCAS_INIT_CALL['line'] . ')');
00349 }
00350 if (gettype($server_version) != 'string') {
00351 phpCAS :: error('type mismatched for parameter $server_version (should be `string\')');
00352 }
00353 if (gettype($server_hostname) != 'string') {
00354 phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')');
00355 }
00356 if (gettype($server_port) != 'integer') {
00357 phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')');
00358 }
00359 if (gettype($server_uri) != 'string') {
00360 phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')');
00361 }
00362
00363
00364 $dbg = phpCAS :: backtrace();
00365 $PHPCAS_INIT_CALL = array (
00366 'done' => TRUE,
00367 'file' => $dbg[0]['file'],
00368 'line' => $dbg[0]['line'],
00369 'method' => __CLASS__ . '::' . __FUNCTION__
00370 );
00371
00372
00373 $PHPCAS_CLIENT = new CASClient($server_version, FALSE
00374 , $server_hostname, $server_port, $server_uri, $start_session);
00375 phpCAS :: traceEnd();
00376 }
00377
00392 public static function proxy($server_version, $server_hostname, $server_port, $server_uri, $start_session = true) {
00393 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
00394
00395 phpCAS :: traceBegin();
00396 if (is_object($PHPCAS_CLIENT)) {
00397 phpCAS :: error($PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . $PHPCAS_INIT_CALL['file'] . ':' . $PHPCAS_INIT_CALL['line'] . ')');
00398 }
00399 if (gettype($server_version) != 'string') {
00400 phpCAS :: error('type mismatched for parameter $server_version (should be `string\')');
00401 }
00402 if (gettype($server_hostname) != 'string') {
00403 phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')');
00404 }
00405 if (gettype($server_port) != 'integer') {
00406 phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')');
00407 }
00408 if (gettype($server_uri) != 'string') {
00409 phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')');
00410 }
00411
00412
00413 $dbg = phpCAS :: backtrace();
00414 $PHPCAS_INIT_CALL = array (
00415 'done' => TRUE,
00416 'file' => $dbg[0]['file'],
00417 'line' => $dbg[0]['line'],
00418 'method' => __CLASS__ . '::' . __FUNCTION__
00419 );
00420
00421
00422 $PHPCAS_CLIENT = new CASClient($server_version, TRUE
00423 , $server_hostname, $server_port, $server_uri, $start_session);
00424 phpCAS :: traceEnd();
00425 }
00426
00428
00429
00430
00431
00442 public static function setDebug($filename = '') {
00443 global $PHPCAS_DEBUG;
00444
00445 if ($filename != FALSE && gettype($filename) != 'string') {
00446 phpCAS :: error('type mismatched for parameter $dbg (should be FALSE or the name of the log file)');
00447 }
00448 if ($filename === FALSE){
00449 unset($PHPCAS_DEBUG['filename']);
00450 }else{
00451 if (empty ($filename)) {
00452 if (preg_match('/^Win.*/', getenv('OS'))) {
00453 if (isset ($_ENV['TMP'])) {
00454 $debugDir = $_ENV['TMP'] . '/';
00455 } else
00456 if (isset ($_ENV['TEMP'])) {
00457 $debugDir = $_ENV['TEMP'] . '/';
00458 } else {
00459 $debugDir = '';
00460 }
00461 } else {
00462 $debugDir = DEFAULT_DEBUG_DIR;
00463 }
00464 $filename = $debugDir . 'phpCAS.log';
00465 }
00466
00467 if (empty ($PHPCAS_DEBUG['unique_id'])) {
00468 $PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4);
00469 }
00470
00471 $PHPCAS_DEBUG['filename'] = $filename;
00472
00473 phpCAS :: trace('START phpCAS-' . PHPCAS_VERSION . ' ******************');
00474 }
00475 }
00476
00487 public static function backtrace() {
00488 if (function_exists('debug_backtrace')) {
00489 return debug_backtrace();
00490 } else {
00491
00492 return array ();
00493 }
00494 }
00495
00503 public static function log($str) {
00504 $indent_str = ".";
00505 global $PHPCAS_DEBUG;
00506
00507 if ($PHPCAS_DEBUG['filename']) {
00508 for ($i = 0; $i < $PHPCAS_DEBUG['indent']; $i++) {
00509 $indent_str .= '| ';
00510 }
00511 error_log($PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str . $str . "\n", 3, $PHPCAS_DEBUG['filename']);
00512 }
00513
00514 }
00515
00524 public static function error($msg) {
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]) && isset($dbg[$i]['class']) ) {
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 public static function trace($str) {
00550 $dbg = phpCAS :: backtrace();
00551 phpCAS :: log($str . ' [' . basename($dbg[1]['file']) . ':' . $dbg[1]['line'] . ']');
00552 }
00553
00557 public static function traceBegin() {
00558 global $PHPCAS_DEBUG;
00559
00560 $dbg = phpCAS :: backtrace();
00561 $str = '=> ';
00562 if (!empty ($dbg[2]['class'])) {
00563 $str .= $dbg[2]['class'] . '::';
00564 }
00565 $str .= $dbg[2]['function'] . '(';
00566 if (is_array($dbg[2]['args'])) {
00567 foreach ($dbg[2]['args'] as $index => $arg) {
00568 if ($index != 0) {
00569 $str .= ', ';
00570 }
00571 $str .= str_replace("\n", "", var_export($arg, TRUE));
00572 }
00573 }
00574 if (isset($dbg[2]['file']))
00575 $file = basename($dbg[2]['file']);
00576 else
00577 $file = 'unknown_file';
00578 if (isset($dbg[2]['line']))
00579 $line = $dbg[2]['line'];
00580 else
00581 $line = 'unknown_line';
00582 $str .= ') [' . $file . ':' . $line . ']';
00583 phpCAS :: log($str);
00584 $PHPCAS_DEBUG['indent']++;
00585 }
00586
00592 public static function traceEnd($res = '') {
00593 global $PHPCAS_DEBUG;
00594
00595 $PHPCAS_DEBUG['indent']--;
00596 $dbg = phpCAS :: backtrace();
00597 $str = '';
00598 $str .= '<= ' . str_replace("\n", "", var_export($res, TRUE));
00599 phpCAS :: log($str);
00600 }
00601
00605 public static function traceExit() {
00606 global $PHPCAS_DEBUG;
00607
00608 phpCAS :: log('exit()');
00609 while ($PHPCAS_DEBUG['indent'] > 0) {
00610 phpCAS :: log('-');
00611 $PHPCAS_DEBUG['indent']--;
00612 }
00613 }
00614
00616
00617
00618
00632 public static function setLang($lang) {
00633 global $PHPCAS_CLIENT;
00634 if (!is_object($PHPCAS_CLIENT)) {
00635 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00636 }
00637 if (gettype($lang) != 'string') {
00638 phpCAS :: error('type mismatched for parameter $lang (should be `string\')');
00639 }
00640 $PHPCAS_CLIENT->setLang($lang);
00641 }
00642
00644
00645
00646
00657 public static function getVersion() {
00658 return PHPCAS_VERSION;
00659 }
00660
00662
00663
00664
00675 public static function setHTMLHeader($header) {
00676 global $PHPCAS_CLIENT;
00677 if (!is_object($PHPCAS_CLIENT)) {
00678 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00679 }
00680 if (gettype($header) != 'string') {
00681 phpCAS :: error('type mismatched for parameter $header (should be `string\')');
00682 }
00683 $PHPCAS_CLIENT->setHTMLHeader($header);
00684 }
00685
00691 public static function setHTMLFooter($footer) {
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
00716 public static function setPGTStorage($storage) {
00717 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00718
00719 phpCAS :: traceBegin();
00720 if (!is_object($PHPCAS_CLIENT)) {
00721 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00722 }
00723 if (!$PHPCAS_CLIENT->isProxy()) {
00724 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00725 }
00726 if ($PHPCAS_AUTH_CHECK_CALL['done']) {
00727 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'] . ')');
00728 }
00729 if ( !($storage instanceof CAS_PGTStorage) ) {
00730 phpCAS :: error('type mismatched for parameter $storage (should be a CAS_PGTStorage `object\')');
00731 }
00732 $PHPCAS_CLIENT->setPGTStorage($storage);
00733 phpCAS :: traceEnd();
00734 }
00735
00746 public static function setPGTStorageDb($dsn_or_pdo, $username='', $password='', $table='', $driver_options=null) {
00747 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00748
00749 phpCAS :: traceBegin();
00750 if (!is_object($PHPCAS_CLIENT)) {
00751 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00752 }
00753 if (!$PHPCAS_CLIENT->isProxy()) {
00754 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00755 }
00756 if ($PHPCAS_AUTH_CHECK_CALL['done']) {
00757 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'] . ')');
00758 }
00759 if (gettype($username) != 'string') {
00760 phpCAS :: error('type mismatched for parameter $username (should be `string\')');
00761 }
00762 if (gettype($password) != 'string') {
00763 phpCAS :: error('type mismatched for parameter $password (should be `string\')');
00764 }
00765 if (gettype($table) != 'string') {
00766 phpCAS :: error('type mismatched for parameter $table (should be `string\')');
00767 }
00768 $PHPCAS_CLIENT->setPGTStorageDb($dsn_or_pdo, $username, $password, $table, $driver_options);
00769 phpCAS :: traceEnd();
00770 }
00771
00779 public static function setPGTStorageFile($format = '', $path = '') {
00780 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00781
00782 phpCAS :: traceBegin();
00783 if (!is_object($PHPCAS_CLIENT)) {
00784 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00785 }
00786 if (!$PHPCAS_CLIENT->isProxy()) {
00787 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00788 }
00789 if ($PHPCAS_AUTH_CHECK_CALL['done']) {
00790 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'] . ')');
00791 }
00792 if (gettype($format) != 'string') {
00793 phpCAS :: error('type mismatched for parameter $format (should be `string\')');
00794 }
00795 if (gettype($path) != 'string') {
00796 phpCAS :: error('type mismatched for parameter $format (should be `string\')');
00797 }
00798 $PHPCAS_CLIENT->setPGTStorageFile($format, $path);
00799 phpCAS :: traceEnd();
00800 }
00801
00803
00804
00805
00824 public static function serviceWeb($url, & $err_code, & $output) {
00825 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00826
00827 phpCAS :: traceBegin();
00828 if (!is_object($PHPCAS_CLIENT)) {
00829 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00830 }
00831 if (!$PHPCAS_CLIENT->isProxy()) {
00832 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00833 }
00834 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
00835 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()');
00836 }
00837 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
00838 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');
00839 }
00840 if (gettype($url) != 'string') {
00841 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
00842 }
00843
00844 $res = $PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
00845
00846 phpCAS :: traceEnd($res);
00847 return $res;
00848 }
00849
00867 public static function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt) {
00868 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00869
00870 phpCAS :: traceBegin();
00871 if (!is_object($PHPCAS_CLIENT)) {
00872 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00873 }
00874 if (!$PHPCAS_CLIENT->isProxy()) {
00875 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00876 }
00877 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
00878 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()');
00879 }
00880 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
00881 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');
00882 }
00883 if (gettype($url) != 'string') {
00884 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
00885 }
00886
00887 if (gettype($flags) != 'integer') {
00888 phpCAS :: error('type mismatched for parameter $flags (should be `integer\')');
00889 }
00890
00891 $res = $PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
00892
00893 phpCAS :: traceEnd($res);
00894 return $res;
00895 }
00896
00898
00899
00900
00914 public static function setCacheTimesForAuthRecheck($n) {
00915 global $PHPCAS_CLIENT;
00916 if (!is_object($PHPCAS_CLIENT)) {
00917 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00918 }
00919 if (gettype($n) != 'integer') {
00920 phpCAS :: error('type mismatched for parameter $header (should be `string\')');
00921 }
00922 $PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
00923 }
00924
00943 public static function setPostAuthenticateCallback ($function, array $additionalArgs = array()) {
00944 global $PHPCAS_CLIENT;
00945 if (!is_object($PHPCAS_CLIENT)) {
00946 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00947 }
00948
00949 $PHPCAS_CLIENT->setPostAuthenticateCallback($function, $additionalArgs);
00950 }
00951
00965 public static function setSingleSignoutCallback ($function, array $additionalArgs = array()) {
00966 global $PHPCAS_CLIENT;
00967 if (!is_object($PHPCAS_CLIENT)) {
00968 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00969 }
00970
00971 $PHPCAS_CLIENT->setSingleSignoutCallback($function, $additionalArgs);
00972 }
00973
00980 public static function checkAuthentication() {
00981 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00982
00983 phpCAS :: traceBegin();
00984 if (!is_object($PHPCAS_CLIENT)) {
00985 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00986 }
00987
00988 $auth = $PHPCAS_CLIENT->checkAuthentication();
00989
00990
00991 $dbg = phpCAS :: backtrace();
00992 $PHPCAS_AUTH_CHECK_CALL = array (
00993 'done' => TRUE,
00994 'file' => $dbg[0]['file'],
00995 'line' => $dbg[0]['line'],
00996 'method' => __CLASS__ . '::' . __FUNCTION__,
00997 'result' => $auth
00998 );
00999 phpCAS :: traceEnd($auth);
01000 return $auth;
01001 }
01002
01008 public static function forceAuthentication() {
01009 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01010
01011 phpCAS :: traceBegin();
01012 if (!is_object($PHPCAS_CLIENT)) {
01013 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01014 }
01015
01016 $auth = $PHPCAS_CLIENT->forceAuthentication();
01017
01018
01019 $dbg = phpCAS :: backtrace();
01020 $PHPCAS_AUTH_CHECK_CALL = array (
01021 'done' => TRUE,
01022 'file' => $dbg[0]['file'],
01023 'line' => $dbg[0]['line'],
01024 'method' => __CLASS__ . '::' . __FUNCTION__,
01025 'result' => $auth
01026 );
01027
01028 if (!$auth) {
01029 phpCAS :: trace('user is not authenticated, redirecting to the CAS server');
01030 $PHPCAS_CLIENT->forceAuthentication();
01031 } else {
01032 phpCAS :: trace('no need to authenticate (user `' . phpCAS :: getUser() . '\' is already authenticated)');
01033 }
01034
01035 phpCAS :: traceEnd();
01036 return $auth;
01037 }
01038
01042 public static function renewAuthentication() {
01043 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01044
01045 phpCAS :: traceBegin();
01046 if (!is_object($PHPCAS_CLIENT)) {
01047 phpCAS :: error('this method should not be called before' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01048 }
01049 $auth = $PHPCAS_CLIENT->renewAuthentication();
01050 // store where the authentication has been checked and the result
01051 $dbg = phpCAS :: backtrace();
01052 $PHPCAS_AUTH_CHECK_CALL = array (
01053 'done' => TRUE,
01054 'file' => $dbg[0]['file'],
01055 'line' => $dbg[0]['line'],
01056 'method' => __CLASS__ . '::' . __FUNCTION__,
01057 'result' => $auth
01058 );
01059
01060 //$PHPCAS_CLIENT->renewAuthentication();
01061 phpCAS :: traceEnd();
01062 }
01063
01070 public static function isAuthenticated() {
01071 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01072
01073 phpCAS :: traceBegin();
01074 if (!is_object($PHPCAS_CLIENT)) {
01075 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01076 }
01077
01078 // call the isAuthenticated method of the global $PHPCAS_CLIENT object
01079 $auth = $PHPCAS_CLIENT->isAuthenticated();
01080
01081 // store where the authentication has been checked and the result
01082 $dbg = phpCAS :: backtrace();
01083 $PHPCAS_AUTH_CHECK_CALL = array (
01084 'done' => TRUE,
01085 'file' => $dbg[0]['file'],
01086 'line' => $dbg[0]['line'],
01087 'method' => __CLASS__ . '::' . __FUNCTION__,
01088 'result' => $auth
01089 );
01090 phpCAS :: traceEnd($auth);
01091 return $auth;
01092 }
01093
01100 public static function isSessionAuthenticated() {
01101 global $PHPCAS_CLIENT;
01102 if (!is_object($PHPCAS_CLIENT)) {
01103 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01104 }
01105 return ($PHPCAS_CLIENT->isSessionAuthenticated());
01106 }
01107
01115 public static function getUser() {
01116 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01117 if (!is_object($PHPCAS_CLIENT)) {
01118 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01119 }
01120 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
01121 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01122 }
01123 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
01124 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');
01125 }
01126 return $PHPCAS_CLIENT->getUser();
01127 }
01128
01137 public static function getAttributes() {
01138 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01139 if (!is_object($PHPCAS_CLIENT)) {
01140 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01141 }
01142 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
01143 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01144 }
01145 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
01146 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');
01147 }
01148 return $PHPCAS_CLIENT->getAttributes();
01149 }
01150
01159 public static function hasAttributes() {
01160 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01161 if (!is_object($PHPCAS_CLIENT)) {
01162 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01163 }
01164 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
01165 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01166 }
01167 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
01168 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');
01169 }
01170 return $PHPCAS_CLIENT->hasAttributes();
01171 }
01172
01182 public static function hasAttribute($key) {
01183 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01184 if (!is_object($PHPCAS_CLIENT)) {
01185 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01186 }
01187 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
01188 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01189 }
01190 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
01191 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');
01192 }
01193 return $PHPCAS_CLIENT->hasAttribute($key);
01194 }
01195
01205 public static function getAttribute($key) {
01206 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01207 if (!is_object($PHPCAS_CLIENT)) {
01208 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01209 }
01210 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
01211 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01212 }
01213 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
01214 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');
01215 }
01216 return $PHPCAS_CLIENT->getAttribute($key);
01217 }
01218
01222 public static function handleLogoutRequests($check_client = true, $allowed_clients = false) {
01223 global $PHPCAS_CLIENT;
01224 if (!is_object($PHPCAS_CLIENT)) {
01225 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01226 }
01227 return ($PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
01228 }
01229
01236 public static function getServerLoginURL() {
01237 global $PHPCAS_CLIENT;
01238 if (!is_object($PHPCAS_CLIENT)) {
01239 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01240 }
01241 return $PHPCAS_CLIENT->getServerLoginURL();
01242 }
01243
01249 public static function setServerLoginURL($url = '') {
01250 global $PHPCAS_CLIENT;
01251 phpCAS :: traceBegin();
01252 if (!is_object($PHPCAS_CLIENT)) {
01253 phpCAS :: error('this method should only be called after
01254 ' . __CLASS__ . '::client()');
01255 }
01256 if (gettype($url) != 'string') {
01257 phpCAS :: error('type mismatched for parameter $url (should be
01258 `string\')');
01259 }
01260 $PHPCAS_CLIENT->setServerLoginURL($url);
01261 phpCAS :: traceEnd();
01262 }
01263
01270 public static function setServerServiceValidateURL($url = '') {
01271 global $PHPCAS_CLIENT;
01272 phpCAS :: traceBegin();
01273 if (!is_object($PHPCAS_CLIENT)) {
01274 phpCAS :: error('this method should only be called after
01275 ' . __CLASS__ . '::client()');
01276 }
01277 if (gettype($url) != 'string') {
01278 phpCAS :: error('type mismatched for parameter $url (should be
01279 `string\')');
01280 }
01281 $PHPCAS_CLIENT->setServerServiceValidateURL($url);
01282 phpCAS :: traceEnd();
01283 }
01284
01291 public static function setServerProxyValidateURL($url = '') {
01292 global $PHPCAS_CLIENT;
01293 phpCAS :: traceBegin();
01294 if (!is_object($PHPCAS_CLIENT)) {
01295 phpCAS :: error('this method should only be called after
01296 ' . __CLASS__ . '::client()');
01297 }
01298 if (gettype($url) != 'string') {
01299 phpCAS :: error('type mismatched for parameter $url (should be
01300 `string\')');
01301 }
01302 $PHPCAS_CLIENT->setServerProxyValidateURL($url);
01303 phpCAS :: traceEnd();
01304 }
01305
01311 public static function setServerSamlValidateURL($url = '') {
01312 global $PHPCAS_CLIENT;
01313 phpCAS :: traceBegin();
01314 if (!is_object($PHPCAS_CLIENT)) {
01315 phpCAS :: error('this method should only be called after
01316 ' . __CLASS__ . '::client()');
01317 }
01318 if (gettype($url) != 'string') {
01319 phpCAS :: error('type mismatched for parameter $url (should be
01320 `string\')');
01321 }
01322 $PHPCAS_CLIENT->setServerSamlValidateURL($url);
01323 phpCAS :: traceEnd();
01324 }
01325
01332 public static function getServerLogoutURL() {
01333 global $PHPCAS_CLIENT;
01334 if (!is_object($PHPCAS_CLIENT)) {
01335 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01336 }
01337 return $PHPCAS_CLIENT->getServerLogoutURL();
01338 }
01339
01345 public static function setServerLogoutURL($url = '') {
01346 global $PHPCAS_CLIENT;
01347 phpCAS :: traceBegin();
01348 if (!is_object($PHPCAS_CLIENT)) {
01349 phpCAS :: error('this method should only be called after
01350 ' . __CLASS__ . '::client()');
01351 }
01352 if (gettype($url) != 'string') {
01353 phpCAS :: error('type mismatched for parameter $url (should be
01354 `string\')');
01355 }
01356 $PHPCAS_CLIENT->setServerLogoutURL($url);
01357 phpCAS :: traceEnd();
01358 }
01359
01365 public static function logout($params = "") {
01366 global $PHPCAS_CLIENT;
01367 phpCAS :: traceBegin();
01368 if (!is_object($PHPCAS_CLIENT)) {
01369 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01370 }
01371 $parsedParams = array ();
01372 if ($params != "") {
01373 if (is_string($params)) {
01374 phpCAS :: error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');
01375 }
01376 if (!is_array($params)) {
01377 phpCAS :: error('type mismatched for parameter $params (should be `array\')');
01378 }
01379 foreach ($params as $key => $value) {
01380 if ($key != "service" && $key != "url") {
01381 phpCAS :: error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');
01382 }
01383 $parsedParams[$key] = $value;
01384 }
01385 }
01386 $PHPCAS_CLIENT->logout($parsedParams);
01387
01388 phpCAS :: traceEnd();
01389 }
01390
01395 public static function logoutWithRedirectService($service) {
01396 global $PHPCAS_CLIENT;
01397 phpCAS :: traceBegin();
01398 if (!is_object($PHPCAS_CLIENT)) {
01399 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01400 }
01401 if (!is_string($service)) {
01402 phpCAS :: error('type mismatched for parameter $service (should be `string\')');
01403 }
01404 $PHPCAS_CLIENT->logout(array (
01405 "service" => $service
01406 ));
01407
01408 phpCAS :: traceEnd();
01409 }
01410
01416 public static function logoutWithUrl($url) {
01417 trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
01418 global $PHPCAS_CLIENT;
01419 phpCAS :: traceBegin();
01420 if (!is_object($PHPCAS_CLIENT)) {
01421 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01422 }
01423 if (!is_string($url)) {
01424 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01425 }
01426 $PHPCAS_CLIENT->logout(array (
01427 "url" => $url
01428 ));
01429
01430 phpCAS :: traceEnd();
01431 }
01432
01439 public static function logoutWithRedirectServiceAndUrl($service, $url) {
01440 trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
01441 global $PHPCAS_CLIENT;
01442 phpCAS :: traceBegin();
01443 if (!is_object($PHPCAS_CLIENT)) {
01444 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01445 }
01446 if (!is_string($service)) {
01447 phpCAS :: error('type mismatched for parameter $service (should be `string\')');
01448 }
01449 if (!is_string($url)) {
01450 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01451 }
01452 $PHPCAS_CLIENT->logout(array (
01453 "service" => $service,
01454 "url" => $url
01455 ));
01456
01457 phpCAS :: traceEnd();
01458 }
01459
01466 public static function setFixedCallbackURL($url = '') {
01467 global $PHPCAS_CLIENT;
01468 phpCAS :: traceBegin();
01469 if (!is_object($PHPCAS_CLIENT)) {
01470 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01471 }
01472 if (!$PHPCAS_CLIENT->isProxy()) {
01473 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01474 }
01475 if (gettype($url) != 'string') {
01476 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01477 }
01478 $PHPCAS_CLIENT->setCallbackURL($url);
01479 phpCAS :: traceEnd();
01480 }
01481
01488 public static function setFixedServiceURL($url) {
01489 global $PHPCAS_CLIENT;
01490 phpCAS :: traceBegin();
01491 if (!is_object($PHPCAS_CLIENT)) {
01492 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01493 }
01494 if (gettype($url) != 'string') {
01495 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01496 }
01497 $PHPCAS_CLIENT->setURL($url);
01498 phpCAS :: traceEnd();
01499 }
01500
01504 public static function getServiceURL() {
01505 global $PHPCAS_CLIENT;
01506 if (!is_object($PHPCAS_CLIENT)) {
01507 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01508 }
01509 return ($PHPCAS_CLIENT->getURL());
01510 }
01511
01515 public static function retrievePT($target_service, & $err_code, & $err_msg) {
01516 global $PHPCAS_CLIENT;
01517 if (!is_object($PHPCAS_CLIENT)) {
01518 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01519 }
01520 if (gettype($target_service) != 'string') {
01521 phpCAS :: error('type mismatched for parameter $target_service(should be `string\')');
01522 }
01523 return ($PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
01524 }
01525
01531 public static function setCasServerCACert($cert) {
01532 global $PHPCAS_CLIENT;
01533 phpCAS :: traceBegin();
01534 if (!is_object($PHPCAS_CLIENT)) {
01535 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01536 }
01537 if (gettype($cert) != 'string') {
01538 phpCAS :: error('type mismatched for parameter $cert (should be `string\')');
01539 }
01540 $PHPCAS_CLIENT->setCasServerCACert($cert);
01541 phpCAS :: traceEnd();
01542 }
01543
01547 public static function setNoCasServerValidation() {
01548 global $PHPCAS_CLIENT;
01549 phpCAS :: traceBegin();
01550 if (!is_object($PHPCAS_CLIENT)) {
01551 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01552 }
01553 $PHPCAS_CLIENT->setNoCasServerValidation();
01554 phpCAS :: traceEnd();
01555 }
01556
01565 public static function setExtraCurlOption($key, $value) {
01566 global $PHPCAS_CLIENT;
01567 phpCAS :: traceBegin();
01568 if (!is_object($PHPCAS_CLIENT)) {
01569 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01570 }
01571 $PHPCAS_CLIENT->setExtraCurlOption($key, $value);
01572 phpCAS :: traceEnd();
01573 }
01574
01575
01586 public static function getProxies () {
01587 global $PHPCAS_CLIENT;
01588 if ( !is_object($PHPCAS_CLIENT) ) {
01589 phpCAS::error('this method should only be called after '.__CLASS__.'::client()');
01590 }
01591
01592 return($PHPCAS_CLIENT->getProxies());
01593 }
01594
01595 }
01596
01597
01598
01599
01600
01601
01602
01603
01611
01612
01613
01687
01688
01689
01726 ?>