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', E_USER_NOTICE);
00045 }
00046
00054
00055
00056
00057
00058
00059
00060
00061
00065 define('PHPCAS_VERSION', '1.2.2');
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');
00152
00153
00154
00163 define("PHPCAS_SERVICE_OK", 0);
00168 define("PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE", 1);
00173 define("PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE", 2);
00178 define("PHPCAS_SERVICE_PT_FAILURE", 3);
00182 define("PHPCAS_SERVICE_NOT_AVAILABLE", 4);
00183
00184
00185
00186
00190 define("PHPCAS_PROXIED_SERVICE_HTTP_GET", 'CAS_ProxiedService_Http_Get');
00194 define("PHPCAS_PROXIED_SERVICE_HTTP_POST", 'CAS_ProxiedService_Http_Post');
00198 define("PHPCAS_PROXIED_SERVICE_IMAP", 'CAS_ProxiedService_Imap');
00199
00200
00202
00203
00204
00210 define("PHPCAS_LANG_ENGLISH", 'english');
00211 define("PHPCAS_LANG_FRENCH", 'french');
00212 define("PHPCAS_LANG_GREEK", 'greek');
00213 define("PHPCAS_LANG_GERMAN", 'german');
00214 define("PHPCAS_LANG_JAPANESE", 'japanese');
00215 define("PHPCAS_LANG_SPANISH", 'spanish');
00216 define("PHPCAS_LANG_CATALAN", 'catalan');
00217
00228 define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);
00229
00231
00232
00233
00242 define('DEFAULT_DEBUG_DIR', '/tmp/');
00243
00245
00246
00247
00258 $GLOBALS['PHPCAS_CLIENT'] = null;
00259
00266 $GLOBALS['PHPCAS_INIT_CALL'] = array (
00267 'done' => FALSE,
00268 'file' => '?',
00269 'line' => -1,
00270 'method' => '?'
00271 );
00272
00279 $GLOBALS['PHPCAS_AUTH_CHECK_CALL'] = array (
00280 'done' => FALSE,
00281 'file' => '?',
00282 'line' => -1,
00283 'method' => '?',
00284 'result' => FALSE
00285 );
00286
00292 $GLOBALS['PHPCAS_DEBUG'] = array (
00293 'filename' => FALSE,
00294 'indent' => 0,
00295 'unique_id' => ''
00296 );
00297
00300
00301
00302
00303
00304
00305 include_once (dirname(__FILE__) . '/CAS/Client.php');
00306
00307
00308
00309
00310
00323 class phpCAS {
00324
00325
00326
00327
00328
00348 public static function client($server_version, $server_hostname, $server_port, $server_uri, $start_session = true) {
00349 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
00350
00351 phpCAS :: traceBegin();
00352 if (is_object($PHPCAS_CLIENT)) {
00353 phpCAS :: error($PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . $PHPCAS_INIT_CALL['file'] . ':' . $PHPCAS_INIT_CALL['line'] . ')');
00354 }
00355 if (gettype($server_version) != 'string') {
00356 phpCAS :: error('type mismatched for parameter $server_version (should be `string\')');
00357 }
00358 if (gettype($server_hostname) != 'string') {
00359 phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')');
00360 }
00361 if (gettype($server_port) != 'integer') {
00362 phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')');
00363 }
00364 if (gettype($server_uri) != 'string') {
00365 phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')');
00366 }
00367
00368
00369 $dbg = debug_backtrace();
00370 $PHPCAS_INIT_CALL = array (
00371 'done' => TRUE,
00372 'file' => $dbg[0]['file'],
00373 'line' => $dbg[0]['line'],
00374 'method' => __CLASS__ . '::' . __FUNCTION__
00375 );
00376
00377
00378 $PHPCAS_CLIENT = new CAS_Client($server_version, FALSE
00379 , $server_hostname, $server_port, $server_uri, $start_session);
00380 phpCAS :: traceEnd();
00381 }
00382
00397 public static function proxy($server_version, $server_hostname, $server_port, $server_uri, $start_session = true) {
00398 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
00399
00400 phpCAS :: traceBegin();
00401 if (is_object($PHPCAS_CLIENT)) {
00402 phpCAS :: error($PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . $PHPCAS_INIT_CALL['file'] . ':' . $PHPCAS_INIT_CALL['line'] . ')');
00403 }
00404 if (gettype($server_version) != 'string') {
00405 phpCAS :: error('type mismatched for parameter $server_version (should be `string\')');
00406 }
00407 if (gettype($server_hostname) != 'string') {
00408 phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')');
00409 }
00410 if (gettype($server_port) != 'integer') {
00411 phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')');
00412 }
00413 if (gettype($server_uri) != 'string') {
00414 phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')');
00415 }
00416
00417
00418 $dbg = debug_backtrace();
00419 $PHPCAS_INIT_CALL = array (
00420 'done' => TRUE,
00421 'file' => $dbg[0]['file'],
00422 'line' => $dbg[0]['line'],
00423 'method' => __CLASS__ . '::' . __FUNCTION__
00424 );
00425
00426
00427 $PHPCAS_CLIENT = new CAS_Client($server_version, TRUE
00428 , $server_hostname, $server_port, $server_uri, $start_session);
00429 phpCAS :: traceEnd();
00430 }
00431
00433
00434
00435
00436
00447 public static function setDebug($filename = '') {
00448 global $PHPCAS_DEBUG;
00449
00450 if ($filename != FALSE && gettype($filename) != 'string') {
00451 phpCAS :: error('type mismatched for parameter $dbg (should be FALSE or the name of the log file)');
00452 }
00453 if ($filename === FALSE){
00454 unset($PHPCAS_DEBUG['filename']);
00455 }else{
00456 if (empty ($filename)) {
00457 if (preg_match('/^Win.*/', getenv('OS'))) {
00458 if (isset ($_ENV['TMP'])) {
00459 $debugDir = $_ENV['TMP'] . '/';
00460 } else
00461 if (isset ($_ENV['TEMP'])) {
00462 $debugDir = $_ENV['TEMP'] . '/';
00463 } else {
00464 $debugDir = '';
00465 }
00466 } else {
00467 $debugDir = DEFAULT_DEBUG_DIR;
00468 }
00469 $filename = $debugDir . 'phpCAS.log';
00470 }
00471
00472 if (empty ($PHPCAS_DEBUG['unique_id'])) {
00473 $PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4);
00474 }
00475
00476 $PHPCAS_DEBUG['filename'] = $filename;
00477
00478 phpCAS :: trace('START phpCAS-' . PHPCAS_VERSION . ' ******************');
00479 }
00480 }
00481
00482
00490 public static function log($str) {
00491 $indent_str = ".";
00492 global $PHPCAS_DEBUG;
00493
00494 if ($PHPCAS_DEBUG['filename']) {
00495 for ($i = 0; $i < $PHPCAS_DEBUG['indent']; $i++) {
00496 $indent_str .= '| ';
00497 }
00498
00499 $str2 = str_replace("\n", "\n" . $PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str, $str);
00500 error_log($PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str . $str2 . "\n", 3, $PHPCAS_DEBUG['filename']);
00501 }
00502
00503 }
00504
00513 public static function error($msg) {
00514 $dbg = debug_backtrace();
00515 $function = '?';
00516 $file = '?';
00517 $line = '?';
00518 if (is_array($dbg)) {
00519 for ($i = 1; $i < sizeof($dbg); $i++) {
00520 if (is_array($dbg[$i]) && isset($dbg[$i]['class']) ) {
00521 if ($dbg[$i]['class'] == __CLASS__) {
00522 $function = $dbg[$i]['function'];
00523 $file = $dbg[$i]['file'];
00524 $line = $dbg[$i]['line'];
00525 }
00526 }
00527 }
00528 }
00529 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";
00530 phpCAS :: trace($msg);
00531 phpCAS :: traceExit();
00532 exit ();
00533 }
00534
00538 public static function trace($str) {
00539 $dbg = debug_backtrace();
00540 phpCAS :: log($str . ' [' . basename($dbg[0]['file']) . ':' . $dbg[0]['line'] . ']');
00541 }
00542
00546 public static function traceBegin() {
00547 global $PHPCAS_DEBUG;
00548
00549 $dbg = debug_backtrace();
00550 $str = '=> ';
00551 if (!empty ($dbg[1]['class'])) {
00552 $str .= $dbg[1]['class'] . '::';
00553 }
00554 $str .= $dbg[1]['function'] . '(';
00555 if (is_array($dbg[1]['args'])) {
00556 foreach ($dbg[1]['args'] as $index => $arg) {
00557 if ($index != 0) {
00558 $str .= ', ';
00559 }
00560 if(is_object($arg)){
00561 $str .= get_class($arg);
00562 }else{
00563 $str .= str_replace(array("\r\n", "\n", "\r"), "", var_export($arg, TRUE));
00564 }
00565 }
00566 }
00567 if (isset($dbg[1]['file']))
00568 $file = basename($dbg[1]['file']);
00569 else
00570 $file = 'unknown_file';
00571 if (isset($dbg[1]['line']))
00572 $line = $dbg[1]['line'];
00573 else
00574 $line = 'unknown_line';
00575 $str .= ') [' . $file . ':' . $line . ']';
00576 phpCAS :: log($str);
00577 $PHPCAS_DEBUG['indent']++;
00578 }
00579
00585 public static function traceEnd($res = '') {
00586 global $PHPCAS_DEBUG;
00587
00588 $PHPCAS_DEBUG['indent']--;
00589 $dbg = debug_backtrace();
00590 $str = '';
00591 if(is_object($res)){
00592 $str .= '<= ' . get_class($arg);
00593 }else{
00594 $str .= '<= ' . str_replace(array("\r\n", "\n", "\r"), "", var_export($res, TRUE));
00595 }
00596
00597 phpCAS :: log($str);
00598 }
00599
00603 public static function traceExit() {
00604 global $PHPCAS_DEBUG;
00605
00606 phpCAS :: log('exit()');
00607 while ($PHPCAS_DEBUG['indent'] > 0) {
00608 phpCAS :: log('-');
00609 $PHPCAS_DEBUG['indent']--;
00610 }
00611 }
00612
00614
00615
00616
00630 public static function setLang($lang) {
00631 global $PHPCAS_CLIENT;
00632 if (!is_object($PHPCAS_CLIENT)) {
00633 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00634 }
00635 if (gettype($lang) != 'string') {
00636 phpCAS :: error('type mismatched for parameter $lang (should be `string\')');
00637 }
00638 $PHPCAS_CLIENT->setLang($lang);
00639 }
00640
00642
00643
00644
00655 public static function getVersion() {
00656 return PHPCAS_VERSION;
00657 }
00658
00660
00661
00662
00673 public static function setHTMLHeader($header) {
00674 global $PHPCAS_CLIENT;
00675 if (!is_object($PHPCAS_CLIENT)) {
00676 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00677 }
00678 if (gettype($header) != 'string') {
00679 phpCAS :: error('type mismatched for parameter $header (should be `string\')');
00680 }
00681 $PHPCAS_CLIENT->setHTMLHeader($header);
00682 }
00683
00689 public static function setHTMLFooter($footer) {
00690 global $PHPCAS_CLIENT;
00691 if (!is_object($PHPCAS_CLIENT)) {
00692 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00693 }
00694 if (gettype($footer) != 'string') {
00695 phpCAS :: error('type mismatched for parameter $footer (should be `string\')');
00696 }
00697 $PHPCAS_CLIENT->setHTMLFooter($footer);
00698 }
00699
00701
00702
00703
00714 public static function setPGTStorage($storage) {
00715 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00716
00717 phpCAS :: traceBegin();
00718 if (!is_object($PHPCAS_CLIENT)) {
00719 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00720 }
00721 if (!$PHPCAS_CLIENT->isProxy()) {
00722 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00723 }
00724 if ($PHPCAS_AUTH_CHECK_CALL['done']) {
00725 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'] . ')');
00726 }
00727 if ( !($storage instanceof CAS_PGTStorage) ) {
00728 phpCAS :: error('type mismatched for parameter $storage (should be a CAS_PGTStorage `object\')');
00729 }
00730 $PHPCAS_CLIENT->setPGTStorage($storage);
00731 phpCAS :: traceEnd();
00732 }
00733
00744 public static function setPGTStorageDb($dsn_or_pdo, $username='', $password='', $table='', $driver_options=null) {
00745 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00746
00747 phpCAS :: traceBegin();
00748 if (!is_object($PHPCAS_CLIENT)) {
00749 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00750 }
00751 if (!$PHPCAS_CLIENT->isProxy()) {
00752 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00753 }
00754 if ($PHPCAS_AUTH_CHECK_CALL['done']) {
00755 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'] . ')');
00756 }
00757 if (gettype($username) != 'string') {
00758 phpCAS :: error('type mismatched for parameter $username (should be `string\')');
00759 }
00760 if (gettype($password) != 'string') {
00761 phpCAS :: error('type mismatched for parameter $password (should be `string\')');
00762 }
00763 if (gettype($table) != 'string') {
00764 phpCAS :: error('type mismatched for parameter $table (should be `string\')');
00765 }
00766 $PHPCAS_CLIENT->setPGTStorageDb($dsn_or_pdo, $username, $password, $table, $driver_options);
00767 phpCAS :: traceEnd();
00768 }
00769
00776 public static function setPGTStorageFile($format = '', $path = '') {
00777 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00778
00779 phpCAS :: traceBegin();
00780 if (!is_object($PHPCAS_CLIENT)) {
00781 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00782 }
00783 if (!$PHPCAS_CLIENT->isProxy()) {
00784 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00785 }
00786 if ($PHPCAS_AUTH_CHECK_CALL['done']) {
00787 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'] . ')');
00788 }
00789 if (gettype($format) != 'string') {
00790 phpCAS :: error('type mismatched for parameter $format (should be `string\')');
00791 }
00792 if (gettype($path) != 'string') {
00793 phpCAS :: error('type mismatched for parameter $format (should be `string\')');
00794 }
00795 $PHPCAS_CLIENT->setPGTStorageFile($path);
00796 phpCAS :: traceEnd();
00797 }
00798
00800
00801
00802
00820 public static function getProxiedService ($type) {
00821 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00822
00823 phpCAS :: traceBegin();
00824 if (!is_object($PHPCAS_CLIENT)) {
00825 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00826 }
00827 if (!$PHPCAS_CLIENT->isProxy()) {
00828 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00829 }
00830 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
00831 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()');
00832 }
00833 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
00834 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');
00835 }
00836 if (gettype($type) != 'string') {
00837 phpCAS :: error('type mismatched for parameter $type (should be `string\')');
00838 }
00839
00840 $res = $PHPCAS_CLIENT->getProxiedService($type);
00841
00842 phpCAS :: traceEnd();
00843 return $res;
00844 }
00845
00857 public static function initializeProxiedService (CAS_ProxiedService $proxiedService) {
00858 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00859
00860 if (!is_object($PHPCAS_CLIENT)) {
00861 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00862 }
00863 if (!$PHPCAS_CLIENT->isProxy()) {
00864 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00865 }
00866 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
00867 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()');
00868 }
00869 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
00870 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');
00871 }
00872
00873 $PHPCAS_CLIENT->initializeProxiedService($proxiedService);
00874 }
00875
00889 public static function serviceWeb($url, & $err_code, & $output) {
00890 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00891
00892 phpCAS :: traceBegin();
00893 if (!is_object($PHPCAS_CLIENT)) {
00894 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00895 }
00896 if (!$PHPCAS_CLIENT->isProxy()) {
00897 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00898 }
00899 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
00900 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()');
00901 }
00902 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
00903 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');
00904 }
00905 if (gettype($url) != 'string') {
00906 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
00907 }
00908
00909 $res = $PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
00910
00911 phpCAS :: traceEnd($res);
00912 return $res;
00913 }
00914
00932 public static function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt) {
00933 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
00934
00935 phpCAS :: traceBegin();
00936 if (!is_object($PHPCAS_CLIENT)) {
00937 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00938 }
00939 if (!$PHPCAS_CLIENT->isProxy()) {
00940 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
00941 }
00942 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
00943 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()');
00944 }
00945 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
00946 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');
00947 }
00948 if (gettype($url) != 'string') {
00949 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
00950 }
00951
00952 if (gettype($flags) != 'integer') {
00953 phpCAS :: error('type mismatched for parameter $flags (should be `integer\')');
00954 }
00955
00956 $res = $PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
00957
00958 phpCAS :: traceEnd($res);
00959 return $res;
00960 }
00961
00963
00964
00965
00979 public static function setCacheTimesForAuthRecheck($n) {
00980 global $PHPCAS_CLIENT;
00981 if (!is_object($PHPCAS_CLIENT)) {
00982 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
00983 }
00984 if (gettype($n) != 'integer') {
00985 phpCAS :: error('type mismatched for parameter $header (should be `string\')');
00986 }
00987 $PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
00988 }
00989
01008 public static function setPostAuthenticateCallback ($function, array $additionalArgs = array()) {
01009 global $PHPCAS_CLIENT;
01010 if (!is_object($PHPCAS_CLIENT)) {
01011 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01012 }
01013
01014 $PHPCAS_CLIENT->setPostAuthenticateCallback($function, $additionalArgs);
01015 }
01016
01030 public static function setSingleSignoutCallback ($function, array $additionalArgs = array()) {
01031 global $PHPCAS_CLIENT;
01032 if (!is_object($PHPCAS_CLIENT)) {
01033 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01034 }
01035
01036 $PHPCAS_CLIENT->setSingleSignoutCallback($function, $additionalArgs);
01037 }
01038
01045 public static function checkAuthentication() {
01046 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01047
01048 phpCAS :: traceBegin();
01049 if (!is_object($PHPCAS_CLIENT)) {
01050 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01051 }
01052
01053 $auth = $PHPCAS_CLIENT->checkAuthentication();
01054
01055
01056 $dbg = debug_backtrace();
01057 $PHPCAS_AUTH_CHECK_CALL = array (
01058 'done' => TRUE,
01059 'file' => $dbg[0]['file'],
01060 'line' => $dbg[0]['line'],
01061 'method' => __CLASS__ . '::' . __FUNCTION__,
01062 'result' => $auth
01063 );
01064 phpCAS :: traceEnd($auth);
01065 return $auth;
01066 }
01067
01073 public static function forceAuthentication() {
01074 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01075
01076 phpCAS :: traceBegin();
01077 if (!is_object($PHPCAS_CLIENT)) {
01078 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01079 }
01080
01081 $auth = $PHPCAS_CLIENT->forceAuthentication();
01082
01083
01084 $dbg = debug_backtrace();
01085 $PHPCAS_AUTH_CHECK_CALL = array (
01086 'done' => TRUE,
01087 'file' => $dbg[0]['file'],
01088 'line' => $dbg[0]['line'],
01089 'method' => __CLASS__ . '::' . __FUNCTION__,
01090 'result' => $auth
01091 );
01092
01093 if (!$auth) {
01094 phpCAS :: trace('user is not authenticated, redirecting to the CAS server');
01095 $PHPCAS_CLIENT->forceAuthentication();
01096 } else {
01097 phpCAS :: trace('no need to authenticate (user `' . phpCAS :: getUser() . '\' is already authenticated)');
01098 }
01099
01100 phpCAS :: traceEnd();
01101 return $auth;
01102 }
01103
01107 public static function renewAuthentication() {
01108 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01109
01110 phpCAS :: traceBegin();
01111 if (!is_object($PHPCAS_CLIENT)) {
01112 phpCAS :: error('this method should not be called before' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01113 }
01114 $auth = $PHPCAS_CLIENT->renewAuthentication();
01115 // store where the authentication has been checked and the result
01116 $dbg = debug_backtrace();
01117 $PHPCAS_AUTH_CHECK_CALL = array (
01118 'done' => TRUE,
01119 'file' => $dbg[0]['file'],
01120 'line' => $dbg[0]['line'],
01121 'method' => __CLASS__ . '::' . __FUNCTION__,
01122 'result' => $auth
01123 );
01124
01125 //$PHPCAS_CLIENT->renewAuthentication();
01126 phpCAS :: traceEnd();
01127 }
01128
01135 public static function isAuthenticated() {
01136 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01137
01138 phpCAS :: traceBegin();
01139 if (!is_object($PHPCAS_CLIENT)) {
01140 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01141 }
01142
01143 // call the isAuthenticated method of the global $PHPCAS_CLIENT object
01144 $auth = $PHPCAS_CLIENT->isAuthenticated();
01145
01146 // store where the authentication has been checked and the result
01147 $dbg = debug_backtrace();
01148 $PHPCAS_AUTH_CHECK_CALL = array (
01149 'done' => TRUE,
01150 'file' => $dbg[0]['file'],
01151 'line' => $dbg[0]['line'],
01152 'method' => __CLASS__ . '::' . __FUNCTION__,
01153 'result' => $auth
01154 );
01155 phpCAS :: traceEnd($auth);
01156 return $auth;
01157 }
01158
01165 public static function isSessionAuthenticated() {
01166 global $PHPCAS_CLIENT;
01167 if (!is_object($PHPCAS_CLIENT)) {
01168 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01169 }
01170 return ($PHPCAS_CLIENT->isSessionAuthenticated());
01171 }
01172
01180 public static function getUser() {
01181 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01182 if (!is_object($PHPCAS_CLIENT)) {
01183 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01184 }
01185 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
01186 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01187 }
01188 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
01189 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');
01190 }
01191 return $PHPCAS_CLIENT->getUser();
01192 }
01193
01202 public static function getAttributes() {
01203 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01204 if (!is_object($PHPCAS_CLIENT)) {
01205 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01206 }
01207 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
01208 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01209 }
01210 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
01211 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');
01212 }
01213 return $PHPCAS_CLIENT->getAttributes();
01214 }
01215
01224 public static function hasAttributes() {
01225 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01226 if (!is_object($PHPCAS_CLIENT)) {
01227 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01228 }
01229 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
01230 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01231 }
01232 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
01233 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');
01234 }
01235 return $PHPCAS_CLIENT->hasAttributes();
01236 }
01237
01247 public static function hasAttribute($key) {
01248 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01249 if (!is_object($PHPCAS_CLIENT)) {
01250 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01251 }
01252 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
01253 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01254 }
01255 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
01256 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');
01257 }
01258 return $PHPCAS_CLIENT->hasAttribute($key);
01259 }
01260
01270 public static function getAttribute($key) {
01271 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
01272 if (!is_object($PHPCAS_CLIENT)) {
01273 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01274 }
01275 if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
01276 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
01277 }
01278 if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
01279 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');
01280 }
01281 return $PHPCAS_CLIENT->getAttribute($key);
01282 }
01283
01287 public static function handleLogoutRequests($check_client = true, $allowed_clients = false) {
01288 global $PHPCAS_CLIENT;
01289 if (!is_object($PHPCAS_CLIENT)) {
01290 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01291 }
01292 return ($PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
01293 }
01294
01301 public static function getServerLoginURL() {
01302 global $PHPCAS_CLIENT;
01303 if (!is_object($PHPCAS_CLIENT)) {
01304 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01305 }
01306 return $PHPCAS_CLIENT->getServerLoginURL();
01307 }
01308
01314 public static function setServerLoginURL($url = '') {
01315 global $PHPCAS_CLIENT;
01316 phpCAS :: traceBegin();
01317 if (!is_object($PHPCAS_CLIENT)) {
01318 phpCAS :: error('this method should only be called after
01319 ' . __CLASS__ . '::client()');
01320 }
01321 if (gettype($url) != 'string') {
01322 phpCAS :: error('type mismatched for parameter $url (should be
01323 `string\')');
01324 }
01325 $PHPCAS_CLIENT->setServerLoginURL($url);
01326 phpCAS :: traceEnd();
01327 }
01328
01335 public static function setServerServiceValidateURL($url = '') {
01336 global $PHPCAS_CLIENT;
01337 phpCAS :: traceBegin();
01338 if (!is_object($PHPCAS_CLIENT)) {
01339 phpCAS :: error('this method should only be called after
01340 ' . __CLASS__ . '::client()');
01341 }
01342 if (gettype($url) != 'string') {
01343 phpCAS :: error('type mismatched for parameter $url (should be
01344 `string\')');
01345 }
01346 $PHPCAS_CLIENT->setServerServiceValidateURL($url);
01347 phpCAS :: traceEnd();
01348 }
01349
01356 public static function setServerProxyValidateURL($url = '') {
01357 global $PHPCAS_CLIENT;
01358 phpCAS :: traceBegin();
01359 if (!is_object($PHPCAS_CLIENT)) {
01360 phpCAS :: error('this method should only be called after
01361 ' . __CLASS__ . '::client()');
01362 }
01363 if (gettype($url) != 'string') {
01364 phpCAS :: error('type mismatched for parameter $url (should be
01365 `string\')');
01366 }
01367 $PHPCAS_CLIENT->setServerProxyValidateURL($url);
01368 phpCAS :: traceEnd();
01369 }
01370
01376 public static function setServerSamlValidateURL($url = '') {
01377 global $PHPCAS_CLIENT;
01378 phpCAS :: traceBegin();
01379 if (!is_object($PHPCAS_CLIENT)) {
01380 phpCAS :: error('this method should only be called after
01381 ' . __CLASS__ . '::client()');
01382 }
01383 if (gettype($url) != 'string') {
01384 phpCAS :: error('type mismatched for parameter $url (should be
01385 `string\')');
01386 }
01387 $PHPCAS_CLIENT->setServerSamlValidateURL($url);
01388 phpCAS :: traceEnd();
01389 }
01390
01397 public static function getServerLogoutURL() {
01398 global $PHPCAS_CLIENT;
01399 if (!is_object($PHPCAS_CLIENT)) {
01400 phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
01401 }
01402 return $PHPCAS_CLIENT->getServerLogoutURL();
01403 }
01404
01410 public static function setServerLogoutURL($url = '') {
01411 global $PHPCAS_CLIENT;
01412 phpCAS :: traceBegin();
01413 if (!is_object($PHPCAS_CLIENT)) {
01414 phpCAS :: error('this method should only be called after
01415 ' . __CLASS__ . '::client()');
01416 }
01417 if (gettype($url) != 'string') {
01418 phpCAS :: error('type mismatched for parameter $url (should be
01419 `string\')');
01420 }
01421 $PHPCAS_CLIENT->setServerLogoutURL($url);
01422 phpCAS :: traceEnd();
01423 }
01424
01430 public static function logout($params = "") {
01431 global $PHPCAS_CLIENT;
01432 phpCAS :: traceBegin();
01433 if (!is_object($PHPCAS_CLIENT)) {
01434 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01435 }
01436 $parsedParams = array ();
01437 if ($params != "") {
01438 if (is_string($params)) {
01439 phpCAS :: error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');
01440 }
01441 if (!is_array($params)) {
01442 phpCAS :: error('type mismatched for parameter $params (should be `array\')');
01443 }
01444 foreach ($params as $key => $value) {
01445 if ($key != "service" && $key != "url") {
01446 phpCAS :: error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');
01447 }
01448 $parsedParams[$key] = $value;
01449 }
01450 }
01451 $PHPCAS_CLIENT->logout($parsedParams);
01452
01453 phpCAS :: traceEnd();
01454 }
01455
01460 public static function logoutWithRedirectService($service) {
01461 global $PHPCAS_CLIENT;
01462 phpCAS :: traceBegin();
01463 if (!is_object($PHPCAS_CLIENT)) {
01464 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01465 }
01466 if (!is_string($service)) {
01467 phpCAS :: error('type mismatched for parameter $service (should be `string\')');
01468 }
01469 $PHPCAS_CLIENT->logout(array (
01470 "service" => $service
01471 ));
01472
01473 phpCAS :: traceEnd();
01474 }
01475
01481 public static function logoutWithUrl($url) {
01482 trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
01483 global $PHPCAS_CLIENT;
01484 phpCAS :: traceBegin();
01485 if (!is_object($PHPCAS_CLIENT)) {
01486 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01487 }
01488 if (!is_string($url)) {
01489 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01490 }
01491 $PHPCAS_CLIENT->logout(array (
01492 "url" => $url
01493 ));
01494
01495 phpCAS :: traceEnd();
01496 }
01497
01504 public static function logoutWithRedirectServiceAndUrl($service, $url) {
01505 trigger_error('Function deprecated for cas servers >= 3.3.5.1', E_USER_DEPRECATED);
01506 global $PHPCAS_CLIENT;
01507 phpCAS :: traceBegin();
01508 if (!is_object($PHPCAS_CLIENT)) {
01509 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01510 }
01511 if (!is_string($service)) {
01512 phpCAS :: error('type mismatched for parameter $service (should be `string\')');
01513 }
01514 if (!is_string($url)) {
01515 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01516 }
01517 $PHPCAS_CLIENT->logout(array (
01518 "service" => $service,
01519 "url" => $url
01520 ));
01521
01522 phpCAS :: traceEnd();
01523 }
01524
01531 public static function setFixedCallbackURL($url = '') {
01532 global $PHPCAS_CLIENT;
01533 phpCAS :: traceBegin();
01534 if (!is_object($PHPCAS_CLIENT)) {
01535 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01536 }
01537 if (!$PHPCAS_CLIENT->isProxy()) {
01538 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01539 }
01540 if (gettype($url) != 'string') {
01541 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01542 }
01543 $PHPCAS_CLIENT->setCallbackURL($url);
01544 phpCAS :: traceEnd();
01545 }
01546
01553 public static function setFixedServiceURL($url) {
01554 global $PHPCAS_CLIENT;
01555 phpCAS :: traceBegin();
01556 if (!is_object($PHPCAS_CLIENT)) {
01557 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01558 }
01559 if (gettype($url) != 'string') {
01560 phpCAS :: error('type mismatched for parameter $url (should be `string\')');
01561 }
01562 $PHPCAS_CLIENT->setURL($url);
01563 phpCAS :: traceEnd();
01564 }
01565
01569 public static function getServiceURL() {
01570 global $PHPCAS_CLIENT;
01571 if (!is_object($PHPCAS_CLIENT)) {
01572 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01573 }
01574 return ($PHPCAS_CLIENT->getURL());
01575 }
01576
01580 public static function retrievePT($target_service, & $err_code, & $err_msg) {
01581 global $PHPCAS_CLIENT;
01582 if (!is_object($PHPCAS_CLIENT)) {
01583 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()');
01584 }
01585 if (gettype($target_service) != 'string') {
01586 phpCAS :: error('type mismatched for parameter $target_service(should be `string\')');
01587 }
01588 return ($PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
01589 }
01590
01596 public static function setCasServerCACert($cert) {
01597 global $PHPCAS_CLIENT;
01598 phpCAS :: traceBegin();
01599 if (!is_object($PHPCAS_CLIENT)) {
01600 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01601 }
01602 if (gettype($cert) != 'string') {
01603 phpCAS :: error('type mismatched for parameter $cert (should be `string\')');
01604 }
01605 $PHPCAS_CLIENT->setCasServerCACert($cert);
01606 phpCAS :: traceEnd();
01607 }
01608
01612 public static function setNoCasServerValidation() {
01613 global $PHPCAS_CLIENT;
01614 phpCAS :: traceBegin();
01615 if (!is_object($PHPCAS_CLIENT)) {
01616 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01617 }
01618 $PHPCAS_CLIENT->setNoCasServerValidation();
01619 phpCAS :: traceEnd();
01620 }
01621
01622
01629 public static function setNoClearTicketsFromUrl() {
01630 global $PHPCAS_CLIENT;
01631 phpCAS :: traceBegin();
01632 if (!is_object($PHPCAS_CLIENT)) {
01633 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01634 }
01635 $PHPCAS_CLIENT->setNoClearTicketsFromUrl();
01636 phpCAS :: traceEnd();
01637 }
01638
01647 public static function setExtraCurlOption($key, $value) {
01648 global $PHPCAS_CLIENT;
01649 phpCAS :: traceBegin();
01650 if (!is_object($PHPCAS_CLIENT)) {
01651 phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
01652 }
01653 $PHPCAS_CLIENT->setExtraCurlOption($key, $value);
01654 phpCAS :: traceEnd();
01655 }
01656
01657
01668 public static function getProxies () {
01669 global $PHPCAS_CLIENT;
01670 if ( !is_object($PHPCAS_CLIENT) ) {
01671 phpCAS::error('this method should only be called after '.__CLASS__.'::client()');
01672 }
01673
01674 return($PHPCAS_CLIENT->getProxies());
01675 }
01676
01677 }
01678
01679
01680
01681
01682
01683
01684
01685
01693
01694
01695
01778
01779
01780
01826 ?>