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 if (!$_SERVER['REQUEST_URI']) {
00036 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
00037 }
00038
00039
00040
00041
00042 if (version_compare(PHP_VERSION, '5', '>=')) {
00043 require_once (dirname(__FILE__) . '/CAS/domxml-php4-to-php5.php');
00044 }
00045
00053
00054
00055
00056
00057
00058
00059
00060
00064 define('PHPCAS_VERSION', '1.1.1');
00065
00066
00067
00068
00077 define("CAS_VERSION_1_0", '1.0');
00081 define("CAS_VERSION_2_0", '2.0');
00082
00083
00084
00085
00086
00090 define("SAML_VERSION_1_1", 'S1');
00091
00095 define("SAML_XML_HEADER", '<?xml version="1.0" encoding="UTF-8"?>');
00096
00100 define("SAML_SOAP_ENV", '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/>');
00101
00105 define("SAML_SOAP_BODY", '<SOAP-ENV:Body>');
00106
00110 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">');
00111 define("SAMLP_REQUEST_CLOSE", '</samlp:Request>');
00112
00116 define("SAML_ASSERTION_ARTIFACT", '<samlp:AssertionArtifact>');
00117
00121 define("SAML_ASSERTION_ARTIFACT_CLOSE", '</samlp:AssertionArtifact>');
00122
00126 define("SAML_SOAP_BODY_CLOSE", '</SOAP-ENV:Body>');
00127
00131 define("SAML_SOAP_ENV_CLOSE", '</SOAP-ENV:Envelope>');
00132
00136 define("SAML_ATTRIBUTES", 'SAMLATTRIBS');
00137
00143
00144
00145
00149 define("CAS_PGT_STORAGE_FILE_DEFAULT_PATH", '/tmp');
00153 define("CAS_PGT_STORAGE_FILE_FORMAT_PLAIN", 'plain');
00157 define("CAS_PGT_STORAGE_FILE_FORMAT_XML", 'xml');
00161 define("CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT", CAS_PGT_STORAGE_FILE_FORMAT_PLAIN);
00162
00163
00164
00168 define("CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE", 'mysql');
00172 define("CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME", 'localhost');
00176 define("CAS_PGT_STORAGE_DB_DEFAULT_PORT", '');
00180 define("CAS_PGT_STORAGE_DB_DEFAULT_DATABASE", 'phpCAS');
00184 define("CAS_PGT_STORAGE_DB_DEFAULT_TABLE", 'pgt');
00185
00187
00188
00189
00198 define("PHPCAS_SERVICE_OK", 0);
00203 define("PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE", 1);
00208 define("PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE", 2);
00213 define("PHPCAS_SERVICE_PT_FAILURE", 3);
00217 define("PHPCAS_SERVICE_NOT AVAILABLE", 4);
00218
00220
00221
00222
00228 define("PHPCAS_LANG_ENGLISH", 'english');
00229 define("PHPCAS_LANG_FRENCH", 'french');
00230 define("PHPCAS_LANG_GREEK", 'greek');
00231 define("PHPCAS_LANG_GERMAN", 'german');
00232 define("PHPCAS_LANG_JAPANESE", 'japanese');
00233 define("PHPCAS_LANG_SPANISH", 'spanish');
00234 define("PHPCAS_LANG_CATALAN", 'catalan');
00235
00246 define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);
00247
00249
00250
00251
00260 define('DEFAULT_DEBUG_DIR', '/tmp/');
00261
00263
00264
00265
00276 $GLOBALS['PHPCAS_CLIENT'] = null;
00277
00284 $GLOBALS['PHPCAS_INIT_CALL'] = array (
00285 'done' => FALSE,
00286 'file' => '?',
00287 'line' => -1,
00288 'method' => '?'
00289 );
00290
00297 $GLOBALS['PHPCAS_AUTH_CHECK_CALL'] = array (
00298 'done' => FALSE,
00299 'file' => '?',
00300 'line' => -1,
00301 'method' => '?',
00302 'result' => FALSE
00303 );
00304
00310 $GLOBALS['PHPCAS_DEBUG'] = array (
00311 'filename' => FALSE,
00312 'indent' => 0,
00313 'unique_id' => ''
00314 );
00315
00318
00319
00320
00321
00322
00323 include_once (dirname(__FILE__) . '/CAS/client.php');
00324
00325
00326
00327
00328
00341 class phpCAS {
00342
00343
00344
00345
00346
00366 function client($server_version, $server_hostname, $server_port, $server_uri, $start_session = true) {
00367 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
00368
00369 phpCAS :: traceBegin();
00370 if (is_object($PHPCAS_CLIENT)) {
00371 phpCAS :: error($PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . $PHPCAS_INIT_CALL['file'] . ':' . $PHPCAS_INIT_CALL['line'] . ')');
00372 }
00373 if (gettype($server_version) != 'string') {
00374 phpCAS :: error('type mismatched for parameter $server_version (should be `string\')');
00375 }
00376 if (gettype($server_hostname) != 'string') {
00377 phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')');
00378 }
00379 if (gettype($server_port) != 'integer') {
00380 phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')');
00381 }
00382 if (gettype($server_uri) != 'string') {
00383 phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')');
00384 }
00385
00386
00387 $dbg = phpCAS :: backtrace();
00388 $PHPCAS_INIT_CALL = array (
00389 'done' => TRUE,
00390 'file' => $dbg[0]['file'],
00391 'line' => $dbg[0]['line'],
00392 'method' => __CLASS__ . '::' . __FUNCTION__
00393 );
00394
00395
00396 $PHPCAS_CLIENT = new CASClient($server_version, FALSE
00397 , $server_hostname, $server_port, $server_uri, $start_session);
00398 phpCAS :: traceEnd();
00399 }
00400
00415 function proxy($server_version, $server_hostname, $server_port, $server_uri, $start_session = true) {
00416 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
00417
00418 phpCAS :: traceBegin();
00419 if (is_object($PHPCAS_CLIENT)) {
00420 phpCAS :: error($PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . $PHPCAS_INIT_CALL['file'] . ':' . $PHPCAS_INIT_CALL['line'] . ')');
00421 }
00422 if (gettype($server_version) != 'string') {
00423 phpCAS :: error('type mismatched for parameter $server_version (should be `string\')');
00424 }
00425 if (gettype($server_hostname) != 'string') {
00426 phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')');
00427 }
00428 if (gettype($server_port) != 'integer') {
00429 phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')');
00430 }
00431 if (gettype($server_uri) != 'string') {
00432 phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')');
00433 }
00434
00435
00436 $dbg = phpCAS :: backtrace();
00437 $PHPCAS_INIT_CALL = array (
00438 'done' => TRUE,
00439 'file' => $dbg[0]['file'],
00440 'line' => $dbg[0]['line'],
00441 'method' => __CLASS__ . '::' . __FUNCTION__
00442 );
00443
00444
00445 $PHPCAS_CLIENT = new CASClient($server_version, TRUE
00446 , $server_hostname, $server_port, $server_uri, $start_session);
00447 phpCAS :: traceEnd();
00448 }
00449
00451
00452
00453
00454
00465 function setDebug($filename = '') {
00466 global $PHPCAS_DEBUG;
00467
00468 if ($filename != FALSE && gettype($filename) != 'string') {
00469 phpCAS :: error('type mismatched for parameter $dbg (should be FALSE or the name of the log file)');
00470 }
00471
00472 if (empty ($filename)) {
00473 if (preg_match('/^Win.*/', getenv('OS'))) {
00474 if (isset ($_ENV['TMP'])) {
00475 $debugDir = $_ENV['TMP'] . '/';
00476 } else
00477 if (isset ($_ENV['TEMP'])) {
00478 $debugDir = $_ENV['TEMP'] . '/';
00479 } else {
00480 $debugDir = '';
00481 }
00482 } else {
00483 $debugDir = DEFAULT_DEBUG_DIR;
00484 }
00485 $filename = $debugDir . 'phpCAS.log';
00486 }
00487
00488 if (empty ($PHPCAS_DEBUG['unique_id'])) {
00489 $PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4);
00490 }
00491
00492 $PHPCAS_DEBUG['filename'] = $filename;
00493
00494 phpCAS :: trace('START ******************');
00495 }
00496
00507 function backtrace() {
00508 if (function_exists('debug_backtrace')) {
00509 return debug_backtrace();
00510 } else {
00511
00512 return array ();
00513 }
00514 }
00515
00523 function log($str) {
00524 $indent_str = ".";
00525 global $PHPCAS_DEBUG;
00526
00527 if ($PHPCAS_DEBUG['filename']) {
00528 for ($i = 0; $i < $PHPCAS_DEBUG['indent']; $i++) {
00529 $indent_str .= '| ';
00530 }
00531 error_log($PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str . $str . "\n", 3, $PHPCAS_DEBUG['filename']);
00532 }
00533
00534 }
00535
00544 function error($msg) {
00545 $dbg = phpCAS :: backtrace();
00546 $function = '?';
00547 $file = '?';
00548 $line = '?';
00549 if (is_array($dbg)) {
00550 for ($i = 1; $i < sizeof($dbg); $i++) {
00551 if (is_array($dbg[$i])) {
00552 if ($dbg[$i]['class'] == __CLASS__) {
00553 $function = $dbg[$i]['function'];
00554 $file = $dbg[$i]['file'];
00555 $line = $dbg[$i]['line'];
00556 }
00557 }
00558 }
00559 }
00560 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";
00561 phpCAS :: trace($msg);
00562 phpCAS :: traceExit();
00563 exit ();
00564 }
00565
00569 function trace($str) {
00570 $dbg = phpCAS :: backtrace();
00571 phpCAS :: log($str . ' [' . basename($dbg[1]['file']) . ':' . $dbg[1]['line'] . ']');
00572 }
00573
00577 function traceBegin() {
00578 global $PHPCAS_DEBUG;
00579
00580 $dbg = phpCAS :: backtrace();
00581 $str = '=> ';
00582 if (!empty ($dbg[2]['class'])) {
00583 $str .= $dbg[2]['class'] . '::';
00584 }
00585 $str .= $dbg[2]['function'] . '(';
00586 if (is_array($dbg[2]['args'])) {
00587 foreach ($dbg[2]['args'] as $index => $arg) {
00588 if ($index != 0) {
00589 $str .= ', ';
00590 }
00591 $str .= str_replace("\n", "", var_export($arg, TRUE));
00592 }
00593 }
00594 $str .= ') [' . basename($dbg[2]['file']) . ':' . $dbg[2]['line'] . ']';
00595 phpCAS :: log($str);
00596 $PHPCAS_DEBUG['indent']++;
00597 }
00598
00604 function traceEnd($res = '') {
00605 global $PHPCAS_DEBUG;
00606
00607 $PHPCAS_DEBUG['indent']--;
00608 $dbg = phpCAS :: backtrace();
00609 $str = '';
00610 $str .= '<= ' . str_replace("\n", "", var_export($res, TRUE));
00611 phpCAS :: log($str);
00612 }
00613
00617 function traceExit() {
00618 global $PHPCAS_DEBUG;
00619
00620 phpCAS :: log('exit()');
00621 while ($PHPCAS_DEBUG['indent'] > 0) {
00622 phpCAS :: log('-');
00623 $PHPCAS_DEBUG['indent']--;
00624 }
00625 }
00626
00628
00629
00630
00644 function setLang($lang) {
00645 global $PHPCAS_CLIENT;
00646 if (!is_object($PHPCAS_CLIENT)) {
00647 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00648 }
00649 if (gettype($lang) != 'string') {
00650 phpCAS :: error('type mismatched for parameter $lang (should be `string\')');
00651 }
00652 $PHPCAS_CLIENT->setLang($lang);
00653 }
00654
00656
00657
00658
00669 function getVersion() {
00670 return PHPCAS_VERSION;
00671 }
00672
00674
00675
00676
00687 function setHTMLHeader($header) {
00688 global $PHPCAS_CLIENT;
00689 if (!is_object($PHPCAS_CLIENT)) {
00690 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00691 }
00692 if (gettype($header) != 'string') {
00693 phpCAS :: error('type mismatched for parameter $header (should be `string\')');
00694 }
00695 $PHPCAS_CLIENT->setHTMLHeader($header);
00696 }
00697
00703 function setHTMLFooter($footer) {
00704 global $PHPCAS_CLIENT;
00705 if (!is_object($PHPCAS_CLIENT)) {
00706 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00707 }
00708 if (gettype($footer) != 'string') {
00709 phpCAS :: error('type mismatched for parameter $footer (should be `string\')');
00710 }
00711 $PHPCAS_CLIENT->setHTMLFooter($footer);
00712 }
00713
00715
00716
00717
00730 function setPGTStorageFile($format = '', $path = '') {
00731 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00732
00733 phpCAS :: traceBegin();
00734 if (!is_object($PHPCAS_CLIENT)) {
00735 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00736 }
00737 if (!$PHPCAS_CLIENT->isProxy()) {
00738 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00739 }
00740 if ($PHPCAS_AUTH_CHECK_CALL['done']) {
00741 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'] . ')');
00742 }
00743 if (gettype($format) != 'string') {
00744 phpCAS :: error('type mismatched for parameter $format (should be `string\')');
00745 }
00746 if (gettype($path) != 'string') {
00747 phpCAS :: error('type mismatched for parameter $format (should be `string\')');
00748 }
00749 $PHPCAS_CLIENT->setPGTStorageFile($format, $path);
00750 phpCAS :: traceEnd();
00751 }
00752
00768 function setPGTStorageDB($user, $password, $database_type = '', $hostname = '', $port = 0, $database = '', $table = '') {
00769 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00770
00771 phpCAS :: traceBegin();
00772 if (!is_object($PHPCAS_CLIENT)) {
00773 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00774 }
00775 if (!$PHPCAS_CLIENT->isProxy()) {
00776 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00777 }
00778 if ($PHPCAS_AUTH_CHECK_CALL['done']) {
00779 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'] . ')');
00780 }
00781 if (gettype($user) != 'string') {
00782 phpCAS :: error('type mismatched for parameter $user (should be `string\')');
00783 }
00784 if (gettype($password) != 'string') {
00785 phpCAS :: error('type mismatched for parameter $password (should be `string\')');
00786 }
00787 if (gettype($database_type) != 'string') {
00788 phpCAS :: error('type mismatched for parameter $database_type (should be `string\')');
00789 }
00790 if (gettype($hostname) != 'string') {
00791 phpCAS :: error('type mismatched for parameter $hostname (should be `string\')');
00792 }
00793 if (gettype($port) != 'integer') {
00794 phpCAS :: error('type mismatched for parameter $port (should be `integer\')');
00795 }
00796 if (gettype($database) != 'string') {
00797 phpCAS :: error('type mismatched for parameter $database (should be `string\')');
00798 }
00799 if (gettype($table) != 'string') {
00800 phpCAS :: error('type mismatched for parameter $table (should be `string\')');
00801 }
00802 $PHPCAS_CLIENT->setPGTStorageDB($user, $password, $database_type, $hostname, $port, $database, $table);
00803 phpCAS :: traceEnd();
00804 }
00805
00807
00808
00809
00828 function serviceWeb($url, & $err_code, & $output) {
00829 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00830
00831 phpCAS :: traceBegin();
00832 if (!is_object($PHPCAS_CLIENT)) {
00833 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00834 }
00835 if (!$PHPCAS_CLIENT->isProxy()) {
00836 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00837 }
00838 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
00839 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()');
00840 }
00841 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
00842 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');
00843 }
00844 if (gettype($url) != 'string') {
00845 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
00846 }
00847
00848 $res = $PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
00849
00850 phpCAS :: traceEnd($res);
00851 return $res;
00852 }
00853
00871 function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt) {
00872 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00873
00874 phpCAS :: traceBegin();
00875 if (!is_object($PHPCAS_CLIENT)) {
00876 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00877 }
00878 if (!$PHPCAS_CLIENT->isProxy()) {
00879 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00880 }
00881 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
00882 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()');
00883 }
00884 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
00885 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');
00886 }
00887 if (gettype($url) != 'string') {
00888 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
00889 }
00890
00891 if (gettype($flags) != 'integer') {
00892 phpCAS :: error('type mismatched for parameter $flags (should be `integer\')');
00893 }
00894
00895 $res = $PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
00896
00897 phpCAS :: traceEnd($res);
00898 return $res;
00899 }
00900
00902
00903
00904
00918 function setCacheTimesForAuthRecheck($n) {
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 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00935
00936 phpCAS :: traceBegin();
00937 if (!is_object($PHPCAS_CLIENT)) {
00938 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00939 }
00940
00941 $auth = $PHPCAS_CLIENT->checkAuthentication();
00942
00943
00944 $dbg = phpCAS :: backtrace();
00945 $PHPCAS_AUTH_CHECK_CALL = array (
00946 'done' => TRUE,
00947 'file' => $dbg[0]['file'],
00948 'line' => $dbg[0]['line'],
00949 'method' => __CLASS__ . '::' . __FUNCTION__,
00950 'result' => $auth
00951 );
00952 phpCAS :: traceEnd($auth);
00953 return $auth;
00954 }
00955
00961 function forceAuthentication() {
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 (
00974 'done' => TRUE,
00975 'file' => $dbg[0]['file'],
00976 'line' => $dbg[0]['line'],
00977 'method' => __CLASS__ . '::' . __FUNCTION__,
00978 'result' => $auth
00979 );
00980
00981 if (!$auth) {
00982 phpCAS :: trace('user is not authenticated, redirecting to the CAS server');
00983 $PHPCAS_CLIENT->forceAuthentication();
00984 } else {
00985 phpCAS :: trace('no need to authenticate (user `' . phpCAS :: getUser() . '\' is already authenticated)');
00986 }
00987
00988 phpCAS :: traceEnd();
00989 return $auth;
00990 }
00991
00995 function renewAuthentication() {
00996 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00997
00998 phpCAS :: traceBegin();
00999 if (!is_object($PHPCAS_CLIENT)) {
01000 phpCAS :: error('this method should not be called before' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01001 }
01002
01003 // store where the authentication has been checked and the result
01004 $dbg = phpCAS :: backtrace();
01005 $PHPCAS_AUTH_CHECK_CALL = array (
01006 'done' => TRUE,
01007 'file' => $dbg[0]['file'],
01008 'line' => $dbg[0]['line'],
01009 'method' => __CLASS__ . '::' . __FUNCTION__,
01010 'result' => $auth
01011 );
01012
01013 $PHPCAS_CLIENT->renewAuthentication();
01014 phpCAS :: traceEnd();
01015 }
01016
01020 function authenticate() {
01021 phpCAS :: error('this method is deprecated. You should use ' . __CLASS__ . '::forceAuthentication() instead');
01022 }
01023
01030 function isAuthenticated() {
01031 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01032
01033 phpCAS :: traceBegin();
01034 if (!is_object($PHPCAS_CLIENT)) {
01035 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01036 }
01037
01038 // call the isAuthenticated method of the global $PHPCAS_CLIENT object
01039 $auth = $PHPCAS_CLIENT->isAuthenticated();
01040
01041 // store where the authentication has been checked and the result
01042 $dbg = phpCAS :: backtrace();
01043 $PHPCAS_AUTH_CHECK_CALL = array (
01044 'done' => TRUE,
01045 'file' => $dbg[0]['file'],
01046 'line' => $dbg[0]['line'],
01047 'method' => __CLASS__ . '::' . __FUNCTION__,
01048 'result' => $auth
01049 );
01050 phpCAS :: traceEnd($auth);
01051 return $auth;
01052 }
01053
01060 function isSessionAuthenticated() {
01061 global $PHPCAS_CLIENT;
01062 if (!is_object($PHPCAS_CLIENT)) {
01063 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01064 }
01065 return ($PHPCAS_CLIENT->isSessionAuthenticated());
01066 }
01067
01075 function getUser() {
01076 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01077 if (!is_object($PHPCAS_CLIENT)) {
01078 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01079 }
01080 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
01081 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01082 }
01083 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
01084 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');
01085 }
01086 return $PHPCAS_CLIENT->getUser();
01087 }
01088
01096 function getAttributes() {
01097 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01098 if (!is_object($PHPCAS_CLIENT)) {
01099 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01100 }
01101 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
01102 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01103 }
01104 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
01105 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');
01106 }
01107 return $PHPCAS_CLIENT->getAttributes();
01108 }
01112 function handleLogoutRequests($check_client = true, $allowed_clients = false) {
01113 global $PHPCAS_CLIENT;
01114 if (!is_object($PHPCAS_CLIENT)) {
01115 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01116 }
01117 return ($PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
01118 }
01119
01126 function getServerLoginURL() {
01127 global $PHPCAS_CLIENT;
01128 if (!is_object($PHPCAS_CLIENT)) {
01129 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01130 }
01131 return $PHPCAS_CLIENT->getServerLoginURL();
01132 }
01133
01139 function setServerLoginURL($url = '') {
01140 global $PHPCAS_CLIENT;
01141 phpCAS :: traceBegin();
01142 if (!is_object($PHPCAS_CLIENT)) {
01143 phpCAS :: error('this method should only be called after
01144 ' . __CLASS__ . '::client()');
01145 }
01146 if (gettype($url) != 'string') {
01147 phpCAS :: error('type mismatched for parameter $url (should be
01148 `string\')');
01149 }
01150 $PHPCAS_CLIENT->setServerLoginURL($url);
01151 phpCAS :: traceEnd();
01152 }
01153
01160 function setServerServiceValidateURL($url = '') {
01161 global $PHPCAS_CLIENT;
01162 phpCAS :: traceBegin();
01163 if (!is_object($PHPCAS_CLIENT)) {
01164 phpCAS :: error('this method should only be called after
01165 ' . __CLASS__ . '::client()');
01166 }
01167 if (gettype($url) != 'string') {
01168 phpCAS :: error('type mismatched for parameter $url (should be
01169 `string\')');
01170 }
01171 $PHPCAS_CLIENT->setServerServiceValidateURL($url);
01172 phpCAS :: traceEnd();
01173 }
01174
01181 function setServerProxyValidateURL($url = '') {
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 global $PHPCAS_CLIENT;
01203 phpCAS :: traceBegin();
01204 if (!is_object($PHPCAS_CLIENT)) {
01205 phpCAS :: error('this method should only be called after
01206 ' . __CLASS__ . '::client()');
01207 }
01208 if (gettype($url) != 'string') {
01209 phpCAS :: error('type mismatched for parameter $url (should be
01210 `string\')');
01211 }
01212 $PHPCAS_CLIENT->setServerSamlValidateURL($url);
01213 phpCAS :: traceEnd();
01214 }
01215
01222 function getServerLogoutURL() {
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->getServerLogoutURL();
01228 }
01229
01235 function setServerLogoutURL($url = '') {
01236 global $PHPCAS_CLIENT;
01237 phpCAS :: traceBegin();
01238 if (!is_object($PHPCAS_CLIENT)) {
01239 phpCAS :: error('this method should only be called after
01240 ' . __CLASS__ . '::client()');
01241 }
01242 if (gettype($url) != 'string') {
01243 phpCAS :: error('type mismatched for parameter $url (should be
01244 `string\')');
01245 }
01246 $PHPCAS_CLIENT->setServerLogoutURL($url);
01247 phpCAS :: traceEnd();
01248 }
01249
01255 function logout($params = "") {
01256 global $PHPCAS_CLIENT;
01257 phpCAS :: traceBegin();
01258 if (!is_object($PHPCAS_CLIENT)) {
01259 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01260 }
01261 $parsedParams = array ();
01262 if ($params != "") {
01263 if (is_string($params)) {
01264 phpCAS :: error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');
01265 }
01266 if (!is_array($params)) {
01267 phpCAS :: error('type mismatched for parameter $params (should be `array\')');
01268 }
01269 foreach ($params as $key => $value) {
01270 if ($key != "service" && $key != "url") {
01271 phpCAS :: error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');
01272 }
01273 $parsedParams[$key] = $value;
01274 }
01275 }
01276 $PHPCAS_CLIENT->logout($parsedParams);
01277
01278 phpCAS :: traceEnd();
01279 }
01280
01285 function logoutWithRedirectService($service) {
01286 global $PHPCAS_CLIENT;
01287 phpCAS :: traceBegin();
01288 if (!is_object($PHPCAS_CLIENT)) {
01289 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01290 }
01291 if (!is_string($service)) {
01292 phpCAS :: error('type mismatched for parameter $service (should be `string\')');
01293 }
01294 $PHPCAS_CLIENT->logout(array (
01295 "service" => $service
01296 ));
01297
01298 phpCAS :: traceEnd();
01299 }
01300
01305 function logoutWithUrl($url) {
01306 global $PHPCAS_CLIENT;
01307 phpCAS :: traceBegin();
01308 if (!is_object($PHPCAS_CLIENT)) {
01309 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01310 }
01311 if (!is_string($url)) {
01312 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01313 }
01314 $PHPCAS_CLIENT->logout(array (
01315 "url" => $url
01316 ));
01317
01318 phpCAS :: traceEnd();
01319 }
01320
01326 function logoutWithRedirectServiceAndUrl($service, $url) {
01327 global $PHPCAS_CLIENT;
01328 phpCAS :: traceBegin();
01329 if (!is_object($PHPCAS_CLIENT)) {
01330 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01331 }
01332 if (!is_string($service)) {
01333 phpCAS :: error('type mismatched for parameter $service (should be `string\')');
01334 }
01335 if (!is_string($url)) {
01336 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01337 }
01338 $PHPCAS_CLIENT->logout(array (
01339 "service" => $service,
01340 "url" => $url
01341 ));
01342
01343 phpCAS :: traceEnd();
01344 }
01345
01352 function setFixedCallbackURL($url = '') {
01353 global $PHPCAS_CLIENT;
01354 phpCAS :: traceBegin();
01355 if (!is_object($PHPCAS_CLIENT)) {
01356 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01357 }
01358 if (!$PHPCAS_CLIENT->isProxy()) {
01359 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01360 }
01361 if (gettype($url) != 'string') {
01362 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01363 }
01364 $PHPCAS_CLIENT->setCallbackURL($url);
01365 phpCAS :: traceEnd();
01366 }
01367
01374 function setFixedServiceURL($url) {
01375 global $PHPCAS_CLIENT;
01376 phpCAS :: traceBegin();
01377 if (!is_object($PHPCAS_CLIENT)) {
01378 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01379 }
01380 if (gettype($url) != 'string') {
01381 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01382 }
01383 $PHPCAS_CLIENT->setURL($url);
01384 phpCAS :: traceEnd();
01385 }
01386
01390 function getServiceURL() {
01391 global $PHPCAS_CLIENT;
01392 if (!is_object($PHPCAS_CLIENT)) {
01393 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01394 }
01395 return ($PHPCAS_CLIENT->getURL());
01396 }
01397
01401 function retrievePT($target_service, & $err_code, & $err_msg) {
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 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 (gettype($cert) != 'string') {
01424 phpCAS :: error('type mismatched for parameter $cert (should be `string\')');
01425 }
01426 $PHPCAS_CLIENT->setCasServerCert($cert);
01427 phpCAS :: traceEnd();
01428 }
01429
01435 function setCasServerCACert($cert) {
01436 global $PHPCAS_CLIENT;
01437 phpCAS :: traceBegin();
01438 if (!is_object($PHPCAS_CLIENT)) {
01439 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01440 }
01441 if (gettype($cert) != 'string') {
01442 phpCAS :: error('type mismatched for parameter $cert (should be `string\')');
01443 }
01444 $PHPCAS_CLIENT->setCasServerCACert($cert);
01445 phpCAS :: traceEnd();
01446 }
01447
01451 function setNoCasServerValidation() {
01452 global $PHPCAS_CLIENT;
01453 phpCAS :: traceBegin();
01454 if (!is_object($PHPCAS_CLIENT)) {
01455 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01456 }
01457 $PHPCAS_CLIENT->setNoCasServerValidation();
01458 phpCAS :: traceEnd();
01459 }
01460
01469 function setExtraCurlOption($key, $value) {
01470 global $PHPCAS_CLIENT;
01471 phpCAS :: traceBegin();
01472 if (!is_object($PHPCAS_CLIENT)) {
01473 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01474 }
01475 $PHPCAS_CLIENT->setExtraCurlOption($key, $value);
01476 phpCAS :: traceEnd();
01477 }
01478
01479 }
01480
01481
01482
01483
01484
01485
01486
01487
01495
01496
01497
01571
01572
01573
01610 ?>