3 // commented in 0.4.22-RC2 for Sylvain Derosiaux
\r
4 // error_reporting(E_ALL ^ E_NOTICE);
\r
7 // hack by Vangelis Haniotakis to handle the absence of $_SERVER['REQUEST_URI'] in IIS
\r
9 if (!$_SERVER['REQUEST_URI']) {
\r
10 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];
\r
14 // another one by Vangelis Haniotakis also to make phpCAS work with PHP5
\r
16 if (version_compare(PHP_VERSION,'5','>=')) {
\r
17 require_once(dirname(__FILE__).'/CAS/domxml-php4-to-php5.php');
\r
22 * Interface class of the phpCAS library
\r
27 // ########################################################################
\r
29 // ########################################################################
\r
31 // ------------------------------------------------------------------------
\r
33 // ------------------------------------------------------------------------
\r
36 * phpCAS version. accessible for the user by phpCAS::getVersion().
\r
38 define('PHPCAS_VERSION','1.1.0RC6');
\r
40 // ------------------------------------------------------------------------
\r
42 // ------------------------------------------------------------------------
\r
44 * @addtogroup public
\r
51 define("CAS_VERSION_1_0",'1.0');
\r
55 define("CAS_VERSION_2_0",'2.0');
\r
57 // ------------------------------------------------------------------------
\r
59 // ------------------------------------------------------------------------
\r
64 define("SAML_VERSION_1_1", 'S1');
\r
67 * XML header for SAML POST
\r
69 define("SAML_XML_HEADER", '<?xml version="1.0" encoding="UTF-8"?>');
\r
72 * SOAP envelope for SAML POST
\r
74 define ("SAML_SOAP_ENV", '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/>');
\r
77 * SOAP body for SAML POST
\r
79 define ("SAML_SOAP_BODY", '<SOAP-ENV:Body>');
\r
84 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">');
\r
85 define ("SAMLP_REQUEST_CLOSE", '</samlp:Request>');
\r
88 * SAMLP artifact tag (for the ticket)
\r
90 define ("SAML_ASSERTION_ARTIFACT", '<samlp:AssertionArtifact>');
\r
95 define ("SAML_ASSERTION_ARTIFACT_CLOSE", '</samlp:AssertionArtifact>');
\r
100 define ("SAML_SOAP_BODY_CLOSE", '</SOAP-ENV:Body>');
\r
103 * SOAP envelope close
\r
105 define ("SAML_SOAP_ENV_CLOSE", '</SOAP-ENV:Envelope>');
\r
110 define("SAML_ATTRIBUTES", 'SAMLATTRIBS');
\r
116 * @addtogroup publicPGTStorage
\r
119 // ------------------------------------------------------------------------
\r
120 // FILE PGT STORAGE
\r
121 // ------------------------------------------------------------------------
\r
123 * Default path used when storing PGT's to file
\r
125 define("CAS_PGT_STORAGE_FILE_DEFAULT_PATH",'/tmp');
\r
127 * phpCAS::setPGTStorageFile()'s 2nd parameter to write plain text files
\r
129 define("CAS_PGT_STORAGE_FILE_FORMAT_PLAIN",'plain');
\r
131 * phpCAS::setPGTStorageFile()'s 2nd parameter to write xml files
\r
133 define("CAS_PGT_STORAGE_FILE_FORMAT_XML",'xml');
\r
135 * Default format used when storing PGT's to file
\r
137 define("CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT",CAS_PGT_STORAGE_FILE_FORMAT_PLAIN);
\r
138 // ------------------------------------------------------------------------
\r
139 // DATABASE PGT STORAGE
\r
140 // ------------------------------------------------------------------------
\r
142 * default database type when storing PGT's to database
\r
144 define("CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE",'mysql');
\r
146 * default host when storing PGT's to database
\r
148 define("CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME",'localhost');
\r
150 * default port when storing PGT's to database
\r
152 define("CAS_PGT_STORAGE_DB_DEFAULT_PORT",'');
\r
154 * default database when storing PGT's to database
\r
156 define("CAS_PGT_STORAGE_DB_DEFAULT_DATABASE",'phpCAS');
\r
158 * default table when storing PGT's to database
\r
160 define("CAS_PGT_STORAGE_DB_DEFAULT_TABLE",'pgt');
\r
163 // ------------------------------------------------------------------------
\r
164 // SERVICE ACCESS ERRORS
\r
165 // ------------------------------------------------------------------------
\r
167 * @addtogroup publicServices
\r
172 * phpCAS::service() error code on success
\r
174 define("PHPCAS_SERVICE_OK",0);
\r
176 * phpCAS::service() error code when the PT could not retrieve because
\r
177 * the CAS server did not respond.
\r
179 define("PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE",1);
\r
181 * phpCAS::service() error code when the PT could not retrieve because
\r
182 * the response of the CAS server was ill-formed.
\r
184 define("PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE",2);
\r
186 * phpCAS::service() error code when the PT could not retrieve because
\r
187 * the CAS server did not want to.
\r
189 define("PHPCAS_SERVICE_PT_FAILURE",3);
\r
191 * phpCAS::service() error code when the service was not available.
\r
193 define("PHPCAS_SERVICE_NOT AVAILABLE",4);
\r
196 // ------------------------------------------------------------------------
\r
198 // ------------------------------------------------------------------------
\r
200 * @addtogroup publicLang
\r
204 define("PHPCAS_LANG_ENGLISH", 'english');
\r
205 define("PHPCAS_LANG_FRENCH", 'french');
\r
206 define("PHPCAS_LANG_GREEK", 'greek');
\r
207 define("PHPCAS_LANG_GERMAN", 'german');
\r
208 define("PHPCAS_LANG_JAPANESE", 'japanese');
\r
209 define("PHPCAS_LANG_SPANISH", 'spanish');
\r
210 define("PHPCAS_LANG_CATALAN", 'catalan');
\r
215 * @addtogroup internalLang
\r
220 * phpCAS default language (when phpCAS::setLang() is not used)
\r
222 define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);
\r
225 // ------------------------------------------------------------------------
\r
227 // ------------------------------------------------------------------------
\r
229 * @addtogroup publicDebug
\r
234 * The default directory for the debug file under Unix.
\r
236 define('DEFAULT_DEBUG_DIR','/tmp/');
\r
239 // ------------------------------------------------------------------------
\r
241 // ------------------------------------------------------------------------
\r
243 * @addtogroup internalMisc
\r
248 * This global variable is used by the interface class phpCAS.
\r
252 $GLOBALS['PHPCAS_CLIENT'] = null;
\r
255 * This global variable is used to store where the initializer is called from
\r
256 * (to print a comprehensive error in case of multiple calls).
\r
260 $GLOBALS['PHPCAS_INIT_CALL'] = array('done' => FALSE,
\r
266 * This global variable is used to store where the method checking
\r
267 * the authentication is called from (to print comprehensive errors)
\r
271 $GLOBALS['PHPCAS_AUTH_CHECK_CALL'] = array('done' => FALSE,
\r
275 'result' => FALSE);
\r
278 * This global variable is used to store phpCAS debug mode.
\r
282 $GLOBALS['PHPCAS_DEBUG'] = array('filename' => FALSE,
\r
284 'unique_id' => '');
\r
288 // ########################################################################
\r
290 // ########################################################################
\r
292 // include client class
\r
293 include_once(dirname(__FILE__).'/CAS/client.php');
\r
295 // ########################################################################
\r
297 // ########################################################################
\r
301 * The phpCAS class is a simple container for the phpCAS library. It provides CAS
\r
302 * authentication for web applications written in PHP.
\r
305 * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
\r
307 * \internal All its methods access the same object ($PHPCAS_CLIENT, declared
\r
308 * at the end of CAS/client.php).
\r
316 // ########################################################################
\r
318 // ########################################################################
\r
321 * @addtogroup publicInit
\r
326 * phpCAS client initializer.
\r
327 * @note Only one of the phpCAS::client() and phpCAS::proxy functions should be
\r
328 * called, only once, and before all other methods (except phpCAS::getVersion()
\r
329 * and phpCAS::setDebug()).
\r
331 * @param $server_version the version of the CAS server
\r
332 * @param $server_hostname the hostname of the CAS server
\r
333 * @param $server_port the port the CAS server is running on
\r
334 * @param $server_uri the URI the CAS server is responding on
\r
335 * @param $start_session Have phpCAS start PHP sessions (default true)
\r
337 * @return a newly created CASClient object
\r
339 function client($server_version,
\r
343 $start_session = true)
\r
345 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
\r
347 phpCAS::traceBegin();
\r
348 if ( is_object($PHPCAS_CLIENT) ) {
\r
349 phpCAS::error($PHPCAS_INIT_CALL['method'].'() has already been called (at '.$PHPCAS_INIT_CALL['file'].':'.$PHPCAS_INIT_CALL['line'].')');
\r
351 if ( gettype($server_version) != 'string' ) {
\r
352 phpCAS::error('type mismatched for parameter $server_version (should be `string\')');
\r
354 if ( gettype($server_hostname) != 'string' ) {
\r
355 phpCAS::error('type mismatched for parameter $server_hostname (should be `string\')');
\r
357 if ( gettype($server_port) != 'integer' ) {
\r
358 phpCAS::error('type mismatched for parameter $server_port (should be `integer\')');
\r
360 if ( gettype($server_uri) != 'string' ) {
\r
361 phpCAS::error('type mismatched for parameter $server_uri (should be `string\')');
\r
364 // store where the initializer is called from
\r
365 $dbg = phpCAS::backtrace();
\r
366 $PHPCAS_INIT_CALL = array('done' => TRUE,
\r
367 'file' => $dbg[0]['file'],
\r
368 'line' => $dbg[0]['line'],
\r
369 'method' => __CLASS__.'::'.__FUNCTION__);
\r
371 // initialize the global object $PHPCAS_CLIENT
\r
372 $PHPCAS_CLIENT = new CASClient($server_version,FALSE/*proxy*/,$server_hostname,$server_port,$server_uri,$start_session);
\r
373 phpCAS::traceEnd();
\r
377 * phpCAS proxy initializer.
\r
378 * @note Only one of the phpCAS::client() and phpCAS::proxy functions should be
\r
379 * called, only once, and before all other methods (except phpCAS::getVersion()
\r
380 * and phpCAS::setDebug()).
\r
382 * @param $server_version the version of the CAS server
\r
383 * @param $server_hostname the hostname of the CAS server
\r
384 * @param $server_port the port the CAS server is running on
\r
385 * @param $server_uri the URI the CAS server is responding on
\r
386 * @param $start_session Have phpCAS start PHP sessions (default true)
\r
388 * @return a newly created CASClient object
\r
390 function proxy($server_version,
\r
394 $start_session = true)
\r
396 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
\r
398 phpCAS::traceBegin();
\r
399 if ( is_object($PHPCAS_CLIENT) ) {
\r
400 phpCAS::error($PHPCAS_INIT_CALL['method'].'() has already been called (at '.$PHPCAS_INIT_CALL['file'].':'.$PHPCAS_INIT_CALL['line'].')');
\r
402 if ( gettype($server_version) != 'string' ) {
\r
403 phpCAS::error('type mismatched for parameter $server_version (should be `string\')');
\r
405 if ( gettype($server_hostname) != 'string' ) {
\r
406 phpCAS::error('type mismatched for parameter $server_hostname (should be `string\')');
\r
408 if ( gettype($server_port) != 'integer' ) {
\r
409 phpCAS::error('type mismatched for parameter $server_port (should be `integer\')');
\r
411 if ( gettype($server_uri) != 'string' ) {
\r
412 phpCAS::error('type mismatched for parameter $server_uri (should be `string\')');
\r
415 // store where the initialzer is called from
\r
416 $dbg = phpCAS::backtrace();
\r
417 $PHPCAS_INIT_CALL = array('done' => TRUE,
\r
418 'file' => $dbg[0]['file'],
\r
419 'line' => $dbg[0]['line'],
\r
420 'method' => __CLASS__.'::'.__FUNCTION__);
\r
422 // initialize the global object $PHPCAS_CLIENT
\r
423 $PHPCAS_CLIENT = new CASClient($server_version,TRUE/*proxy*/,$server_hostname,$server_port,$server_uri,$start_session);
\r
424 phpCAS::traceEnd();
\r
428 // ########################################################################
\r
430 // ########################################################################
\r
433 * @addtogroup publicDebug
\r
438 * Set/unset debug mode
\r
440 * @param $filename the name of the file used for logging, or FALSE to stop debugging.
\r
442 function setDebug($filename='')
\r
444 global $PHPCAS_DEBUG;
\r
446 if ( $filename != FALSE && gettype($filename) != 'string' ) {
\r
447 phpCAS::error('type mismatched for parameter $dbg (should be FALSE or the name of the log file)');
\r
450 if ( empty($filename) ) {
\r
451 if ( preg_match('/^Win.*/',getenv('OS')) ) {
\r
452 if ( isset($_ENV['TMP']) ) {
\r
453 $debugDir = $_ENV['TMP'].'/';
\r
454 } else if ( isset($_ENV['TEMP']) ) {
\r
455 $debugDir = $_ENV['TEMP'].'/';
\r
460 $debugDir = DEFAULT_DEBUG_DIR;
\r
462 $filename = $debugDir . 'phpCAS.log';
\r
465 if ( empty($PHPCAS_DEBUG['unique_id']) ) {
\r
466 $PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))),0,4);
\r
469 $PHPCAS_DEBUG['filename'] = $filename;
\r
471 phpCAS::trace('START ******************');
\r
476 * @addtogroup internalDebug
\r
481 * This method is a wrapper for debug_backtrace() that is not available
\r
482 * in all PHP versions (>= 4.3.0 only)
\r
484 function backtrace()
\r
486 if ( function_exists('debug_backtrace') ) {
\r
487 return debug_backtrace();
\r
489 // poor man's hack ... but it does work ...
\r
495 * Logs a string in debug mode.
\r
497 * @param $str the string to write
\r
504 global $PHPCAS_DEBUG;
\r
506 if ( $PHPCAS_DEBUG['filename'] ) {
\r
507 for ($i=0;$i<$PHPCAS_DEBUG['indent'];$i++) {
\r
508 $indent_str .= '| ';
\r
510 error_log($PHPCAS_DEBUG['unique_id'].' '.$indent_str.$str."\n",3,$PHPCAS_DEBUG['filename']);
\r
516 * This method is used by interface methods to print an error and where the function
\r
517 * was originally called from.
\r
519 * @param $msg the message to print
\r
523 function error($msg)
\r
525 $dbg = phpCAS::backtrace();
\r
529 if ( is_array($dbg) ) {
\r
530 for ( $i=1; $i<sizeof($dbg); $i++) {
\r
531 if ( is_array($dbg[$i]) ) {
\r
532 if ( $dbg[$i]['class'] == __CLASS__ ) {
\r
533 $function = $dbg[$i]['function'];
\r
534 $file = $dbg[$i]['file'];
\r
535 $line = $dbg[$i]['line'];
\r
540 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";
\r
541 phpCAS::trace($msg);
\r
542 phpCAS::traceExit();
\r
547 * This method is used to log something in debug mode.
\r
549 function trace($str)
\r
551 $dbg = phpCAS::backtrace();
\r
552 phpCAS::log($str.' ['.basename($dbg[1]['file']).':'.$dbg[1]['line'].']');
\r
556 * This method is used to indicate the start of the execution of a function in debug mode.
\r
558 function traceBegin()
\r
560 global $PHPCAS_DEBUG;
\r
562 $dbg = phpCAS::backtrace();
\r
564 if ( !empty($dbg[2]['class']) ) {
\r
565 $str .= $dbg[2]['class'].'::';
\r
567 $str .= $dbg[2]['function'].'(';
\r
568 if ( is_array($dbg[2]['args']) ) {
\r
569 foreach ($dbg[2]['args'] as $index => $arg) {
\r
570 if ( $index != 0 ) {
\r
573 $str .= str_replace("\n","",var_export($arg,TRUE));
\r
576 $str .= ') ['.basename($dbg[2]['file']).':'.$dbg[2]['line'].']';
\r
578 $PHPCAS_DEBUG['indent'] ++;
\r
582 * This method is used to indicate the end of the execution of a function in debug mode.
\r
584 * @param $res the result of the function
\r
586 function traceEnd($res='')
\r
588 global $PHPCAS_DEBUG;
\r
590 $PHPCAS_DEBUG['indent'] --;
\r
591 $dbg = phpCAS::backtrace();
\r
593 $str .= '<= '.str_replace("\n","",var_export($res,TRUE));
\r
598 * This method is used to indicate the end of the execution of the program
\r
600 function traceExit()
\r
602 global $PHPCAS_DEBUG;
\r
604 phpCAS::log('exit()');
\r
605 while ( $PHPCAS_DEBUG['indent'] > 0 ) {
\r
607 $PHPCAS_DEBUG['indent'] --;
\r
612 // ########################################################################
\r
613 // INTERNATIONALIZATION
\r
614 // ########################################################################
\r
616 * @addtogroup publicLang
\r
621 * This method is used to set the language used by phpCAS.
\r
622 * @note Can be called only once.
\r
624 * @param $lang a string representing the language.
\r
626 * @sa PHPCAS_LANG_FRENCH, PHPCAS_LANG_ENGLISH
\r
628 function setLang($lang)
\r
630 global $PHPCAS_CLIENT;
\r
631 if ( !is_object($PHPCAS_CLIENT) ) {
\r
632 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
634 if ( gettype($lang) != 'string' ) {
\r
635 phpCAS::error('type mismatched for parameter $lang (should be `string\')');
\r
637 $PHPCAS_CLIENT->setLang($lang);
\r
641 // ########################################################################
\r
643 // ########################################################################
\r
645 * @addtogroup public
\r
650 * This method returns the phpCAS version.
\r
652 * @return the phpCAS version.
\r
654 function getVersion()
\r
656 return PHPCAS_VERSION;
\r
660 // ########################################################################
\r
662 // ########################################################################
\r
664 * @addtogroup publicOutput
\r
669 * This method sets the HTML header used for all outputs.
\r
671 * @param $header the HTML header.
\r
673 function setHTMLHeader($header)
\r
675 global $PHPCAS_CLIENT;
\r
676 if ( !is_object($PHPCAS_CLIENT) ) {
\r
677 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
679 if ( gettype($header) != 'string' ) {
\r
680 phpCAS::error('type mismatched for parameter $header (should be `string\')');
\r
682 $PHPCAS_CLIENT->setHTMLHeader($header);
\r
686 * This method sets the HTML footer used for all outputs.
\r
688 * @param $footer the HTML footer.
\r
690 function setHTMLFooter($footer)
\r
692 global $PHPCAS_CLIENT;
\r
693 if ( !is_object($PHPCAS_CLIENT) ) {
\r
694 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
696 if ( gettype($footer) != 'string' ) {
\r
697 phpCAS::error('type mismatched for parameter $footer (should be `string\')');
\r
699 $PHPCAS_CLIENT->setHTMLFooter($footer);
\r
703 // ########################################################################
\r
705 // ########################################################################
\r
707 * @addtogroup publicPGTStorage
\r
712 * This method is used to tell phpCAS to store the response of the
\r
713 * CAS server to PGT requests onto the filesystem.
\r
715 * @param $format the format used to store the PGT's (`plain' and `xml' allowed)
\r
716 * @param $path the path where the PGT's should be stored
\r
718 function setPGTStorageFile($format='',
\r
721 global $PHPCAS_CLIENT,$PHPCAS_AUTH_CHECK_CALL;
\r
723 phpCAS::traceBegin();
\r
724 if ( !is_object($PHPCAS_CLIENT) ) {
\r
725 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
727 if ( !$PHPCAS_CLIENT->isProxy() ) {
\r
728 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
730 if ( $PHPCAS_AUTH_CHECK_CALL['done'] ) {
\r
731 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'].')');
\r
733 if ( gettype($format) != 'string' ) {
\r
734 phpCAS::error('type mismatched for parameter $format (should be `string\')');
\r
736 if ( gettype($path) != 'string' ) {
\r
737 phpCAS::error('type mismatched for parameter $format (should be `string\')');
\r
739 $PHPCAS_CLIENT->setPGTStorageFile($format,$path);
\r
740 phpCAS::traceEnd();
\r
744 * This method is used to tell phpCAS to store the response of the
\r
745 * CAS server to PGT requests into a database.
\r
746 * @note The connection to the database is done only when needed.
\r
747 * As a consequence, bad parameters are detected only when
\r
748 * initializing PGT storage, except in debug mode.
\r
750 * @param $user the user to access the data with
\r
751 * @param $password the user's password
\r
752 * @param $database_type the type of the database hosting the data
\r
753 * @param $hostname the server hosting the database
\r
754 * @param $port the port the server is listening on
\r
755 * @param $database the name of the database
\r
756 * @param $table the name of the table storing the data
\r
758 function setPGTStorageDB($user,
\r
766 global $PHPCAS_CLIENT,$PHPCAS_AUTH_CHECK_CALL;
\r
768 phpCAS::traceBegin();
\r
769 if ( !is_object($PHPCAS_CLIENT) ) {
\r
770 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
772 if ( !$PHPCAS_CLIENT->isProxy() ) {
\r
773 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
775 if ( $PHPCAS_AUTH_CHECK_CALL['done'] ) {
\r
776 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'].')');
\r
778 if ( gettype($user) != 'string' ) {
\r
779 phpCAS::error('type mismatched for parameter $user (should be `string\')');
\r
781 if ( gettype($password) != 'string' ) {
\r
782 phpCAS::error('type mismatched for parameter $password (should be `string\')');
\r
784 if ( gettype($database_type) != 'string' ) {
\r
785 phpCAS::error('type mismatched for parameter $database_type (should be `string\')');
\r
787 if ( gettype($hostname) != 'string' ) {
\r
788 phpCAS::error('type mismatched for parameter $hostname (should be `string\')');
\r
790 if ( gettype($port) != 'integer' ) {
\r
791 phpCAS::error('type mismatched for parameter $port (should be `integer\')');
\r
793 if ( gettype($database) != 'string' ) {
\r
794 phpCAS::error('type mismatched for parameter $database (should be `string\')');
\r
796 if ( gettype($table) != 'string' ) {
\r
797 phpCAS::error('type mismatched for parameter $table (should be `string\')');
\r
799 $PHPCAS_CLIENT->setPGTStorageDB($user,$password,$database_type,$hostname,$port,$database,$table);
\r
800 phpCAS::traceEnd();
\r
804 // ########################################################################
\r
805 // ACCESS TO EXTERNAL SERVICES
\r
806 // ########################################################################
\r
808 * @addtogroup publicServices
\r
813 * This method is used to access an HTTP[S] service.
\r
815 * @param $url the service to access.
\r
816 * @param $err_code an error code Possible values are PHPCAS_SERVICE_OK (on
\r
817 * success), PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE, PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE,
\r
818 * PHPCAS_SERVICE_PT_FAILURE, PHPCAS_SERVICE_NOT AVAILABLE.
\r
819 * @param $output the output of the service (also used to give an error
\r
820 * message on failure).
\r
822 * @return TRUE on success, FALSE otherwise (in this later case, $err_code
\r
823 * gives the reason why it failed and $output contains an error message).
\r
825 function serviceWeb($url,&$err_code,&$output)
\r
827 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
\r
829 phpCAS::traceBegin();
\r
830 if ( !is_object($PHPCAS_CLIENT) ) {
\r
831 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
833 if ( !$PHPCAS_CLIENT->isProxy() ) {
\r
834 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
836 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
\r
837 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()');
\r
839 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
\r
840 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');
\r
842 if ( gettype($url) != 'string' ) {
\r
843 phpCAS::error('type mismatched for parameter $url (should be `string\')');
\r
846 $res = $PHPCAS_CLIENT->serviceWeb($url,$err_code,$output);
\r
848 phpCAS::traceEnd($res);
\r
853 * This method is used to access an IMAP/POP3/NNTP service.
\r
855 * @param $url a string giving the URL of the service, including the mailing box
\r
856 * for IMAP URLs, as accepted by imap_open().
\r
857 * @param $service a string giving for CAS retrieve Proxy ticket
\r
858 * @param $flags options given to imap_open().
\r
859 * @param $err_code an error code Possible values are PHPCAS_SERVICE_OK (on
\r
860 * success), PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE, PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE,
\r
861 * PHPCAS_SERVICE_PT_FAILURE, PHPCAS_SERVICE_NOT AVAILABLE.
\r
862 * @param $err_msg an error message on failure
\r
863 * @param $pt the Proxy Ticket (PT) retrieved from the CAS server to access the URL
\r
864 * on success, FALSE on error).
\r
866 * @return an IMAP stream on success, FALSE otherwise (in this later case, $err_code
\r
867 * gives the reason why it failed and $err_msg contains an error message).
\r
869 function serviceMail($url,$service,$flags,&$err_code,&$err_msg,&$pt)
\r
871 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
\r
873 phpCAS::traceBegin();
\r
874 if ( !is_object($PHPCAS_CLIENT) ) {
\r
875 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
877 if ( !$PHPCAS_CLIENT->isProxy() ) {
\r
878 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
880 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
\r
881 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()');
\r
883 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
\r
884 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');
\r
886 if ( gettype($url) != 'string' ) {
\r
887 phpCAS::error('type mismatched for parameter $url (should be `string\')');
\r
890 if ( gettype($flags) != 'integer' ) {
\r
891 phpCAS::error('type mismatched for parameter $flags (should be `integer\')');
\r
894 $res = $PHPCAS_CLIENT->serviceMail($url,$service,$flags,$err_code,$err_msg,$pt);
\r
896 phpCAS::traceEnd($res);
\r
901 // ########################################################################
\r
903 // ########################################################################
\r
905 * @addtogroup publicAuth
\r
910 * Set the times authentication will be cached before really accessing the CAS server in gateway mode:
\r
911 * - -1: check only once, and then never again (until you pree login)
\r
912 * - 0: always check
\r
913 * - n: check every "n" time
\r
915 * @param $n an integer.
\r
917 function setCacheTimesForAuthRecheck($n)
\r
919 global $PHPCAS_CLIENT;
\r
920 if ( !is_object($PHPCAS_CLIENT) ) {
\r
921 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
923 if ( gettype($n) != 'integer' ) {
\r
924 phpCAS::error('type mismatched for parameter $header (should be `string\')');
\r
926 $PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
\r
930 * This method is called to check if the user is authenticated (use the gateway feature).
\r
931 * @return TRUE when the user is authenticated; otherwise FALSE.
\r
933 function checkAuthentication()
\r
935 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
\r
937 phpCAS::traceBegin();
\r
938 if ( !is_object($PHPCAS_CLIENT) ) {
\r
939 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
942 $auth = $PHPCAS_CLIENT->checkAuthentication();
\r
944 // store where the authentication has been checked and the result
\r
945 $dbg = phpCAS::backtrace();
\r
946 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,
\r
947 'file' => $dbg[0]['file'],
\r
948 'line' => $dbg[0]['line'],
\r
949 'method' => __CLASS__.'::'.__FUNCTION__,
\r
950 'result' => $auth );
\r
951 phpCAS::traceEnd($auth);
\r
956 * This method is called to force authentication if the user was not already
\r
957 * authenticated. If the user is not authenticated, halt by redirecting to
\r
960 function forceAuthentication()
\r
962 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
\r
964 phpCAS::traceBegin();
\r
965 if ( !is_object($PHPCAS_CLIENT) ) {
\r
966 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
969 $auth = $PHPCAS_CLIENT->forceAuthentication();
\r
971 // store where the authentication has been checked and the result
\r
972 $dbg = phpCAS::backtrace();
\r
973 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,
\r
974 'file' => $dbg[0]['file'],
\r
975 'line' => $dbg[0]['line'],
\r
976 'method' => __CLASS__.'::'.__FUNCTION__,
\r
977 'result' => $auth );
\r
980 phpCAS::trace('user is not authenticated, redirecting to the CAS server');
\r
981 $PHPCAS_CLIENT->forceAuthentication();
\r
983 phpCAS::trace('no need to authenticate (user `'.phpCAS::getUser().'\' is already authenticated)');
\r
986 phpCAS::traceEnd();
\r
991 * This method is called to renew the authentication.
\r
993 function renewAuthentication() {
\r
994 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
\r
996 phpCAS::traceBegin();
\r
997 if ( !is_object($PHPCAS_CLIENT) ) {
\r
998 phpCAS::error('this method should not be called before'.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
1001 // store where the authentication has been checked and the result
\r
1002 $dbg = phpCAS::backtrace();
\r
1003 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE, 'file' => $dbg[0]['file'], 'line' => $dbg[0]['line'], 'method' => __CLASS__.'::'.__FUNCTION__, 'result' => $auth );
\r
1005 $PHPCAS_CLIENT->renewAuthentication();
\r
1006 phpCAS::traceEnd();
\r
1010 * This method has been left from version 0.4.1 for compatibility reasons.
\r
1012 function authenticate()
\r
1014 phpCAS::error('this method is deprecated. You should use '.__CLASS__.'::forceAuthentication() instead');
\r
1018 * This method is called to check if the user is authenticated (previously or by
\r
1019 * tickets given in the URL).
\r
1021 * @return TRUE when the user is authenticated.
\r
1023 function isAuthenticated()
\r
1025 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
\r
1027 phpCAS::traceBegin();
\r
1028 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1029 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
1032 // call the isAuthenticated method of the global $PHPCAS_CLIENT object
\r
1033 $auth = $PHPCAS_CLIENT->isAuthenticated();
\r
1035 // store where the authentication has been checked and the result
\r
1036 $dbg = phpCAS::backtrace();
\r
1037 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,
\r
1038 'file' => $dbg[0]['file'],
\r
1039 'line' => $dbg[0]['line'],
\r
1040 'method' => __CLASS__.'::'.__FUNCTION__,
\r
1041 'result' => $auth );
\r
1042 phpCAS::traceEnd($auth);
\r
1047 * Checks whether authenticated based on $_SESSION. Useful to avoid
\r
1049 * @return true if authenticated, false otherwise.
\r
1050 * @since 0.4.22 by Brendan Arnold
\r
1052 function isSessionAuthenticated ()
\r
1054 global $PHPCAS_CLIENT;
\r
1055 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1056 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
1058 return($PHPCAS_CLIENT->isSessionAuthenticated());
\r
1062 * This method returns the CAS user's login name.
\r
1063 * @warning should not be called only after phpCAS::forceAuthentication()
\r
1064 * or phpCAS::checkAuthentication().
\r
1066 * @return the login name of the authenticated user
\r
1068 function getUser()
\r
1070 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
\r
1071 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1072 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
1074 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
\r
1075 phpCAS::error('this method should only be called after '.__CLASS__.'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()');
\r
1077 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
\r
1078 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');
\r
1080 return $PHPCAS_CLIENT->getUser();
\r
1084 * This method returns the CAS user's login name.
\r
1085 * @warning should not be called only after phpCAS::forceAuthentication()
\r
1086 * or phpCAS::checkAuthentication().
\r
1088 * @return the login name of the authenticated user
\r
1090 function getAttributes()
\r
1092 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
\r
1093 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1094 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
1096 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {
\r
1097 phpCAS::error('this method should only be called after '.__CLASS__.'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()');
\r
1099 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {
\r
1100 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');
\r
1102 return $PHPCAS_CLIENT->getAttributes();
\r
1105 * Handle logout requests.
\r
1107 function handleLogoutRequests($check_client=true, $allowed_clients=false)
\r
1109 global $PHPCAS_CLIENT;
\r
1110 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1111 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
1113 return($PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
\r
1117 * This method returns the URL to be used to login.
\r
1118 * or phpCAS::isAuthenticated().
\r
1120 * @return the login name of the authenticated user
\r
1122 function getServerLoginURL()
\r
1124 global $PHPCAS_CLIENT;
\r
1125 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1126 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
1128 return $PHPCAS_CLIENT->getServerLoginURL();
\r
1132 * Set the login URL of the CAS server.
\r
1133 * @param $url the login URL
\r
1134 * @since 0.4.21 by Wyman Chan
\r
1136 function setServerLoginURL($url='')
\r
1138 global $PHPCAS_CLIENT;
\r
1139 phpCAS::traceBegin();
\r
1140 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1141 phpCAS::error('this method should only be called after
\r
1142 '.__CLASS__.'::client()');
\r
1144 if ( gettype($url) != 'string' ) {
\r
1145 phpCAS::error('type mismatched for parameter $url (should be
\r
1148 $PHPCAS_CLIENT->setServerLoginURL($url);
\r
1149 phpCAS::traceEnd();
\r
1154 * Set the serviceValidate URL of the CAS server.
\r
1155 * @param $url the serviceValidate URL
\r
1156 * @since 1.1.0 by Joachim Fritschi
\r
1158 function setServerServiceValidateURL($url='')
\r
1160 global $PHPCAS_CLIENT;
\r
1161 phpCAS::traceBegin();
\r
1162 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1163 phpCAS::error('this method should only be called after
\r
1164 '.__CLASS__.'::client()');
\r
1166 if ( gettype($url) != 'string' ) {
\r
1167 phpCAS::error('type mismatched for parameter $url (should be
\r
1170 $PHPCAS_CLIENT->setServerServiceValidateURL($url);
\r
1171 phpCAS::traceEnd();
\r
1176 * Set the proxyValidate URL of the CAS server.
\r
1177 * @param $url the proxyValidate URL
\r
1178 * @since 1.1.0 by Joachim Fritschi
\r
1180 function setServerProxyValidateURL($url='')
\r
1182 global $PHPCAS_CLIENT;
\r
1183 phpCAS::traceBegin();
\r
1184 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1185 phpCAS::error('this method should only be called after
\r
1186 '.__CLASS__.'::client()');
\r
1188 if ( gettype($url) != 'string' ) {
\r
1189 phpCAS::error('type mismatched for parameter $url (should be
\r
1192 $PHPCAS_CLIENT->setServerProxyValidateURL($url);
\r
1193 phpCAS::traceEnd();
\r
1197 * Set the samlValidate URL of the CAS server.
\r
1198 * @param $url the samlValidate URL
\r
1199 * @since 1.1.0 by Joachim Fritschi
\r
1201 function setServerSamlValidateURL($url='')
\r
1203 global $PHPCAS_CLIENT;
\r
1204 phpCAS::traceBegin();
\r
1205 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1206 phpCAS::error('this method should only be called after
\r
1207 '.__CLASS__.'::client()');
\r
1209 if ( gettype($url) != 'string' ) {
\r
1210 phpCAS::error('type mismatched for parameter $url (should be
\r
1213 $PHPCAS_CLIENT->setServerSamlValidateURL($url);
\r
1214 phpCAS::traceEnd();
\r
1218 * This method returns the URL to be used to login.
\r
1219 * or phpCAS::isAuthenticated().
\r
1221 * @return the login name of the authenticated user
\r
1223 function getServerLogoutURL()
\r
1225 global $PHPCAS_CLIENT;
\r
1226 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1227 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');
\r
1229 return $PHPCAS_CLIENT->getServerLogoutURL();
\r
1233 * Set the logout URL of the CAS server.
\r
1234 * @param $url the logout URL
\r
1235 * @since 0.4.21 by Wyman Chan
\r
1237 function setServerLogoutURL($url='')
\r
1239 global $PHPCAS_CLIENT;
\r
1240 phpCAS::traceBegin();
\r
1241 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1242 phpCAS::error('this method should only be called after
\r
1243 '.__CLASS__.'::client()');
\r
1245 if ( gettype($url) != 'string' ) {
\r
1246 phpCAS::error('type mismatched for parameter $url (should be
\r
1249 $PHPCAS_CLIENT->setServerLogoutURL($url);
\r
1250 phpCAS::traceEnd();
\r
1254 * This method is used to logout from CAS.
\r
1255 * @params $params an array that contains the optional url and service parameters that will be passed to the CAS server
\r
1258 function logout($params = "") {
\r
1259 global $PHPCAS_CLIENT;
\r
1260 phpCAS::traceBegin();
\r
1261 if (!is_object($PHPCAS_CLIENT)) {
\r
1262 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
\r
1264 $parsedParams = array();
\r
1265 if ($params != "") {
\r
1266 if (is_string($params)) {
\r
1267 phpCAS::error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');
\r
1269 if (!is_array($params)) {
\r
1270 phpCAS::error('type mismatched for parameter $params (should be `array\')');
\r
1272 foreach ($params as $key => $value) {
\r
1273 if ($key != "service" && $key != "url") {
\r
1274 phpCAS::error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');
\r
1276 $parsedParams[$key] = $value;
\r
1279 $PHPCAS_CLIENT->logout($parsedParams);
\r
1281 phpCAS::traceEnd();
\r
1285 * This method is used to logout from CAS. Halts by redirecting to the CAS server.
\r
1286 * @param $service a URL that will be transmitted to the CAS server
\r
1288 function logoutWithRedirectService($service) {
\r
1289 global $PHPCAS_CLIENT;
\r
1290 phpCAS::traceBegin();
\r
1291 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1292 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
\r
1294 if (!is_string($service)) {
\r
1295 phpCAS::error('type mismatched for parameter $service (should be `string\')');
\r
1297 $PHPCAS_CLIENT->logout(array("service" => $service));
\r
1299 phpCAS::traceEnd();
\r
1303 * This method is used to logout from CAS. Halts by redirecting to the CAS server.
\r
1304 * @param $url a URL that will be transmitted to the CAS server
\r
1306 function logoutWithUrl($url) {
\r
1307 global $PHPCAS_CLIENT;
\r
1308 phpCAS::traceBegin();
\r
1309 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1310 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
\r
1312 if (!is_string($url)) {
\r
1313 phpCAS::error('type mismatched for parameter $url (should be `string\')');
\r
1315 $PHPCAS_CLIENT->logout(array("url" => $url));
\r
1317 phpCAS::traceEnd();
\r
1321 * This method is used to logout from CAS. Halts by redirecting to the CAS server.
\r
1322 * @param $service a URL that will be transmitted to the CAS server
\r
1323 * @param $url a URL that will be transmitted to the CAS server
\r
1325 function logoutWithRedirectServiceAndUrl($service, $url) {
\r
1326 global $PHPCAS_CLIENT;
\r
1327 phpCAS::traceBegin();
\r
1328 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1329 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
\r
1331 if (!is_string($service)) {
\r
1332 phpCAS::error('type mismatched for parameter $service (should be `string\')');
\r
1334 if (!is_string($url)) {
\r
1335 phpCAS::error('type mismatched for parameter $url (should be `string\')');
\r
1337 $PHPCAS_CLIENT->logout(array("service" => $service, "url" => $url));
\r
1339 phpCAS::traceEnd();
\r
1343 * Set the fixed URL that will be used by the CAS server to transmit the PGT.
\r
1344 * When this method is not called, a phpCAS script uses its own URL for the callback.
\r
1346 * @param $url the URL
\r
1348 function setFixedCallbackURL($url='')
\r
1350 global $PHPCAS_CLIENT;
\r
1351 phpCAS::traceBegin();
\r
1352 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1353 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
1355 if ( !$PHPCAS_CLIENT->isProxy() ) {
\r
1356 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
1358 if ( gettype($url) != 'string' ) {
\r
1359 phpCAS::error('type mismatched for parameter $url (should be `string\')');
\r
1361 $PHPCAS_CLIENT->setCallbackURL($url);
\r
1362 phpCAS::traceEnd();
\r
1366 * Set the fixed URL that will be set as the CAS service parameter. When this
\r
1367 * method is not called, a phpCAS script uses its own URL.
\r
1369 * @param $url the URL
\r
1371 function setFixedServiceURL($url)
\r
1373 global $PHPCAS_CLIENT;
\r
1374 phpCAS::traceBegin();
\r
1375 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1376 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
1378 if ( gettype($url) != 'string' ) {
\r
1379 phpCAS::error('type mismatched for parameter $url (should be `string\')');
\r
1381 $PHPCAS_CLIENT->setURL($url);
\r
1382 phpCAS::traceEnd();
\r
1386 * Get the URL that is set as the CAS service parameter.
\r
1388 function getServiceURL()
\r
1390 global $PHPCAS_CLIENT;
\r
1391 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1392 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
1394 return($PHPCAS_CLIENT->getURL());
\r
1398 * Retrieve a Proxy Ticket from the CAS server.
\r
1400 function retrievePT($target_service,&$err_code,&$err_msg)
\r
1402 global $PHPCAS_CLIENT;
\r
1403 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1404 phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');
\r
1406 if ( gettype($target_service) != 'string' ) {
\r
1407 phpCAS::error('type mismatched for parameter $target_service(should be `string\')');
\r
1409 return($PHPCAS_CLIENT->retrievePT($target_service,$err_code,$err_msg));
\r
1413 * Set the certificate of the CAS server.
\r
1415 * @param $cert the PEM certificate
\r
1417 function setCasServerCert($cert)
\r
1419 global $PHPCAS_CLIENT;
\r
1420 phpCAS::traceBegin();
\r
1421 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1422 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
\r
1424 if ( gettype($cert) != 'string' ) {
\r
1425 phpCAS::error('type mismatched for parameter $cert (should be `string\')');
\r
1427 $PHPCAS_CLIENT->setCasServerCert($cert);
\r
1428 phpCAS::traceEnd();
\r
1432 * Set the certificate of the CAS server CA.
\r
1434 * @param $cert the CA certificate
\r
1436 function setCasServerCACert($cert)
\r
1438 global $PHPCAS_CLIENT;
\r
1439 phpCAS::traceBegin();
\r
1440 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1441 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
\r
1443 if ( gettype($cert) != 'string' ) {
\r
1444 phpCAS::error('type mismatched for parameter $cert (should be `string\')');
\r
1446 $PHPCAS_CLIENT->setCasServerCACert($cert);
\r
1447 phpCAS::traceEnd();
\r
1451 * Set no SSL validation for the CAS server.
\r
1453 function setNoCasServerValidation()
\r
1455 global $PHPCAS_CLIENT;
\r
1456 phpCAS::traceBegin();
\r
1457 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1458 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
\r
1460 $PHPCAS_CLIENT->setNoCasServerValidation();
\r
1461 phpCAS::traceEnd();
\r
1467 * Change CURL options.
\r
1468 * CURL is used to connect through HTTPS to CAS server
\r
1469 * @param $key the option key
\r
1470 * @param $value the value to set
\r
1472 function setExtraCurlOption($key, $value)
\r
1474 global $PHPCAS_CLIENT;
\r
1475 phpCAS::traceBegin();
\r
1476 if ( !is_object($PHPCAS_CLIENT) ) {
\r
1477 phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');
\r
1479 $PHPCAS_CLIENT->setExtraCurlOption($key, $value);
\r
1480 phpCAS::traceEnd();
\r
1485 // ########################################################################
\r
1487 // ########################################################################
\r
1489 // ########################################################################
\r
1495 * The following pages only show the source documentation.
\r
1499 // ########################################################################
\r
1500 // MODULES DEFINITION
\r
1502 /** @defgroup public User interface */
\r
1504 /** @defgroup publicInit Initialization
\r
1505 * @ingroup public */
\r
1507 /** @defgroup publicAuth Authentication
\r
1508 * @ingroup public */
\r
1510 /** @defgroup publicServices Access to external services
\r
1511 * @ingroup public */
\r
1513 /** @defgroup publicConfig Configuration
\r
1514 * @ingroup public */
\r
1516 /** @defgroup publicLang Internationalization
\r
1517 * @ingroup publicConfig */
\r
1519 /** @defgroup publicOutput HTML output
\r
1520 * @ingroup publicConfig */
\r
1522 /** @defgroup publicPGTStorage PGT storage
\r
1523 * @ingroup publicConfig */
\r
1525 /** @defgroup publicDebug Debugging
\r
1526 * @ingroup public */
\r
1529 /** @defgroup internal Implementation */
\r
1531 /** @defgroup internalAuthentication Authentication
\r
1532 * @ingroup internal */
\r
1534 /** @defgroup internalBasic CAS Basic client features (CAS 1.0, Service Tickets)
\r
1535 * @ingroup internal */
\r
1537 /** @defgroup internalProxy CAS Proxy features (CAS 2.0, Proxy Granting Tickets)
\r
1538 * @ingroup internal */
\r
1540 /** @defgroup internalPGTStorage PGT storage
\r
1541 * @ingroup internalProxy */
\r
1543 /** @defgroup internalPGTStorageDB PGT storage in a database
\r
1544 * @ingroup internalPGTStorage */
\r
1546 /** @defgroup internalPGTStorageFile PGT storage on the filesystem
\r
1547 * @ingroup internalPGTStorage */
\r
1549 /** @defgroup internalCallback Callback from the CAS server
\r
1550 * @ingroup internalProxy */
\r
1552 /** @defgroup internalProxied CAS proxied client features (CAS 2.0, Proxy Tickets)
\r
1553 * @ingroup internal */
\r
1555 /** @defgroup internalConfig Configuration
\r
1556 * @ingroup internal */
\r
1558 /** @defgroup internalOutput HTML output
\r
1559 * @ingroup internalConfig */
\r
1561 /** @defgroup internalLang Internationalization
\r
1562 * @ingroup internalConfig
\r
1564 * To add a new language:
\r
1565 * - 1. define a new constant PHPCAS_LANG_XXXXXX in CAS/CAS.php
\r
1566 * - 2. copy any file from CAS/languages to CAS/languages/XXXXXX.php
\r
1567 * - 3. Make the translations
\r
1570 /** @defgroup internalDebug Debugging
\r
1571 * @ingroup internal */
\r
1573 /** @defgroup internalMisc Miscellaneous
\r
1574 * @ingroup internal */
\r
1576 // ########################################################################
\r
1580 * @example example_simple.php
\r
1583 * @example example_proxy.php
\r
1586 * @example example_proxy2.php
\r
1589 * @example example_lang.php
\r
1592 * @example example_html.php
\r
1595 * @example example_file.php
\r
1598 * @example example_db.php
\r
1601 * @example example_service.php
\r
1604 * @example example_session_proxy.php
\r
1607 * @example example_session_service.php
\r
1610 * @example example_gateway.php
\r