@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | // hack by Vangelis Haniotakis to handle the absence of $_SERVER['REQUEST_URI'] in IIS |
34 | 34 | // |
35 | 35 | if (!$_SERVER['REQUEST_URI']) { |
36 | - $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING']; |
|
36 | + $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING']; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | // |
40 | 40 | // another one by Vangelis Haniotakis also to make phpCAS work with PHP5 |
41 | 41 | // |
42 | 42 | if (version_compare(PHP_VERSION, '5', '>=')) { |
43 | - require_once (dirname(__FILE__) . '/CAS/domxml-php4-to-php5.php'); |
|
43 | + require_once (dirname(__FILE__) . '/CAS/domxml-php4-to-php5.php'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -282,10 +282,10 @@ discard block |
||
282 | 282 | * @hideinitializer |
283 | 283 | */ |
284 | 284 | $GLOBALS['PHPCAS_INIT_CALL'] = array ( |
285 | - 'done' => FALSE, |
|
286 | - 'file' => '?', |
|
287 | - 'line' => -1, |
|
288 | - 'method' => '?' |
|
285 | + 'done' => FALSE, |
|
286 | + 'file' => '?', |
|
287 | + 'line' => -1, |
|
288 | + 'method' => '?' |
|
289 | 289 | ); |
290 | 290 | |
291 | 291 | /** |
@@ -295,11 +295,11 @@ discard block |
||
295 | 295 | * @hideinitializer |
296 | 296 | */ |
297 | 297 | $GLOBALS['PHPCAS_AUTH_CHECK_CALL'] = array ( |
298 | - 'done' => FALSE, |
|
299 | - 'file' => '?', |
|
300 | - 'line' => -1, |
|
301 | - 'method' => '?', |
|
302 | - 'result' => FALSE |
|
298 | + 'done' => FALSE, |
|
299 | + 'file' => '?', |
|
300 | + 'line' => -1, |
|
301 | + 'method' => '?', |
|
302 | + 'result' => FALSE |
|
303 | 303 | ); |
304 | 304 | |
305 | 305 | /** |
@@ -308,9 +308,9 @@ discard block |
||
308 | 308 | * @hideinitializer |
309 | 309 | */ |
310 | 310 | $GLOBALS['PHPCAS_DEBUG'] = array ( |
311 | - 'filename' => '/tmp/cas.log', |
|
312 | - 'indent' => 0, |
|
313 | - 'unique_id' => '' |
|
311 | + 'filename' => '/tmp/cas.log', |
|
312 | + 'indent' => 0, |
|
313 | + 'unique_id' => '' |
|
314 | 314 | ); |
315 | 315 | |
316 | 316 | /** @} */ |
@@ -340,1141 +340,1141 @@ discard block |
||
340 | 340 | |
341 | 341 | class phpCAS { |
342 | 342 | |
343 | - // ######################################################################## |
|
344 | - // INITIALIZATION |
|
345 | - // ######################################################################## |
|
346 | - |
|
347 | - /** |
|
348 | - * @addtogroup publicInit |
|
349 | - * @{ |
|
350 | - */ |
|
351 | - |
|
352 | - /** |
|
353 | - * phpCAS client initializer. |
|
354 | - * @note Only one of the phpCAS::client() and phpCAS::proxy functions should be |
|
355 | - * called, only once, and before all other methods (except phpCAS::getVersion() |
|
356 | - * and phpCAS::setDebug()). |
|
357 | - * |
|
358 | - * @param $server_version the version of the CAS server |
|
359 | - * @param $server_hostname the hostname of the CAS server |
|
360 | - * @param $server_port the port the CAS server is running on |
|
361 | - * @param $server_uri the URI the CAS server is responding on |
|
362 | - * @param $start_session Have phpCAS start PHP sessions (default true) |
|
363 | - * |
|
364 | - * @return a newly created CASClient object |
|
365 | - */ |
|
366 | - function client($server_version, $server_hostname, $server_port, $server_uri, $start_session = true) { |
|
367 | - global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL; |
|
368 | - |
|
369 | - phpCAS :: traceBegin(); |
|
370 | - if (is_object($PHPCAS_CLIENT)) { |
|
371 | - phpCAS :: error($PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . $PHPCAS_INIT_CALL['file'] . ':' . $PHPCAS_INIT_CALL['line'] . ')'); |
|
372 | - } |
|
373 | - if (gettype($server_version) != 'string') { |
|
374 | - phpCAS :: error('type mismatched for parameter $server_version (should be `string\')'); |
|
375 | - } |
|
376 | - if (gettype($server_hostname) != 'string') { |
|
377 | - phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')'); |
|
378 | - } |
|
379 | - if (gettype($server_port) != 'integer') { |
|
380 | - phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')'); |
|
381 | - } |
|
382 | - if (gettype($server_uri) != 'string') { |
|
383 | - phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')'); |
|
384 | - } |
|
385 | - |
|
386 | - // store where the initializer is called from |
|
387 | - $dbg = phpCAS :: backtrace(); |
|
388 | - $PHPCAS_INIT_CALL = array ( |
|
389 | - 'done' => TRUE, |
|
390 | - 'file' => $dbg[0]['file'], |
|
391 | - 'line' => $dbg[0]['line'], |
|
392 | - 'method' => __CLASS__ . '::' . __FUNCTION__ |
|
393 | - ); |
|
394 | - |
|
395 | - // initialize the global object $PHPCAS_CLIENT |
|
396 | - $PHPCAS_CLIENT = new CASClient($server_version, FALSE /*proxy*/ |
|
397 | - , $server_hostname, $server_port, $server_uri, $start_session); |
|
398 | - phpCAS :: traceEnd(); |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * phpCAS proxy initializer. |
|
403 | - * @note Only one of the phpCAS::client() and phpCAS::proxy functions should be |
|
404 | - * called, only once, and before all other methods (except phpCAS::getVersion() |
|
405 | - * and phpCAS::setDebug()). |
|
406 | - * |
|
407 | - * @param $server_version the version of the CAS server |
|
408 | - * @param $server_hostname the hostname of the CAS server |
|
409 | - * @param $server_port the port the CAS server is running on |
|
410 | - * @param $server_uri the URI the CAS server is responding on |
|
411 | - * @param $start_session Have phpCAS start PHP sessions (default true) |
|
412 | - * |
|
413 | - * @return a newly created CASClient object |
|
414 | - */ |
|
415 | - function proxy($server_version, $server_hostname, $server_port, $server_uri, $start_session = true) { |
|
416 | - global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL; |
|
417 | - |
|
418 | - phpCAS :: traceBegin(); |
|
419 | - if (is_object($PHPCAS_CLIENT)) { |
|
420 | - phpCAS :: error($PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . $PHPCAS_INIT_CALL['file'] . ':' . $PHPCAS_INIT_CALL['line'] . ')'); |
|
421 | - } |
|
422 | - if (gettype($server_version) != 'string') { |
|
423 | - phpCAS :: error('type mismatched for parameter $server_version (should be `string\')'); |
|
424 | - } |
|
425 | - if (gettype($server_hostname) != 'string') { |
|
426 | - phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')'); |
|
427 | - } |
|
428 | - if (gettype($server_port) != 'integer') { |
|
429 | - phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')'); |
|
430 | - } |
|
431 | - if (gettype($server_uri) != 'string') { |
|
432 | - phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')'); |
|
433 | - } |
|
434 | - |
|
435 | - // store where the initialzer is called from |
|
436 | - $dbg = phpCAS :: backtrace(); |
|
437 | - $PHPCAS_INIT_CALL = array ( |
|
438 | - 'done' => TRUE, |
|
439 | - 'file' => $dbg[0]['file'], |
|
440 | - 'line' => $dbg[0]['line'], |
|
441 | - 'method' => __CLASS__ . '::' . __FUNCTION__ |
|
442 | - ); |
|
443 | - |
|
444 | - // initialize the global object $PHPCAS_CLIENT |
|
445 | - $PHPCAS_CLIENT = new CASClient($server_version, TRUE /*proxy*/ |
|
446 | - , $server_hostname, $server_port, $server_uri, $start_session); |
|
447 | - phpCAS :: traceEnd(); |
|
448 | - } |
|
449 | - |
|
450 | - /** @} */ |
|
451 | - // ######################################################################## |
|
452 | - // DEBUGGING |
|
453 | - // ######################################################################## |
|
454 | - |
|
455 | - /** |
|
456 | - * @addtogroup publicDebug |
|
457 | - * @{ |
|
458 | - */ |
|
459 | - |
|
460 | - /** |
|
461 | - * Set/unset debug mode |
|
462 | - * |
|
463 | - * @param $filename the name of the file used for logging, or FALSE to stop debugging. |
|
464 | - */ |
|
465 | - function setDebug($filename = '') { |
|
466 | - global $PHPCAS_DEBUG; |
|
467 | - |
|
468 | - if ($filename != FALSE && gettype($filename) != 'string') { |
|
469 | - phpCAS :: error('type mismatched for parameter $dbg (should be FALSE or the name of the log file)'); |
|
470 | - } |
|
471 | - |
|
472 | - if (empty ($filename)) { |
|
473 | - if (preg_match('/^Win.*/', getenv('OS'))) { |
|
474 | - if (isset ($_ENV['TMP'])) { |
|
475 | - $debugDir = $_ENV['TMP'] . '/'; |
|
476 | - } else |
|
477 | - if (isset ($_ENV['TEMP'])) { |
|
478 | - $debugDir = $_ENV['TEMP'] . '/'; |
|
479 | - } else { |
|
480 | - $debugDir = ''; |
|
481 | - } |
|
482 | - } else { |
|
483 | - $debugDir = DEFAULT_DEBUG_DIR; |
|
484 | - } |
|
485 | - $filename = $debugDir . 'phpCAS.log'; |
|
486 | - } |
|
487 | - |
|
488 | - if (empty ($PHPCAS_DEBUG['unique_id'])) { |
|
489 | - $PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4); |
|
490 | - } |
|
491 | - |
|
492 | - $PHPCAS_DEBUG['filename'] = $filename; |
|
493 | - |
|
494 | - phpCAS :: trace('START ******************'); |
|
495 | - } |
|
496 | - |
|
497 | - /** @} */ |
|
498 | - /** |
|
499 | - * @addtogroup internalDebug |
|
500 | - * @{ |
|
501 | - */ |
|
502 | - |
|
503 | - /** |
|
504 | - * This method is a wrapper for debug_backtrace() that is not available |
|
505 | - * in all PHP versions (>= 4.3.0 only) |
|
506 | - */ |
|
507 | - function backtrace() { |
|
508 | - if (function_exists('debug_backtrace')) { |
|
509 | - return debug_backtrace(); |
|
510 | - } else { |
|
511 | - // poor man's hack ... but it does work ... |
|
512 | - return array (); |
|
513 | - } |
|
514 | - } |
|
515 | - |
|
516 | - /** |
|
517 | - * Logs a string in debug mode. |
|
518 | - * |
|
519 | - * @param $str the string to write |
|
520 | - * |
|
521 | - * @private |
|
522 | - */ |
|
523 | - function log($str) { |
|
524 | - $indent_str = "."; |
|
525 | - global $PHPCAS_DEBUG; |
|
526 | - |
|
527 | - if ($PHPCAS_DEBUG['filename']) { |
|
528 | - for ($i = 0; $i < $PHPCAS_DEBUG['indent']; $i++) { |
|
529 | - $indent_str .= '| '; |
|
530 | - } |
|
531 | - error_log($PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str . $str . "\n", 3, $PHPCAS_DEBUG['filename']); |
|
532 | - } |
|
533 | - |
|
534 | - } |
|
535 | - |
|
536 | - /** |
|
537 | - * This method is used by interface methods to print an error and where the function |
|
538 | - * was originally called from. |
|
539 | - * |
|
540 | - * @param $msg the message to print |
|
541 | - * |
|
542 | - * @private |
|
543 | - */ |
|
544 | - function error($msg) { |
|
545 | - $dbg = phpCAS :: backtrace(); |
|
546 | - $function = '?'; |
|
547 | - $file = '?'; |
|
548 | - $line = '?'; |
|
549 | - if (is_array($dbg)) { |
|
550 | - for ($i = 1; $i < sizeof($dbg); $i++) { |
|
551 | - if (is_array($dbg[$i])) { |
|
552 | - if ($dbg[$i]['class'] == __CLASS__) { |
|
553 | - $function = $dbg[$i]['function']; |
|
554 | - $file = $dbg[$i]['file']; |
|
555 | - $line = $dbg[$i]['line']; |
|
556 | - } |
|
557 | - } |
|
558 | - } |
|
559 | - } |
|
560 | - 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"; |
|
561 | - phpCAS :: trace($msg); |
|
562 | - phpCAS :: traceExit(); |
|
563 | - exit (); |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * This method is used to log something in debug mode. |
|
568 | - */ |
|
569 | - function trace($str) { |
|
570 | - $dbg = phpCAS :: backtrace(); |
|
571 | - phpCAS :: log($str . ' [' . basename($dbg[1]['file']) . ':' . $dbg[1]['line'] . ']'); |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * This method is used to indicate the start of the execution of a function in debug mode. |
|
576 | - */ |
|
577 | - function traceBegin() { |
|
578 | - global $PHPCAS_DEBUG; |
|
579 | - |
|
580 | - $dbg = phpCAS :: backtrace(); |
|
581 | - $str = '=> '; |
|
582 | - if (!empty ($dbg[2]['class'])) { |
|
583 | - $str .= $dbg[2]['class'] . '::'; |
|
584 | - } |
|
585 | - $str .= $dbg[2]['function'] . '('; |
|
586 | - if (is_array($dbg[2]['args'])) { |
|
587 | - foreach ($dbg[2]['args'] as $index => $arg) { |
|
588 | - if ($index != 0) { |
|
589 | - $str .= ', '; |
|
590 | - } |
|
591 | - $str .= str_replace("\n", "", var_export($arg, TRUE)); |
|
592 | - } |
|
593 | - } |
|
594 | - $str .= ') [' . basename($dbg[2]['file']) . ':' . $dbg[2]['line'] . ']'; |
|
595 | - phpCAS :: log($str); |
|
596 | - $PHPCAS_DEBUG['indent']++; |
|
597 | - } |
|
598 | - |
|
599 | - /** |
|
600 | - * This method is used to indicate the end of the execution of a function in debug mode. |
|
601 | - * |
|
602 | - * @param $res the result of the function |
|
603 | - */ |
|
604 | - function traceEnd($res = '') { |
|
605 | - global $PHPCAS_DEBUG; |
|
606 | - |
|
607 | - $PHPCAS_DEBUG['indent']--; |
|
608 | - $dbg = phpCAS :: backtrace(); |
|
609 | - $str = ''; |
|
610 | - $str .= '<= ' . str_replace("\n", "", var_export($res, TRUE)); |
|
611 | - phpCAS :: log($str); |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * This method is used to indicate the end of the execution of the program |
|
616 | - */ |
|
617 | - function traceExit() { |
|
618 | - global $PHPCAS_DEBUG; |
|
619 | - |
|
620 | - phpCAS :: log('exit()'); |
|
621 | - while ($PHPCAS_DEBUG['indent'] > 0) { |
|
622 | - phpCAS :: log('-'); |
|
623 | - $PHPCAS_DEBUG['indent']--; |
|
624 | - } |
|
625 | - } |
|
626 | - |
|
627 | - /** @} */ |
|
628 | - // ######################################################################## |
|
629 | - // INTERNATIONALIZATION |
|
630 | - // ######################################################################## |
|
631 | - /** |
|
632 | - * @addtogroup publicLang |
|
633 | - * @{ |
|
634 | - */ |
|
635 | - |
|
636 | - /** |
|
637 | - * This method is used to set the language used by phpCAS. |
|
638 | - * @note Can be called only once. |
|
639 | - * |
|
640 | - * @param $lang a string representing the language. |
|
641 | - * |
|
642 | - * @sa PHPCAS_LANG_FRENCH, PHPCAS_LANG_ENGLISH |
|
643 | - */ |
|
644 | - function setLang($lang) { |
|
645 | - global $PHPCAS_CLIENT; |
|
646 | - if (!is_object($PHPCAS_CLIENT)) { |
|
647 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
648 | - } |
|
649 | - if (gettype($lang) != 'string') { |
|
650 | - phpCAS :: error('type mismatched for parameter $lang (should be `string\')'); |
|
651 | - } |
|
652 | - $PHPCAS_CLIENT->setLang($lang); |
|
653 | - } |
|
654 | - |
|
655 | - /** @} */ |
|
656 | - // ######################################################################## |
|
657 | - // VERSION |
|
658 | - // ######################################################################## |
|
659 | - /** |
|
660 | - * @addtogroup public |
|
661 | - * @{ |
|
662 | - */ |
|
663 | - |
|
664 | - /** |
|
665 | - * This method returns the phpCAS version. |
|
666 | - * |
|
667 | - * @return the phpCAS version. |
|
668 | - */ |
|
669 | - function getVersion() { |
|
670 | - return PHPCAS_VERSION; |
|
671 | - } |
|
672 | - |
|
673 | - /** @} */ |
|
674 | - // ######################################################################## |
|
675 | - // HTML OUTPUT |
|
676 | - // ######################################################################## |
|
677 | - /** |
|
678 | - * @addtogroup publicOutput |
|
679 | - * @{ |
|
680 | - */ |
|
681 | - |
|
682 | - /** |
|
683 | - * This method sets the HTML header used for all outputs. |
|
684 | - * |
|
685 | - * @param $header the HTML header. |
|
686 | - */ |
|
687 | - function setHTMLHeader($header) { |
|
688 | - global $PHPCAS_CLIENT; |
|
689 | - if (!is_object($PHPCAS_CLIENT)) { |
|
690 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
691 | - } |
|
692 | - if (gettype($header) != 'string') { |
|
693 | - phpCAS :: error('type mismatched for parameter $header (should be `string\')'); |
|
694 | - } |
|
695 | - $PHPCAS_CLIENT->setHTMLHeader($header); |
|
696 | - } |
|
697 | - |
|
698 | - /** |
|
699 | - * This method sets the HTML footer used for all outputs. |
|
700 | - * |
|
701 | - * @param $footer the HTML footer. |
|
702 | - */ |
|
703 | - function setHTMLFooter($footer) { |
|
704 | - global $PHPCAS_CLIENT; |
|
705 | - if (!is_object($PHPCAS_CLIENT)) { |
|
706 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
707 | - } |
|
708 | - if (gettype($footer) != 'string') { |
|
709 | - phpCAS :: error('type mismatched for parameter $footer (should be `string\')'); |
|
710 | - } |
|
711 | - $PHPCAS_CLIENT->setHTMLFooter($footer); |
|
712 | - } |
|
713 | - |
|
714 | - /** @} */ |
|
715 | - // ######################################################################## |
|
716 | - // PGT STORAGE |
|
717 | - // ######################################################################## |
|
718 | - /** |
|
719 | - * @addtogroup publicPGTStorage |
|
720 | - * @{ |
|
721 | - */ |
|
722 | - |
|
723 | - /** |
|
724 | - * This method is used to tell phpCAS to store the response of the |
|
725 | - * CAS server to PGT requests onto the filesystem. |
|
726 | - * |
|
727 | - * @param $format the format used to store the PGT's (`plain' and `xml' allowed) |
|
728 | - * @param $path the path where the PGT's should be stored |
|
729 | - */ |
|
730 | - function setPGTStorageFile($format = '', $path = '') { |
|
731 | - global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
732 | - |
|
733 | - phpCAS :: traceBegin(); |
|
734 | - if (!is_object($PHPCAS_CLIENT)) { |
|
735 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
736 | - } |
|
737 | - if (!$PHPCAS_CLIENT->isProxy()) { |
|
738 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
739 | - } |
|
740 | - if ($PHPCAS_AUTH_CHECK_CALL['done']) { |
|
741 | - 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'] . ')'); |
|
742 | - } |
|
743 | - if (gettype($format) != 'string') { |
|
744 | - phpCAS :: error('type mismatched for parameter $format (should be `string\')'); |
|
745 | - } |
|
746 | - if (gettype($path) != 'string') { |
|
747 | - phpCAS :: error('type mismatched for parameter $format (should be `string\')'); |
|
748 | - } |
|
749 | - $PHPCAS_CLIENT->setPGTStorageFile($format, $path); |
|
750 | - phpCAS :: traceEnd(); |
|
751 | - } |
|
752 | - |
|
753 | - /** |
|
754 | - * This method is used to tell phpCAS to store the response of the |
|
755 | - * CAS server to PGT requests into a database. |
|
756 | - * @note The connection to the database is done only when needed. |
|
757 | - * As a consequence, bad parameters are detected only when |
|
758 | - * initializing PGT storage, except in debug mode. |
|
759 | - * |
|
760 | - * @param $user the user to access the data with |
|
761 | - * @param $password the user's password |
|
762 | - * @param $database_type the type of the database hosting the data |
|
763 | - * @param $hostname the server hosting the database |
|
764 | - * @param $port the port the server is listening on |
|
765 | - * @param $database the name of the database |
|
766 | - * @param $table the name of the table storing the data |
|
767 | - */ |
|
768 | - function setPGTStorageDB($user, $password, $database_type = '', $hostname = '', $port = 0, $database = '', $table = '') { |
|
769 | - global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
770 | - |
|
771 | - phpCAS :: traceBegin(); |
|
772 | - if (!is_object($PHPCAS_CLIENT)) { |
|
773 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
774 | - } |
|
775 | - if (!$PHPCAS_CLIENT->isProxy()) { |
|
776 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
777 | - } |
|
778 | - if ($PHPCAS_AUTH_CHECK_CALL['done']) { |
|
779 | - 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'] . ')'); |
|
780 | - } |
|
781 | - if (gettype($user) != 'string') { |
|
782 | - phpCAS :: error('type mismatched for parameter $user (should be `string\')'); |
|
783 | - } |
|
784 | - if (gettype($password) != 'string') { |
|
785 | - phpCAS :: error('type mismatched for parameter $password (should be `string\')'); |
|
786 | - } |
|
787 | - if (gettype($database_type) != 'string') { |
|
788 | - phpCAS :: error('type mismatched for parameter $database_type (should be `string\')'); |
|
789 | - } |
|
790 | - if (gettype($hostname) != 'string') { |
|
791 | - phpCAS :: error('type mismatched for parameter $hostname (should be `string\')'); |
|
792 | - } |
|
793 | - if (gettype($port) != 'integer') { |
|
794 | - phpCAS :: error('type mismatched for parameter $port (should be `integer\')'); |
|
795 | - } |
|
796 | - if (gettype($database) != 'string') { |
|
797 | - phpCAS :: error('type mismatched for parameter $database (should be `string\')'); |
|
798 | - } |
|
799 | - if (gettype($table) != 'string') { |
|
800 | - phpCAS :: error('type mismatched for parameter $table (should be `string\')'); |
|
801 | - } |
|
802 | - $PHPCAS_CLIENT->setPGTStorageDB($user, $password, $database_type, $hostname, $port, $database, $table); |
|
803 | - phpCAS :: traceEnd(); |
|
804 | - } |
|
805 | - |
|
806 | - /** @} */ |
|
807 | - // ######################################################################## |
|
808 | - // ACCESS TO EXTERNAL SERVICES |
|
809 | - // ######################################################################## |
|
810 | - /** |
|
811 | - * @addtogroup publicServices |
|
812 | - * @{ |
|
813 | - */ |
|
814 | - |
|
815 | - /** |
|
816 | - * This method is used to access an HTTP[S] service. |
|
817 | - * |
|
818 | - * @param $url the service to access. |
|
819 | - * @param $err_code an error code Possible values are PHPCAS_SERVICE_OK (on |
|
820 | - * success), PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE, PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE, |
|
821 | - * PHPCAS_SERVICE_PT_FAILURE, PHPCAS_SERVICE_NOT AVAILABLE. |
|
822 | - * @param $output the output of the service (also used to give an error |
|
823 | - * message on failure). |
|
824 | - * |
|
825 | - * @return TRUE on success, FALSE otherwise (in this later case, $err_code |
|
826 | - * gives the reason why it failed and $output contains an error message). |
|
827 | - */ |
|
828 | - function serviceWeb($url, & $err_code, & $output) { |
|
829 | - global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
830 | - |
|
831 | - phpCAS :: traceBegin(); |
|
832 | - if (!is_object($PHPCAS_CLIENT)) { |
|
833 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
834 | - } |
|
835 | - if (!$PHPCAS_CLIENT->isProxy()) { |
|
836 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
837 | - } |
|
838 | - if (!$PHPCAS_AUTH_CHECK_CALL['done']) { |
|
839 | - 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()'); |
|
840 | - } |
|
841 | - if (!$PHPCAS_AUTH_CHECK_CALL['result']) { |
|
842 | - 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'); |
|
843 | - } |
|
844 | - if (gettype($url) != 'string') { |
|
845 | - phpCAS :: error('type mismatched for parameter $url (should be `string\')'); |
|
846 | - } |
|
847 | - |
|
848 | - $res = $PHPCAS_CLIENT->serviceWeb($url, $err_code, $output); |
|
849 | - |
|
850 | - phpCAS :: traceEnd($res); |
|
851 | - return $res; |
|
852 | - } |
|
853 | - |
|
854 | - /** |
|
855 | - * This method is used to access an IMAP/POP3/NNTP service. |
|
856 | - * |
|
857 | - * @param $url a string giving the URL of the service, including the mailing box |
|
858 | - * for IMAP URLs, as accepted by imap_open(). |
|
859 | - * @param $service a string giving for CAS retrieve Proxy ticket |
|
860 | - * @param $flags options given to imap_open(). |
|
861 | - * @param $err_code an error code Possible values are PHPCAS_SERVICE_OK (on |
|
862 | - * success), PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE, PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE, |
|
863 | - * PHPCAS_SERVICE_PT_FAILURE, PHPCAS_SERVICE_NOT AVAILABLE. |
|
864 | - * @param $err_msg an error message on failure |
|
865 | - * @param $pt the Proxy Ticket (PT) retrieved from the CAS server to access the URL |
|
866 | - * on success, FALSE on error). |
|
867 | - * |
|
868 | - * @return an IMAP stream on success, FALSE otherwise (in this later case, $err_code |
|
869 | - * gives the reason why it failed and $err_msg contains an error message). |
|
870 | - */ |
|
871 | - function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt) { |
|
872 | - global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
873 | - |
|
874 | - phpCAS :: traceBegin(); |
|
875 | - if (!is_object($PHPCAS_CLIENT)) { |
|
876 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
877 | - } |
|
878 | - if (!$PHPCAS_CLIENT->isProxy()) { |
|
879 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
880 | - } |
|
881 | - if (!$PHPCAS_AUTH_CHECK_CALL['done']) { |
|
882 | - 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()'); |
|
883 | - } |
|
884 | - if (!$PHPCAS_AUTH_CHECK_CALL['result']) { |
|
885 | - 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'); |
|
886 | - } |
|
887 | - if (gettype($url) != 'string') { |
|
888 | - phpCAS :: error('type mismatched for parameter $url (should be `string\')'); |
|
889 | - } |
|
890 | - |
|
891 | - if (gettype($flags) != 'integer') { |
|
892 | - phpCAS :: error('type mismatched for parameter $flags (should be `integer\')'); |
|
893 | - } |
|
894 | - |
|
895 | - $res = $PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt); |
|
896 | - |
|
897 | - phpCAS :: traceEnd($res); |
|
898 | - return $res; |
|
899 | - } |
|
900 | - |
|
901 | - /** @} */ |
|
902 | - // ######################################################################## |
|
903 | - // AUTHENTICATION |
|
904 | - // ######################################################################## |
|
905 | - /** |
|
906 | - * @addtogroup publicAuth |
|
907 | - * @{ |
|
908 | - */ |
|
909 | - |
|
910 | - /** |
|
911 | - * Set the times authentication will be cached before really accessing the CAS server in gateway mode: |
|
912 | - * - -1: check only once, and then never again (until you pree login) |
|
913 | - * - 0: always check |
|
914 | - * - n: check every "n" time |
|
915 | - * |
|
916 | - * @param $n an integer. |
|
917 | - */ |
|
918 | - function setCacheTimesForAuthRecheck($n) { |
|
919 | - global $PHPCAS_CLIENT; |
|
920 | - if (!is_object($PHPCAS_CLIENT)) { |
|
921 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
922 | - } |
|
923 | - if (gettype($n) != 'integer') { |
|
924 | - phpCAS :: error('type mismatched for parameter $header (should be `string\')'); |
|
925 | - } |
|
926 | - $PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n); |
|
927 | - } |
|
928 | - |
|
929 | - /** |
|
930 | - * This method is called to check if the user is authenticated (use the gateway feature). |
|
931 | - * @return TRUE when the user is authenticated; otherwise FALSE. |
|
932 | - */ |
|
933 | - function checkAuthentication() { |
|
934 | - global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
935 | - |
|
936 | - phpCAS :: traceBegin(); |
|
937 | - if (!is_object($PHPCAS_CLIENT)) { |
|
938 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
939 | - } |
|
940 | - |
|
941 | - $auth = $PHPCAS_CLIENT->checkAuthentication(); |
|
942 | - |
|
943 | - // store where the authentication has been checked and the result |
|
944 | - $dbg = phpCAS :: backtrace(); |
|
945 | - $PHPCAS_AUTH_CHECK_CALL = array ( |
|
946 | - 'done' => TRUE, |
|
947 | - 'file' => $dbg[0]['file'], |
|
948 | - 'line' => $dbg[0]['line'], |
|
949 | - 'method' => __CLASS__ . '::' . __FUNCTION__, |
|
950 | - 'result' => $auth |
|
951 | - ); |
|
952 | - phpCAS :: traceEnd($auth); |
|
953 | - return $auth; |
|
954 | - } |
|
955 | - |
|
956 | - /** |
|
957 | - * This method is called to force authentication if the user was not already |
|
958 | - * authenticated. If the user is not authenticated, halt by redirecting to |
|
959 | - * the CAS server. |
|
960 | - */ |
|
961 | - function forceAuthentication() { |
|
962 | - global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
963 | - |
|
964 | - phpCAS :: traceBegin(); |
|
965 | - if (!is_object($PHPCAS_CLIENT)) { |
|
966 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
967 | - } |
|
968 | - |
|
969 | - $auth = $PHPCAS_CLIENT->forceAuthentication(); |
|
970 | - |
|
971 | - // store where the authentication has been checked and the result |
|
972 | - $dbg = phpCAS :: backtrace(); |
|
973 | - $PHPCAS_AUTH_CHECK_CALL = array ( |
|
974 | - 'done' => TRUE, |
|
975 | - 'file' => $dbg[0]['file'], |
|
976 | - 'line' => $dbg[0]['line'], |
|
977 | - 'method' => __CLASS__ . '::' . __FUNCTION__, |
|
978 | - 'result' => $auth |
|
979 | - ); |
|
980 | - |
|
981 | - if (!$auth) { |
|
982 | - phpCAS :: trace('user is not authenticated, redirecting to the CAS server'); |
|
983 | - $PHPCAS_CLIENT->forceAuthentication(); |
|
984 | - } else { |
|
985 | - phpCAS :: trace('no need to authenticate (user `' . phpCAS :: getUser() . '\' is already authenticated)'); |
|
986 | - } |
|
987 | - |
|
988 | - phpCAS :: traceEnd(); |
|
989 | - return $auth; |
|
990 | - } |
|
991 | - |
|
992 | - /** |
|
993 | - * This method is called to renew the authentication. |
|
994 | - **/ |
|
995 | - function renewAuthentication() { |
|
996 | - global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
997 | - |
|
998 | - phpCAS :: traceBegin(); |
|
999 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1000 | - phpCAS :: error('this method should not be called before' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1001 | - } |
|
1002 | - |
|
1003 | - // store where the authentication has been checked and the result |
|
1004 | - $dbg = phpCAS :: backtrace(); |
|
1005 | - $PHPCAS_AUTH_CHECK_CALL = array ( |
|
1006 | - 'done' => TRUE, |
|
1007 | - 'file' => $dbg[0]['file'], |
|
1008 | - 'line' => $dbg[0]['line'], |
|
1009 | - 'method' => __CLASS__ . '::' . __FUNCTION__, |
|
1010 | - 'result' => $auth |
|
1011 | - ); |
|
1012 | - |
|
1013 | - $PHPCAS_CLIENT->renewAuthentication(); |
|
1014 | - phpCAS :: traceEnd(); |
|
1015 | - } |
|
1016 | - |
|
1017 | - /** |
|
1018 | - * This method has been left from version 0.4.1 for compatibility reasons. |
|
1019 | - */ |
|
1020 | - function authenticate() { |
|
1021 | - phpCAS :: error('this method is deprecated. You should use ' . __CLASS__ . '::forceAuthentication() instead'); |
|
1022 | - } |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * This method is called to check if the user is authenticated (previously or by |
|
1026 | - * tickets given in the URL). |
|
1027 | - * |
|
1028 | - * @return TRUE when the user is authenticated. |
|
1029 | - */ |
|
1030 | - function isAuthenticated() { |
|
1031 | - global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
1032 | - |
|
1033 | - phpCAS :: traceBegin(); |
|
1034 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1035 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1036 | - } |
|
1037 | - |
|
1038 | - // call the isAuthenticated method of the global $PHPCAS_CLIENT object |
|
1039 | - $auth = $PHPCAS_CLIENT->isAuthenticated(); |
|
1040 | - |
|
1041 | - // store where the authentication has been checked and the result |
|
1042 | - $dbg = phpCAS :: backtrace(); |
|
1043 | - $PHPCAS_AUTH_CHECK_CALL = array ( |
|
1044 | - 'done' => TRUE, |
|
1045 | - 'file' => $dbg[0]['file'], |
|
1046 | - 'line' => $dbg[0]['line'], |
|
1047 | - 'method' => __CLASS__ . '::' . __FUNCTION__, |
|
1048 | - 'result' => $auth |
|
1049 | - ); |
|
1050 | - phpCAS :: traceEnd($auth); |
|
1051 | - return $auth; |
|
1052 | - } |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * Checks whether authenticated based on $_SESSION. Useful to avoid |
|
1056 | - * server calls. |
|
1057 | - * @return true if authenticated, false otherwise. |
|
1058 | - * @since 0.4.22 by Brendan Arnold |
|
1059 | - */ |
|
1060 | - function isSessionAuthenticated() { |
|
1061 | - global $PHPCAS_CLIENT; |
|
1062 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1063 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1064 | - } |
|
1065 | - return ($PHPCAS_CLIENT->isSessionAuthenticated()); |
|
1066 | - } |
|
1067 | - |
|
1068 | - /** |
|
1069 | - * This method returns the CAS user's login name. |
|
1070 | - * @warning should not be called only after phpCAS::forceAuthentication() |
|
1071 | - * or phpCAS::checkAuthentication(). |
|
1072 | - * |
|
1073 | - * @return the login name of the authenticated user |
|
1074 | - */ |
|
1075 | - function getUser() { |
|
1076 | - global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
1077 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1078 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1079 | - } |
|
1080 | - if (!$PHPCAS_AUTH_CHECK_CALL['done']) { |
|
1081 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()'); |
|
1082 | - } |
|
1083 | - if (!$PHPCAS_AUTH_CHECK_CALL['result']) { |
|
1084 | - 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'); |
|
1085 | - } |
|
1086 | - return $PHPCAS_CLIENT->getUser(); |
|
1087 | - } |
|
1088 | - |
|
1089 | - /** |
|
1090 | - * This method returns the CAS user's login name. |
|
1091 | - * @warning should not be called only after phpCAS::forceAuthentication() |
|
1092 | - * or phpCAS::checkAuthentication(). |
|
1093 | - * |
|
1094 | - * @return the login name of the authenticated user |
|
1095 | - */ |
|
1096 | - function getAttributes() { |
|
1097 | - global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
1098 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1099 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1100 | - } |
|
1101 | - if (!$PHPCAS_AUTH_CHECK_CALL['done']) { |
|
1102 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()'); |
|
1103 | - } |
|
1104 | - if (!$PHPCAS_AUTH_CHECK_CALL['result']) { |
|
1105 | - 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'); |
|
1106 | - } |
|
1107 | - return $PHPCAS_CLIENT->getAttributes(); |
|
1108 | - } |
|
1109 | - /** |
|
1110 | - * Handle logout requests. |
|
1111 | - */ |
|
1112 | - function handleLogoutRequests($check_client = true, $allowed_clients = false) { |
|
1113 | - global $PHPCAS_CLIENT; |
|
1114 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1115 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1116 | - } |
|
1117 | - return ($PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients)); |
|
1118 | - } |
|
1119 | - |
|
1120 | - /** |
|
1121 | - * This method returns the URL to be used to login. |
|
1122 | - * or phpCAS::isAuthenticated(). |
|
1123 | - * |
|
1124 | - * @return the login name of the authenticated user |
|
1125 | - */ |
|
1126 | - function getServerLoginURL() { |
|
1127 | - global $PHPCAS_CLIENT; |
|
1128 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1129 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1130 | - } |
|
1131 | - return $PHPCAS_CLIENT->getServerLoginURL(); |
|
1132 | - } |
|
1133 | - |
|
1134 | - /** |
|
1135 | - * Set the login URL of the CAS server. |
|
1136 | - * @param $url the login URL |
|
1137 | - * @since 0.4.21 by Wyman Chan |
|
1138 | - */ |
|
1139 | - function setServerLoginURL($url = '') { |
|
1140 | - global $PHPCAS_CLIENT; |
|
1141 | - phpCAS :: traceBegin(); |
|
1142 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1143 | - phpCAS :: error('this method should only be called after |
|
343 | + // ######################################################################## |
|
344 | + // INITIALIZATION |
|
345 | + // ######################################################################## |
|
346 | + |
|
347 | + /** |
|
348 | + * @addtogroup publicInit |
|
349 | + * @{ |
|
350 | + */ |
|
351 | + |
|
352 | + /** |
|
353 | + * phpCAS client initializer. |
|
354 | + * @note Only one of the phpCAS::client() and phpCAS::proxy functions should be |
|
355 | + * called, only once, and before all other methods (except phpCAS::getVersion() |
|
356 | + * and phpCAS::setDebug()). |
|
357 | + * |
|
358 | + * @param $server_version the version of the CAS server |
|
359 | + * @param $server_hostname the hostname of the CAS server |
|
360 | + * @param $server_port the port the CAS server is running on |
|
361 | + * @param $server_uri the URI the CAS server is responding on |
|
362 | + * @param $start_session Have phpCAS start PHP sessions (default true) |
|
363 | + * |
|
364 | + * @return a newly created CASClient object |
|
365 | + */ |
|
366 | + function client($server_version, $server_hostname, $server_port, $server_uri, $start_session = true) { |
|
367 | + global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL; |
|
368 | + |
|
369 | + phpCAS :: traceBegin(); |
|
370 | + if (is_object($PHPCAS_CLIENT)) { |
|
371 | + phpCAS :: error($PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . $PHPCAS_INIT_CALL['file'] . ':' . $PHPCAS_INIT_CALL['line'] . ')'); |
|
372 | + } |
|
373 | + if (gettype($server_version) != 'string') { |
|
374 | + phpCAS :: error('type mismatched for parameter $server_version (should be `string\')'); |
|
375 | + } |
|
376 | + if (gettype($server_hostname) != 'string') { |
|
377 | + phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')'); |
|
378 | + } |
|
379 | + if (gettype($server_port) != 'integer') { |
|
380 | + phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')'); |
|
381 | + } |
|
382 | + if (gettype($server_uri) != 'string') { |
|
383 | + phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')'); |
|
384 | + } |
|
385 | + |
|
386 | + // store where the initializer is called from |
|
387 | + $dbg = phpCAS :: backtrace(); |
|
388 | + $PHPCAS_INIT_CALL = array ( |
|
389 | + 'done' => TRUE, |
|
390 | + 'file' => $dbg[0]['file'], |
|
391 | + 'line' => $dbg[0]['line'], |
|
392 | + 'method' => __CLASS__ . '::' . __FUNCTION__ |
|
393 | + ); |
|
394 | + |
|
395 | + // initialize the global object $PHPCAS_CLIENT |
|
396 | + $PHPCAS_CLIENT = new CASClient($server_version, FALSE /*proxy*/ |
|
397 | + , $server_hostname, $server_port, $server_uri, $start_session); |
|
398 | + phpCAS :: traceEnd(); |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * phpCAS proxy initializer. |
|
403 | + * @note Only one of the phpCAS::client() and phpCAS::proxy functions should be |
|
404 | + * called, only once, and before all other methods (except phpCAS::getVersion() |
|
405 | + * and phpCAS::setDebug()). |
|
406 | + * |
|
407 | + * @param $server_version the version of the CAS server |
|
408 | + * @param $server_hostname the hostname of the CAS server |
|
409 | + * @param $server_port the port the CAS server is running on |
|
410 | + * @param $server_uri the URI the CAS server is responding on |
|
411 | + * @param $start_session Have phpCAS start PHP sessions (default true) |
|
412 | + * |
|
413 | + * @return a newly created CASClient object |
|
414 | + */ |
|
415 | + function proxy($server_version, $server_hostname, $server_port, $server_uri, $start_session = true) { |
|
416 | + global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL; |
|
417 | + |
|
418 | + phpCAS :: traceBegin(); |
|
419 | + if (is_object($PHPCAS_CLIENT)) { |
|
420 | + phpCAS :: error($PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . $PHPCAS_INIT_CALL['file'] . ':' . $PHPCAS_INIT_CALL['line'] . ')'); |
|
421 | + } |
|
422 | + if (gettype($server_version) != 'string') { |
|
423 | + phpCAS :: error('type mismatched for parameter $server_version (should be `string\')'); |
|
424 | + } |
|
425 | + if (gettype($server_hostname) != 'string') { |
|
426 | + phpCAS :: error('type mismatched for parameter $server_hostname (should be `string\')'); |
|
427 | + } |
|
428 | + if (gettype($server_port) != 'integer') { |
|
429 | + phpCAS :: error('type mismatched for parameter $server_port (should be `integer\')'); |
|
430 | + } |
|
431 | + if (gettype($server_uri) != 'string') { |
|
432 | + phpCAS :: error('type mismatched for parameter $server_uri (should be `string\')'); |
|
433 | + } |
|
434 | + |
|
435 | + // store where the initialzer is called from |
|
436 | + $dbg = phpCAS :: backtrace(); |
|
437 | + $PHPCAS_INIT_CALL = array ( |
|
438 | + 'done' => TRUE, |
|
439 | + 'file' => $dbg[0]['file'], |
|
440 | + 'line' => $dbg[0]['line'], |
|
441 | + 'method' => __CLASS__ . '::' . __FUNCTION__ |
|
442 | + ); |
|
443 | + |
|
444 | + // initialize the global object $PHPCAS_CLIENT |
|
445 | + $PHPCAS_CLIENT = new CASClient($server_version, TRUE /*proxy*/ |
|
446 | + , $server_hostname, $server_port, $server_uri, $start_session); |
|
447 | + phpCAS :: traceEnd(); |
|
448 | + } |
|
449 | + |
|
450 | + /** @} */ |
|
451 | + // ######################################################################## |
|
452 | + // DEBUGGING |
|
453 | + // ######################################################################## |
|
454 | + |
|
455 | + /** |
|
456 | + * @addtogroup publicDebug |
|
457 | + * @{ |
|
458 | + */ |
|
459 | + |
|
460 | + /** |
|
461 | + * Set/unset debug mode |
|
462 | + * |
|
463 | + * @param $filename the name of the file used for logging, or FALSE to stop debugging. |
|
464 | + */ |
|
465 | + function setDebug($filename = '') { |
|
466 | + global $PHPCAS_DEBUG; |
|
467 | + |
|
468 | + if ($filename != FALSE && gettype($filename) != 'string') { |
|
469 | + phpCAS :: error('type mismatched for parameter $dbg (should be FALSE or the name of the log file)'); |
|
470 | + } |
|
471 | + |
|
472 | + if (empty ($filename)) { |
|
473 | + if (preg_match('/^Win.*/', getenv('OS'))) { |
|
474 | + if (isset ($_ENV['TMP'])) { |
|
475 | + $debugDir = $_ENV['TMP'] . '/'; |
|
476 | + } else |
|
477 | + if (isset ($_ENV['TEMP'])) { |
|
478 | + $debugDir = $_ENV['TEMP'] . '/'; |
|
479 | + } else { |
|
480 | + $debugDir = ''; |
|
481 | + } |
|
482 | + } else { |
|
483 | + $debugDir = DEFAULT_DEBUG_DIR; |
|
484 | + } |
|
485 | + $filename = $debugDir . 'phpCAS.log'; |
|
486 | + } |
|
487 | + |
|
488 | + if (empty ($PHPCAS_DEBUG['unique_id'])) { |
|
489 | + $PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4); |
|
490 | + } |
|
491 | + |
|
492 | + $PHPCAS_DEBUG['filename'] = $filename; |
|
493 | + |
|
494 | + phpCAS :: trace('START ******************'); |
|
495 | + } |
|
496 | + |
|
497 | + /** @} */ |
|
498 | + /** |
|
499 | + * @addtogroup internalDebug |
|
500 | + * @{ |
|
501 | + */ |
|
502 | + |
|
503 | + /** |
|
504 | + * This method is a wrapper for debug_backtrace() that is not available |
|
505 | + * in all PHP versions (>= 4.3.0 only) |
|
506 | + */ |
|
507 | + function backtrace() { |
|
508 | + if (function_exists('debug_backtrace')) { |
|
509 | + return debug_backtrace(); |
|
510 | + } else { |
|
511 | + // poor man's hack ... but it does work ... |
|
512 | + return array (); |
|
513 | + } |
|
514 | + } |
|
515 | + |
|
516 | + /** |
|
517 | + * Logs a string in debug mode. |
|
518 | + * |
|
519 | + * @param $str the string to write |
|
520 | + * |
|
521 | + * @private |
|
522 | + */ |
|
523 | + function log($str) { |
|
524 | + $indent_str = "."; |
|
525 | + global $PHPCAS_DEBUG; |
|
526 | + |
|
527 | + if ($PHPCAS_DEBUG['filename']) { |
|
528 | + for ($i = 0; $i < $PHPCAS_DEBUG['indent']; $i++) { |
|
529 | + $indent_str .= '| '; |
|
530 | + } |
|
531 | + error_log($PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str . $str . "\n", 3, $PHPCAS_DEBUG['filename']); |
|
532 | + } |
|
533 | + |
|
534 | + } |
|
535 | + |
|
536 | + /** |
|
537 | + * This method is used by interface methods to print an error and where the function |
|
538 | + * was originally called from. |
|
539 | + * |
|
540 | + * @param $msg the message to print |
|
541 | + * |
|
542 | + * @private |
|
543 | + */ |
|
544 | + function error($msg) { |
|
545 | + $dbg = phpCAS :: backtrace(); |
|
546 | + $function = '?'; |
|
547 | + $file = '?'; |
|
548 | + $line = '?'; |
|
549 | + if (is_array($dbg)) { |
|
550 | + for ($i = 1; $i < sizeof($dbg); $i++) { |
|
551 | + if (is_array($dbg[$i])) { |
|
552 | + if ($dbg[$i]['class'] == __CLASS__) { |
|
553 | + $function = $dbg[$i]['function']; |
|
554 | + $file = $dbg[$i]['file']; |
|
555 | + $line = $dbg[$i]['line']; |
|
556 | + } |
|
557 | + } |
|
558 | + } |
|
559 | + } |
|
560 | + 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"; |
|
561 | + phpCAS :: trace($msg); |
|
562 | + phpCAS :: traceExit(); |
|
563 | + exit (); |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * This method is used to log something in debug mode. |
|
568 | + */ |
|
569 | + function trace($str) { |
|
570 | + $dbg = phpCAS :: backtrace(); |
|
571 | + phpCAS :: log($str . ' [' . basename($dbg[1]['file']) . ':' . $dbg[1]['line'] . ']'); |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * This method is used to indicate the start of the execution of a function in debug mode. |
|
576 | + */ |
|
577 | + function traceBegin() { |
|
578 | + global $PHPCAS_DEBUG; |
|
579 | + |
|
580 | + $dbg = phpCAS :: backtrace(); |
|
581 | + $str = '=> '; |
|
582 | + if (!empty ($dbg[2]['class'])) { |
|
583 | + $str .= $dbg[2]['class'] . '::'; |
|
584 | + } |
|
585 | + $str .= $dbg[2]['function'] . '('; |
|
586 | + if (is_array($dbg[2]['args'])) { |
|
587 | + foreach ($dbg[2]['args'] as $index => $arg) { |
|
588 | + if ($index != 0) { |
|
589 | + $str .= ', '; |
|
590 | + } |
|
591 | + $str .= str_replace("\n", "", var_export($arg, TRUE)); |
|
592 | + } |
|
593 | + } |
|
594 | + $str .= ') [' . basename($dbg[2]['file']) . ':' . $dbg[2]['line'] . ']'; |
|
595 | + phpCAS :: log($str); |
|
596 | + $PHPCAS_DEBUG['indent']++; |
|
597 | + } |
|
598 | + |
|
599 | + /** |
|
600 | + * This method is used to indicate the end of the execution of a function in debug mode. |
|
601 | + * |
|
602 | + * @param $res the result of the function |
|
603 | + */ |
|
604 | + function traceEnd($res = '') { |
|
605 | + global $PHPCAS_DEBUG; |
|
606 | + |
|
607 | + $PHPCAS_DEBUG['indent']--; |
|
608 | + $dbg = phpCAS :: backtrace(); |
|
609 | + $str = ''; |
|
610 | + $str .= '<= ' . str_replace("\n", "", var_export($res, TRUE)); |
|
611 | + phpCAS :: log($str); |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * This method is used to indicate the end of the execution of the program |
|
616 | + */ |
|
617 | + function traceExit() { |
|
618 | + global $PHPCAS_DEBUG; |
|
619 | + |
|
620 | + phpCAS :: log('exit()'); |
|
621 | + while ($PHPCAS_DEBUG['indent'] > 0) { |
|
622 | + phpCAS :: log('-'); |
|
623 | + $PHPCAS_DEBUG['indent']--; |
|
624 | + } |
|
625 | + } |
|
626 | + |
|
627 | + /** @} */ |
|
628 | + // ######################################################################## |
|
629 | + // INTERNATIONALIZATION |
|
630 | + // ######################################################################## |
|
631 | + /** |
|
632 | + * @addtogroup publicLang |
|
633 | + * @{ |
|
634 | + */ |
|
635 | + |
|
636 | + /** |
|
637 | + * This method is used to set the language used by phpCAS. |
|
638 | + * @note Can be called only once. |
|
639 | + * |
|
640 | + * @param $lang a string representing the language. |
|
641 | + * |
|
642 | + * @sa PHPCAS_LANG_FRENCH, PHPCAS_LANG_ENGLISH |
|
643 | + */ |
|
644 | + function setLang($lang) { |
|
645 | + global $PHPCAS_CLIENT; |
|
646 | + if (!is_object($PHPCAS_CLIENT)) { |
|
647 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
648 | + } |
|
649 | + if (gettype($lang) != 'string') { |
|
650 | + phpCAS :: error('type mismatched for parameter $lang (should be `string\')'); |
|
651 | + } |
|
652 | + $PHPCAS_CLIENT->setLang($lang); |
|
653 | + } |
|
654 | + |
|
655 | + /** @} */ |
|
656 | + // ######################################################################## |
|
657 | + // VERSION |
|
658 | + // ######################################################################## |
|
659 | + /** |
|
660 | + * @addtogroup public |
|
661 | + * @{ |
|
662 | + */ |
|
663 | + |
|
664 | + /** |
|
665 | + * This method returns the phpCAS version. |
|
666 | + * |
|
667 | + * @return the phpCAS version. |
|
668 | + */ |
|
669 | + function getVersion() { |
|
670 | + return PHPCAS_VERSION; |
|
671 | + } |
|
672 | + |
|
673 | + /** @} */ |
|
674 | + // ######################################################################## |
|
675 | + // HTML OUTPUT |
|
676 | + // ######################################################################## |
|
677 | + /** |
|
678 | + * @addtogroup publicOutput |
|
679 | + * @{ |
|
680 | + */ |
|
681 | + |
|
682 | + /** |
|
683 | + * This method sets the HTML header used for all outputs. |
|
684 | + * |
|
685 | + * @param $header the HTML header. |
|
686 | + */ |
|
687 | + function setHTMLHeader($header) { |
|
688 | + global $PHPCAS_CLIENT; |
|
689 | + if (!is_object($PHPCAS_CLIENT)) { |
|
690 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
691 | + } |
|
692 | + if (gettype($header) != 'string') { |
|
693 | + phpCAS :: error('type mismatched for parameter $header (should be `string\')'); |
|
694 | + } |
|
695 | + $PHPCAS_CLIENT->setHTMLHeader($header); |
|
696 | + } |
|
697 | + |
|
698 | + /** |
|
699 | + * This method sets the HTML footer used for all outputs. |
|
700 | + * |
|
701 | + * @param $footer the HTML footer. |
|
702 | + */ |
|
703 | + function setHTMLFooter($footer) { |
|
704 | + global $PHPCAS_CLIENT; |
|
705 | + if (!is_object($PHPCAS_CLIENT)) { |
|
706 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
707 | + } |
|
708 | + if (gettype($footer) != 'string') { |
|
709 | + phpCAS :: error('type mismatched for parameter $footer (should be `string\')'); |
|
710 | + } |
|
711 | + $PHPCAS_CLIENT->setHTMLFooter($footer); |
|
712 | + } |
|
713 | + |
|
714 | + /** @} */ |
|
715 | + // ######################################################################## |
|
716 | + // PGT STORAGE |
|
717 | + // ######################################################################## |
|
718 | + /** |
|
719 | + * @addtogroup publicPGTStorage |
|
720 | + * @{ |
|
721 | + */ |
|
722 | + |
|
723 | + /** |
|
724 | + * This method is used to tell phpCAS to store the response of the |
|
725 | + * CAS server to PGT requests onto the filesystem. |
|
726 | + * |
|
727 | + * @param $format the format used to store the PGT's (`plain' and `xml' allowed) |
|
728 | + * @param $path the path where the PGT's should be stored |
|
729 | + */ |
|
730 | + function setPGTStorageFile($format = '', $path = '') { |
|
731 | + global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
732 | + |
|
733 | + phpCAS :: traceBegin(); |
|
734 | + if (!is_object($PHPCAS_CLIENT)) { |
|
735 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
736 | + } |
|
737 | + if (!$PHPCAS_CLIENT->isProxy()) { |
|
738 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
739 | + } |
|
740 | + if ($PHPCAS_AUTH_CHECK_CALL['done']) { |
|
741 | + 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'] . ')'); |
|
742 | + } |
|
743 | + if (gettype($format) != 'string') { |
|
744 | + phpCAS :: error('type mismatched for parameter $format (should be `string\')'); |
|
745 | + } |
|
746 | + if (gettype($path) != 'string') { |
|
747 | + phpCAS :: error('type mismatched for parameter $format (should be `string\')'); |
|
748 | + } |
|
749 | + $PHPCAS_CLIENT->setPGTStorageFile($format, $path); |
|
750 | + phpCAS :: traceEnd(); |
|
751 | + } |
|
752 | + |
|
753 | + /** |
|
754 | + * This method is used to tell phpCAS to store the response of the |
|
755 | + * CAS server to PGT requests into a database. |
|
756 | + * @note The connection to the database is done only when needed. |
|
757 | + * As a consequence, bad parameters are detected only when |
|
758 | + * initializing PGT storage, except in debug mode. |
|
759 | + * |
|
760 | + * @param $user the user to access the data with |
|
761 | + * @param $password the user's password |
|
762 | + * @param $database_type the type of the database hosting the data |
|
763 | + * @param $hostname the server hosting the database |
|
764 | + * @param $port the port the server is listening on |
|
765 | + * @param $database the name of the database |
|
766 | + * @param $table the name of the table storing the data |
|
767 | + */ |
|
768 | + function setPGTStorageDB($user, $password, $database_type = '', $hostname = '', $port = 0, $database = '', $table = '') { |
|
769 | + global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
770 | + |
|
771 | + phpCAS :: traceBegin(); |
|
772 | + if (!is_object($PHPCAS_CLIENT)) { |
|
773 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
774 | + } |
|
775 | + if (!$PHPCAS_CLIENT->isProxy()) { |
|
776 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
777 | + } |
|
778 | + if ($PHPCAS_AUTH_CHECK_CALL['done']) { |
|
779 | + 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'] . ')'); |
|
780 | + } |
|
781 | + if (gettype($user) != 'string') { |
|
782 | + phpCAS :: error('type mismatched for parameter $user (should be `string\')'); |
|
783 | + } |
|
784 | + if (gettype($password) != 'string') { |
|
785 | + phpCAS :: error('type mismatched for parameter $password (should be `string\')'); |
|
786 | + } |
|
787 | + if (gettype($database_type) != 'string') { |
|
788 | + phpCAS :: error('type mismatched for parameter $database_type (should be `string\')'); |
|
789 | + } |
|
790 | + if (gettype($hostname) != 'string') { |
|
791 | + phpCAS :: error('type mismatched for parameter $hostname (should be `string\')'); |
|
792 | + } |
|
793 | + if (gettype($port) != 'integer') { |
|
794 | + phpCAS :: error('type mismatched for parameter $port (should be `integer\')'); |
|
795 | + } |
|
796 | + if (gettype($database) != 'string') { |
|
797 | + phpCAS :: error('type mismatched for parameter $database (should be `string\')'); |
|
798 | + } |
|
799 | + if (gettype($table) != 'string') { |
|
800 | + phpCAS :: error('type mismatched for parameter $table (should be `string\')'); |
|
801 | + } |
|
802 | + $PHPCAS_CLIENT->setPGTStorageDB($user, $password, $database_type, $hostname, $port, $database, $table); |
|
803 | + phpCAS :: traceEnd(); |
|
804 | + } |
|
805 | + |
|
806 | + /** @} */ |
|
807 | + // ######################################################################## |
|
808 | + // ACCESS TO EXTERNAL SERVICES |
|
809 | + // ######################################################################## |
|
810 | + /** |
|
811 | + * @addtogroup publicServices |
|
812 | + * @{ |
|
813 | + */ |
|
814 | + |
|
815 | + /** |
|
816 | + * This method is used to access an HTTP[S] service. |
|
817 | + * |
|
818 | + * @param $url the service to access. |
|
819 | + * @param $err_code an error code Possible values are PHPCAS_SERVICE_OK (on |
|
820 | + * success), PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE, PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE, |
|
821 | + * PHPCAS_SERVICE_PT_FAILURE, PHPCAS_SERVICE_NOT AVAILABLE. |
|
822 | + * @param $output the output of the service (also used to give an error |
|
823 | + * message on failure). |
|
824 | + * |
|
825 | + * @return TRUE on success, FALSE otherwise (in this later case, $err_code |
|
826 | + * gives the reason why it failed and $output contains an error message). |
|
827 | + */ |
|
828 | + function serviceWeb($url, & $err_code, & $output) { |
|
829 | + global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
830 | + |
|
831 | + phpCAS :: traceBegin(); |
|
832 | + if (!is_object($PHPCAS_CLIENT)) { |
|
833 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
834 | + } |
|
835 | + if (!$PHPCAS_CLIENT->isProxy()) { |
|
836 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
837 | + } |
|
838 | + if (!$PHPCAS_AUTH_CHECK_CALL['done']) { |
|
839 | + 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()'); |
|
840 | + } |
|
841 | + if (!$PHPCAS_AUTH_CHECK_CALL['result']) { |
|
842 | + 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'); |
|
843 | + } |
|
844 | + if (gettype($url) != 'string') { |
|
845 | + phpCAS :: error('type mismatched for parameter $url (should be `string\')'); |
|
846 | + } |
|
847 | + |
|
848 | + $res = $PHPCAS_CLIENT->serviceWeb($url, $err_code, $output); |
|
849 | + |
|
850 | + phpCAS :: traceEnd($res); |
|
851 | + return $res; |
|
852 | + } |
|
853 | + |
|
854 | + /** |
|
855 | + * This method is used to access an IMAP/POP3/NNTP service. |
|
856 | + * |
|
857 | + * @param $url a string giving the URL of the service, including the mailing box |
|
858 | + * for IMAP URLs, as accepted by imap_open(). |
|
859 | + * @param $service a string giving for CAS retrieve Proxy ticket |
|
860 | + * @param $flags options given to imap_open(). |
|
861 | + * @param $err_code an error code Possible values are PHPCAS_SERVICE_OK (on |
|
862 | + * success), PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE, PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE, |
|
863 | + * PHPCAS_SERVICE_PT_FAILURE, PHPCAS_SERVICE_NOT AVAILABLE. |
|
864 | + * @param $err_msg an error message on failure |
|
865 | + * @param $pt the Proxy Ticket (PT) retrieved from the CAS server to access the URL |
|
866 | + * on success, FALSE on error). |
|
867 | + * |
|
868 | + * @return an IMAP stream on success, FALSE otherwise (in this later case, $err_code |
|
869 | + * gives the reason why it failed and $err_msg contains an error message). |
|
870 | + */ |
|
871 | + function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt) { |
|
872 | + global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
873 | + |
|
874 | + phpCAS :: traceBegin(); |
|
875 | + if (!is_object($PHPCAS_CLIENT)) { |
|
876 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
877 | + } |
|
878 | + if (!$PHPCAS_CLIENT->isProxy()) { |
|
879 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
880 | + } |
|
881 | + if (!$PHPCAS_AUTH_CHECK_CALL['done']) { |
|
882 | + 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()'); |
|
883 | + } |
|
884 | + if (!$PHPCAS_AUTH_CHECK_CALL['result']) { |
|
885 | + 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'); |
|
886 | + } |
|
887 | + if (gettype($url) != 'string') { |
|
888 | + phpCAS :: error('type mismatched for parameter $url (should be `string\')'); |
|
889 | + } |
|
890 | + |
|
891 | + if (gettype($flags) != 'integer') { |
|
892 | + phpCAS :: error('type mismatched for parameter $flags (should be `integer\')'); |
|
893 | + } |
|
894 | + |
|
895 | + $res = $PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt); |
|
896 | + |
|
897 | + phpCAS :: traceEnd($res); |
|
898 | + return $res; |
|
899 | + } |
|
900 | + |
|
901 | + /** @} */ |
|
902 | + // ######################################################################## |
|
903 | + // AUTHENTICATION |
|
904 | + // ######################################################################## |
|
905 | + /** |
|
906 | + * @addtogroup publicAuth |
|
907 | + * @{ |
|
908 | + */ |
|
909 | + |
|
910 | + /** |
|
911 | + * Set the times authentication will be cached before really accessing the CAS server in gateway mode: |
|
912 | + * - -1: check only once, and then never again (until you pree login) |
|
913 | + * - 0: always check |
|
914 | + * - n: check every "n" time |
|
915 | + * |
|
916 | + * @param $n an integer. |
|
917 | + */ |
|
918 | + function setCacheTimesForAuthRecheck($n) { |
|
919 | + global $PHPCAS_CLIENT; |
|
920 | + if (!is_object($PHPCAS_CLIENT)) { |
|
921 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
922 | + } |
|
923 | + if (gettype($n) != 'integer') { |
|
924 | + phpCAS :: error('type mismatched for parameter $header (should be `string\')'); |
|
925 | + } |
|
926 | + $PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n); |
|
927 | + } |
|
928 | + |
|
929 | + /** |
|
930 | + * This method is called to check if the user is authenticated (use the gateway feature). |
|
931 | + * @return TRUE when the user is authenticated; otherwise FALSE. |
|
932 | + */ |
|
933 | + function checkAuthentication() { |
|
934 | + global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
935 | + |
|
936 | + phpCAS :: traceBegin(); |
|
937 | + if (!is_object($PHPCAS_CLIENT)) { |
|
938 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
939 | + } |
|
940 | + |
|
941 | + $auth = $PHPCAS_CLIENT->checkAuthentication(); |
|
942 | + |
|
943 | + // store where the authentication has been checked and the result |
|
944 | + $dbg = phpCAS :: backtrace(); |
|
945 | + $PHPCAS_AUTH_CHECK_CALL = array ( |
|
946 | + 'done' => TRUE, |
|
947 | + 'file' => $dbg[0]['file'], |
|
948 | + 'line' => $dbg[0]['line'], |
|
949 | + 'method' => __CLASS__ . '::' . __FUNCTION__, |
|
950 | + 'result' => $auth |
|
951 | + ); |
|
952 | + phpCAS :: traceEnd($auth); |
|
953 | + return $auth; |
|
954 | + } |
|
955 | + |
|
956 | + /** |
|
957 | + * This method is called to force authentication if the user was not already |
|
958 | + * authenticated. If the user is not authenticated, halt by redirecting to |
|
959 | + * the CAS server. |
|
960 | + */ |
|
961 | + function forceAuthentication() { |
|
962 | + global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
963 | + |
|
964 | + phpCAS :: traceBegin(); |
|
965 | + if (!is_object($PHPCAS_CLIENT)) { |
|
966 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
967 | + } |
|
968 | + |
|
969 | + $auth = $PHPCAS_CLIENT->forceAuthentication(); |
|
970 | + |
|
971 | + // store where the authentication has been checked and the result |
|
972 | + $dbg = phpCAS :: backtrace(); |
|
973 | + $PHPCAS_AUTH_CHECK_CALL = array ( |
|
974 | + 'done' => TRUE, |
|
975 | + 'file' => $dbg[0]['file'], |
|
976 | + 'line' => $dbg[0]['line'], |
|
977 | + 'method' => __CLASS__ . '::' . __FUNCTION__, |
|
978 | + 'result' => $auth |
|
979 | + ); |
|
980 | + |
|
981 | + if (!$auth) { |
|
982 | + phpCAS :: trace('user is not authenticated, redirecting to the CAS server'); |
|
983 | + $PHPCAS_CLIENT->forceAuthentication(); |
|
984 | + } else { |
|
985 | + phpCAS :: trace('no need to authenticate (user `' . phpCAS :: getUser() . '\' is already authenticated)'); |
|
986 | + } |
|
987 | + |
|
988 | + phpCAS :: traceEnd(); |
|
989 | + return $auth; |
|
990 | + } |
|
991 | + |
|
992 | + /** |
|
993 | + * This method is called to renew the authentication. |
|
994 | + **/ |
|
995 | + function renewAuthentication() { |
|
996 | + global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
997 | + |
|
998 | + phpCAS :: traceBegin(); |
|
999 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1000 | + phpCAS :: error('this method should not be called before' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1001 | + } |
|
1002 | + |
|
1003 | + // store where the authentication has been checked and the result |
|
1004 | + $dbg = phpCAS :: backtrace(); |
|
1005 | + $PHPCAS_AUTH_CHECK_CALL = array ( |
|
1006 | + 'done' => TRUE, |
|
1007 | + 'file' => $dbg[0]['file'], |
|
1008 | + 'line' => $dbg[0]['line'], |
|
1009 | + 'method' => __CLASS__ . '::' . __FUNCTION__, |
|
1010 | + 'result' => $auth |
|
1011 | + ); |
|
1012 | + |
|
1013 | + $PHPCAS_CLIENT->renewAuthentication(); |
|
1014 | + phpCAS :: traceEnd(); |
|
1015 | + } |
|
1016 | + |
|
1017 | + /** |
|
1018 | + * This method has been left from version 0.4.1 for compatibility reasons. |
|
1019 | + */ |
|
1020 | + function authenticate() { |
|
1021 | + phpCAS :: error('this method is deprecated. You should use ' . __CLASS__ . '::forceAuthentication() instead'); |
|
1022 | + } |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * This method is called to check if the user is authenticated (previously or by |
|
1026 | + * tickets given in the URL). |
|
1027 | + * |
|
1028 | + * @return TRUE when the user is authenticated. |
|
1029 | + */ |
|
1030 | + function isAuthenticated() { |
|
1031 | + global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
1032 | + |
|
1033 | + phpCAS :: traceBegin(); |
|
1034 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1035 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1036 | + } |
|
1037 | + |
|
1038 | + // call the isAuthenticated method of the global $PHPCAS_CLIENT object |
|
1039 | + $auth = $PHPCAS_CLIENT->isAuthenticated(); |
|
1040 | + |
|
1041 | + // store where the authentication has been checked and the result |
|
1042 | + $dbg = phpCAS :: backtrace(); |
|
1043 | + $PHPCAS_AUTH_CHECK_CALL = array ( |
|
1044 | + 'done' => TRUE, |
|
1045 | + 'file' => $dbg[0]['file'], |
|
1046 | + 'line' => $dbg[0]['line'], |
|
1047 | + 'method' => __CLASS__ . '::' . __FUNCTION__, |
|
1048 | + 'result' => $auth |
|
1049 | + ); |
|
1050 | + phpCAS :: traceEnd($auth); |
|
1051 | + return $auth; |
|
1052 | + } |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * Checks whether authenticated based on $_SESSION. Useful to avoid |
|
1056 | + * server calls. |
|
1057 | + * @return true if authenticated, false otherwise. |
|
1058 | + * @since 0.4.22 by Brendan Arnold |
|
1059 | + */ |
|
1060 | + function isSessionAuthenticated() { |
|
1061 | + global $PHPCAS_CLIENT; |
|
1062 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1063 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1064 | + } |
|
1065 | + return ($PHPCAS_CLIENT->isSessionAuthenticated()); |
|
1066 | + } |
|
1067 | + |
|
1068 | + /** |
|
1069 | + * This method returns the CAS user's login name. |
|
1070 | + * @warning should not be called only after phpCAS::forceAuthentication() |
|
1071 | + * or phpCAS::checkAuthentication(). |
|
1072 | + * |
|
1073 | + * @return the login name of the authenticated user |
|
1074 | + */ |
|
1075 | + function getUser() { |
|
1076 | + global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
1077 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1078 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1079 | + } |
|
1080 | + if (!$PHPCAS_AUTH_CHECK_CALL['done']) { |
|
1081 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()'); |
|
1082 | + } |
|
1083 | + if (!$PHPCAS_AUTH_CHECK_CALL['result']) { |
|
1084 | + 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'); |
|
1085 | + } |
|
1086 | + return $PHPCAS_CLIENT->getUser(); |
|
1087 | + } |
|
1088 | + |
|
1089 | + /** |
|
1090 | + * This method returns the CAS user's login name. |
|
1091 | + * @warning should not be called only after phpCAS::forceAuthentication() |
|
1092 | + * or phpCAS::checkAuthentication(). |
|
1093 | + * |
|
1094 | + * @return the login name of the authenticated user |
|
1095 | + */ |
|
1096 | + function getAttributes() { |
|
1097 | + global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL; |
|
1098 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1099 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1100 | + } |
|
1101 | + if (!$PHPCAS_AUTH_CHECK_CALL['done']) { |
|
1102 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()'); |
|
1103 | + } |
|
1104 | + if (!$PHPCAS_AUTH_CHECK_CALL['result']) { |
|
1105 | + 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'); |
|
1106 | + } |
|
1107 | + return $PHPCAS_CLIENT->getAttributes(); |
|
1108 | + } |
|
1109 | + /** |
|
1110 | + * Handle logout requests. |
|
1111 | + */ |
|
1112 | + function handleLogoutRequests($check_client = true, $allowed_clients = false) { |
|
1113 | + global $PHPCAS_CLIENT; |
|
1114 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1115 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1116 | + } |
|
1117 | + return ($PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients)); |
|
1118 | + } |
|
1119 | + |
|
1120 | + /** |
|
1121 | + * This method returns the URL to be used to login. |
|
1122 | + * or phpCAS::isAuthenticated(). |
|
1123 | + * |
|
1124 | + * @return the login name of the authenticated user |
|
1125 | + */ |
|
1126 | + function getServerLoginURL() { |
|
1127 | + global $PHPCAS_CLIENT; |
|
1128 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1129 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1130 | + } |
|
1131 | + return $PHPCAS_CLIENT->getServerLoginURL(); |
|
1132 | + } |
|
1133 | + |
|
1134 | + /** |
|
1135 | + * Set the login URL of the CAS server. |
|
1136 | + * @param $url the login URL |
|
1137 | + * @since 0.4.21 by Wyman Chan |
|
1138 | + */ |
|
1139 | + function setServerLoginURL($url = '') { |
|
1140 | + global $PHPCAS_CLIENT; |
|
1141 | + phpCAS :: traceBegin(); |
|
1142 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1143 | + phpCAS :: error('this method should only be called after |
|
1144 | 1144 | ' . __CLASS__ . '::client()'); |
1145 | - } |
|
1146 | - if (gettype($url) != 'string') { |
|
1147 | - phpCAS :: error('type mismatched for parameter $url (should be |
|
1145 | + } |
|
1146 | + if (gettype($url) != 'string') { |
|
1147 | + phpCAS :: error('type mismatched for parameter $url (should be |
|
1148 | 1148 | `string\')'); |
1149 | - } |
|
1150 | - $PHPCAS_CLIENT->setServerLoginURL($url); |
|
1151 | - phpCAS :: traceEnd(); |
|
1152 | - } |
|
1153 | - |
|
1154 | - /** |
|
1155 | - * Set the serviceValidate URL of the CAS server. |
|
1156 | - * Used only in CAS 1.0 validations |
|
1157 | - * @param $url the serviceValidate URL |
|
1158 | - * @since 1.1.0 by Joachim Fritschi |
|
1159 | - */ |
|
1160 | - function setServerServiceValidateURL($url = '') { |
|
1161 | - global $PHPCAS_CLIENT; |
|
1162 | - phpCAS :: traceBegin(); |
|
1163 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1164 | - phpCAS :: error('this method should only be called after |
|
1149 | + } |
|
1150 | + $PHPCAS_CLIENT->setServerLoginURL($url); |
|
1151 | + phpCAS :: traceEnd(); |
|
1152 | + } |
|
1153 | + |
|
1154 | + /** |
|
1155 | + * Set the serviceValidate URL of the CAS server. |
|
1156 | + * Used only in CAS 1.0 validations |
|
1157 | + * @param $url the serviceValidate URL |
|
1158 | + * @since 1.1.0 by Joachim Fritschi |
|
1159 | + */ |
|
1160 | + function setServerServiceValidateURL($url = '') { |
|
1161 | + global $PHPCAS_CLIENT; |
|
1162 | + phpCAS :: traceBegin(); |
|
1163 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1164 | + phpCAS :: error('this method should only be called after |
|
1165 | 1165 | ' . __CLASS__ . '::client()'); |
1166 | - } |
|
1167 | - if (gettype($url) != 'string') { |
|
1168 | - phpCAS :: error('type mismatched for parameter $url (should be |
|
1166 | + } |
|
1167 | + if (gettype($url) != 'string') { |
|
1168 | + phpCAS :: error('type mismatched for parameter $url (should be |
|
1169 | 1169 | `string\')'); |
1170 | - } |
|
1171 | - $PHPCAS_CLIENT->setServerServiceValidateURL($url); |
|
1172 | - phpCAS :: traceEnd(); |
|
1173 | - } |
|
1174 | - |
|
1175 | - /** |
|
1176 | - * Set the proxyValidate URL of the CAS server. |
|
1177 | - * Used for all CAS 2.0 validations |
|
1178 | - * @param $url the proxyValidate URL |
|
1179 | - * @since 1.1.0 by Joachim Fritschi |
|
1180 | - */ |
|
1181 | - function setServerProxyValidateURL($url = '') { |
|
1182 | - global $PHPCAS_CLIENT; |
|
1183 | - phpCAS :: traceBegin(); |
|
1184 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1185 | - phpCAS :: error('this method should only be called after |
|
1170 | + } |
|
1171 | + $PHPCAS_CLIENT->setServerServiceValidateURL($url); |
|
1172 | + phpCAS :: traceEnd(); |
|
1173 | + } |
|
1174 | + |
|
1175 | + /** |
|
1176 | + * Set the proxyValidate URL of the CAS server. |
|
1177 | + * Used for all CAS 2.0 validations |
|
1178 | + * @param $url the proxyValidate URL |
|
1179 | + * @since 1.1.0 by Joachim Fritschi |
|
1180 | + */ |
|
1181 | + function setServerProxyValidateURL($url = '') { |
|
1182 | + global $PHPCAS_CLIENT; |
|
1183 | + phpCAS :: traceBegin(); |
|
1184 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1185 | + phpCAS :: error('this method should only be called after |
|
1186 | 1186 | ' . __CLASS__ . '::client()'); |
1187 | - } |
|
1188 | - if (gettype($url) != 'string') { |
|
1189 | - phpCAS :: error('type mismatched for parameter $url (should be |
|
1187 | + } |
|
1188 | + if (gettype($url) != 'string') { |
|
1189 | + phpCAS :: error('type mismatched for parameter $url (should be |
|
1190 | 1190 | `string\')'); |
1191 | - } |
|
1192 | - $PHPCAS_CLIENT->setServerProxyValidateURL($url); |
|
1193 | - phpCAS :: traceEnd(); |
|
1194 | - } |
|
1195 | - |
|
1196 | - /** |
|
1197 | - * Set the samlValidate URL of the CAS server. |
|
1198 | - * @param $url the samlValidate URL |
|
1199 | - * @since 1.1.0 by Joachim Fritschi |
|
1200 | - */ |
|
1201 | - function setServerSamlValidateURL($url = '') { |
|
1202 | - global $PHPCAS_CLIENT; |
|
1203 | - phpCAS :: traceBegin(); |
|
1204 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1205 | - phpCAS :: error('this method should only be called after |
|
1191 | + } |
|
1192 | + $PHPCAS_CLIENT->setServerProxyValidateURL($url); |
|
1193 | + phpCAS :: traceEnd(); |
|
1194 | + } |
|
1195 | + |
|
1196 | + /** |
|
1197 | + * Set the samlValidate URL of the CAS server. |
|
1198 | + * @param $url the samlValidate URL |
|
1199 | + * @since 1.1.0 by Joachim Fritschi |
|
1200 | + */ |
|
1201 | + function setServerSamlValidateURL($url = '') { |
|
1202 | + global $PHPCAS_CLIENT; |
|
1203 | + phpCAS :: traceBegin(); |
|
1204 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1205 | + phpCAS :: error('this method should only be called after |
|
1206 | 1206 | ' . __CLASS__ . '::client()'); |
1207 | - } |
|
1208 | - if (gettype($url) != 'string') { |
|
1209 | - phpCAS :: error('type mismatched for parameter $url (should be |
|
1207 | + } |
|
1208 | + if (gettype($url) != 'string') { |
|
1209 | + phpCAS :: error('type mismatched for parameter $url (should be |
|
1210 | 1210 | `string\')'); |
1211 | - } |
|
1212 | - $PHPCAS_CLIENT->setServerSamlValidateURL($url); |
|
1213 | - phpCAS :: traceEnd(); |
|
1214 | - } |
|
1215 | - |
|
1216 | - /** |
|
1217 | - * This method returns the URL to be used to login. |
|
1218 | - * or phpCAS::isAuthenticated(). |
|
1219 | - * |
|
1220 | - * @return the login name of the authenticated user |
|
1221 | - */ |
|
1222 | - function getServerLogoutURL() { |
|
1223 | - global $PHPCAS_CLIENT; |
|
1224 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1225 | - phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1226 | - } |
|
1227 | - return $PHPCAS_CLIENT->getServerLogoutURL(); |
|
1228 | - } |
|
1229 | - |
|
1230 | - /** |
|
1231 | - * Set the logout URL of the CAS server. |
|
1232 | - * @param $url the logout URL |
|
1233 | - * @since 0.4.21 by Wyman Chan |
|
1234 | - */ |
|
1235 | - function setServerLogoutURL($url = '') { |
|
1236 | - global $PHPCAS_CLIENT; |
|
1237 | - phpCAS :: traceBegin(); |
|
1238 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1239 | - phpCAS :: error('this method should only be called after |
|
1211 | + } |
|
1212 | + $PHPCAS_CLIENT->setServerSamlValidateURL($url); |
|
1213 | + phpCAS :: traceEnd(); |
|
1214 | + } |
|
1215 | + |
|
1216 | + /** |
|
1217 | + * This method returns the URL to be used to login. |
|
1218 | + * or phpCAS::isAuthenticated(). |
|
1219 | + * |
|
1220 | + * @return the login name of the authenticated user |
|
1221 | + */ |
|
1222 | + function getServerLogoutURL() { |
|
1223 | + global $PHPCAS_CLIENT; |
|
1224 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1225 | + phpCAS :: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()'); |
|
1226 | + } |
|
1227 | + return $PHPCAS_CLIENT->getServerLogoutURL(); |
|
1228 | + } |
|
1229 | + |
|
1230 | + /** |
|
1231 | + * Set the logout URL of the CAS server. |
|
1232 | + * @param $url the logout URL |
|
1233 | + * @since 0.4.21 by Wyman Chan |
|
1234 | + */ |
|
1235 | + function setServerLogoutURL($url = '') { |
|
1236 | + global $PHPCAS_CLIENT; |
|
1237 | + phpCAS :: traceBegin(); |
|
1238 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1239 | + phpCAS :: error('this method should only be called after |
|
1240 | 1240 | ' . __CLASS__ . '::client()'); |
1241 | - } |
|
1242 | - if (gettype($url) != 'string') { |
|
1243 | - phpCAS :: error('type mismatched for parameter $url (should be |
|
1241 | + } |
|
1242 | + if (gettype($url) != 'string') { |
|
1243 | + phpCAS :: error('type mismatched for parameter $url (should be |
|
1244 | 1244 | `string\')'); |
1245 | - } |
|
1246 | - $PHPCAS_CLIENT->setServerLogoutURL($url); |
|
1247 | - phpCAS :: traceEnd(); |
|
1248 | - } |
|
1249 | - |
|
1250 | - /** |
|
1251 | - * This method is used to logout from CAS. |
|
1252 | - * @params $params an array that contains the optional url and service parameters that will be passed to the CAS server |
|
1253 | - * @public |
|
1254 | - */ |
|
1255 | - function logout($params = "") { |
|
1256 | - global $PHPCAS_CLIENT; |
|
1257 | - phpCAS :: traceBegin(); |
|
1258 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1259 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1260 | - } |
|
1261 | - $parsedParams = array (); |
|
1262 | - if ($params != "") { |
|
1263 | - if (is_string($params)) { |
|
1264 | - phpCAS :: error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead'); |
|
1265 | - } |
|
1266 | - if (!is_array($params)) { |
|
1267 | - phpCAS :: error('type mismatched for parameter $params (should be `array\')'); |
|
1268 | - } |
|
1269 | - foreach ($params as $key => $value) { |
|
1270 | - if ($key != "service" && $key != "url") { |
|
1271 | - phpCAS :: error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\''); |
|
1272 | - } |
|
1273 | - $parsedParams[$key] = $value; |
|
1274 | - } |
|
1275 | - } |
|
1276 | - $PHPCAS_CLIENT->logout($parsedParams); |
|
1277 | - // never reached |
|
1278 | - phpCAS :: traceEnd(); |
|
1279 | - } |
|
1280 | - |
|
1281 | - /** |
|
1282 | - * This method is used to logout from CAS. Halts by redirecting to the CAS server. |
|
1283 | - * @param $service a URL that will be transmitted to the CAS server |
|
1284 | - */ |
|
1285 | - function logoutWithRedirectService($service) { |
|
1286 | - global $PHPCAS_CLIENT; |
|
1287 | - phpCAS :: traceBegin(); |
|
1288 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1289 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1290 | - } |
|
1291 | - if (!is_string($service)) { |
|
1292 | - phpCAS :: error('type mismatched for parameter $service (should be `string\')'); |
|
1293 | - } |
|
1294 | - $PHPCAS_CLIENT->logout(array ( |
|
1295 | - "service" => $service |
|
1296 | - )); |
|
1297 | - // never reached |
|
1298 | - phpCAS :: traceEnd(); |
|
1299 | - } |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * This method is used to logout from CAS. Halts by redirecting to the CAS server. |
|
1303 | - * @param $url a URL that will be transmitted to the CAS server |
|
1304 | - */ |
|
1305 | - function logoutWithUrl($url) { |
|
1306 | - global $PHPCAS_CLIENT; |
|
1307 | - phpCAS :: traceBegin(); |
|
1308 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1309 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1310 | - } |
|
1311 | - if (!is_string($url)) { |
|
1312 | - phpCAS :: error('type mismatched for parameter $url (should be `string\')'); |
|
1313 | - } |
|
1314 | - $PHPCAS_CLIENT->logout(array ( |
|
1315 | - "url" => $url |
|
1316 | - )); |
|
1317 | - // never reached |
|
1318 | - phpCAS :: traceEnd(); |
|
1319 | - } |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * This method is used to logout from CAS. Halts by redirecting to the CAS server. |
|
1323 | - * @param $service a URL that will be transmitted to the CAS server |
|
1324 | - * @param $url a URL that will be transmitted to the CAS server |
|
1325 | - */ |
|
1326 | - function logoutWithRedirectServiceAndUrl($service, $url) { |
|
1327 | - global $PHPCAS_CLIENT; |
|
1328 | - phpCAS :: traceBegin(); |
|
1329 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1330 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1331 | - } |
|
1332 | - if (!is_string($service)) { |
|
1333 | - phpCAS :: error('type mismatched for parameter $service (should be `string\')'); |
|
1334 | - } |
|
1335 | - if (!is_string($url)) { |
|
1336 | - phpCAS :: error('type mismatched for parameter $url (should be `string\')'); |
|
1337 | - } |
|
1338 | - $PHPCAS_CLIENT->logout(array ( |
|
1339 | - "service" => $service, |
|
1340 | - "url" => $url |
|
1341 | - )); |
|
1342 | - // never reached |
|
1343 | - phpCAS :: traceEnd(); |
|
1344 | - } |
|
1345 | - |
|
1346 | - /** |
|
1347 | - * Set the fixed URL that will be used by the CAS server to transmit the PGT. |
|
1348 | - * When this method is not called, a phpCAS script uses its own URL for the callback. |
|
1349 | - * |
|
1350 | - * @param $url the URL |
|
1351 | - */ |
|
1352 | - function setFixedCallbackURL($url = '') { |
|
1353 | - global $PHPCAS_CLIENT; |
|
1354 | - phpCAS :: traceBegin(); |
|
1355 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1356 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
1357 | - } |
|
1358 | - if (!$PHPCAS_CLIENT->isProxy()) { |
|
1359 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
1360 | - } |
|
1361 | - if (gettype($url) != 'string') { |
|
1362 | - phpCAS :: error('type mismatched for parameter $url (should be `string\')'); |
|
1363 | - } |
|
1364 | - $PHPCAS_CLIENT->setCallbackURL($url); |
|
1365 | - phpCAS :: traceEnd(); |
|
1366 | - } |
|
1367 | - |
|
1368 | - /** |
|
1369 | - * Set the fixed URL that will be set as the CAS service parameter. When this |
|
1370 | - * method is not called, a phpCAS script uses its own URL. |
|
1371 | - * |
|
1372 | - * @param $url the URL |
|
1373 | - */ |
|
1374 | - function setFixedServiceURL($url) { |
|
1375 | - global $PHPCAS_CLIENT; |
|
1376 | - phpCAS :: traceBegin(); |
|
1377 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1378 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
1379 | - } |
|
1380 | - if (gettype($url) != 'string') { |
|
1381 | - phpCAS :: error('type mismatched for parameter $url (should be `string\')'); |
|
1382 | - } |
|
1383 | - $PHPCAS_CLIENT->setURL($url); |
|
1384 | - phpCAS :: traceEnd(); |
|
1385 | - } |
|
1386 | - |
|
1387 | - /** |
|
1388 | - * Get the URL that is set as the CAS service parameter. |
|
1389 | - */ |
|
1390 | - function getServiceURL() { |
|
1391 | - global $PHPCAS_CLIENT; |
|
1392 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1393 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
1394 | - } |
|
1395 | - return ($PHPCAS_CLIENT->getURL()); |
|
1396 | - } |
|
1397 | - |
|
1398 | - /** |
|
1399 | - * Retrieve a Proxy Ticket from the CAS server. |
|
1400 | - */ |
|
1401 | - function retrievePT($target_service, & $err_code, & $err_msg) { |
|
1402 | - global $PHPCAS_CLIENT; |
|
1403 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1404 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
1405 | - } |
|
1406 | - if (gettype($target_service) != 'string') { |
|
1407 | - phpCAS :: error('type mismatched for parameter $target_service(should be `string\')'); |
|
1408 | - } |
|
1409 | - return ($PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg)); |
|
1410 | - } |
|
1411 | - |
|
1412 | - /** |
|
1413 | - * Set the certificate of the CAS server. |
|
1414 | - * |
|
1415 | - * @param $cert the PEM certificate |
|
1416 | - */ |
|
1417 | - function setCasServerCert($cert) { |
|
1418 | - global $PHPCAS_CLIENT; |
|
1419 | - phpCAS :: traceBegin(); |
|
1420 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1421 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1422 | - } |
|
1423 | - if (gettype($cert) != 'string') { |
|
1424 | - phpCAS :: error('type mismatched for parameter $cert (should be `string\')'); |
|
1425 | - } |
|
1426 | - $PHPCAS_CLIENT->setCasServerCert($cert); |
|
1427 | - phpCAS :: traceEnd(); |
|
1428 | - } |
|
1429 | - |
|
1430 | - /** |
|
1431 | - * Set the certificate of the CAS server CA. |
|
1432 | - * |
|
1433 | - * @param $cert the CA certificate |
|
1434 | - */ |
|
1435 | - function setCasServerCACert($cert) { |
|
1436 | - global $PHPCAS_CLIENT; |
|
1437 | - phpCAS :: traceBegin(); |
|
1438 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1439 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1440 | - } |
|
1441 | - if (gettype($cert) != 'string') { |
|
1442 | - phpCAS :: error('type mismatched for parameter $cert (should be `string\')'); |
|
1443 | - } |
|
1444 | - $PHPCAS_CLIENT->setCasServerCACert($cert); |
|
1445 | - phpCAS :: traceEnd(); |
|
1446 | - } |
|
1447 | - |
|
1448 | - /** |
|
1449 | - * Set no SSL validation for the CAS server. |
|
1450 | - */ |
|
1451 | - function setNoCasServerValidation() { |
|
1452 | - global $PHPCAS_CLIENT; |
|
1453 | - phpCAS :: traceBegin(); |
|
1454 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1455 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1456 | - } |
|
1457 | - $PHPCAS_CLIENT->setNoCasServerValidation(); |
|
1458 | - phpCAS :: traceEnd(); |
|
1459 | - } |
|
1460 | - |
|
1461 | - /** @} */ |
|
1462 | - |
|
1463 | - /** |
|
1464 | - * Change CURL options. |
|
1465 | - * CURL is used to connect through HTTPS to CAS server |
|
1466 | - * @param $key the option key |
|
1467 | - * @param $value the value to set |
|
1468 | - */ |
|
1469 | - function setExtraCurlOption($key, $value) { |
|
1470 | - global $PHPCAS_CLIENT; |
|
1471 | - phpCAS :: traceBegin(); |
|
1472 | - if (!is_object($PHPCAS_CLIENT)) { |
|
1473 | - phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1474 | - } |
|
1475 | - $PHPCAS_CLIENT->setExtraCurlOption($key, $value); |
|
1476 | - phpCAS :: traceEnd(); |
|
1477 | - } |
|
1245 | + } |
|
1246 | + $PHPCAS_CLIENT->setServerLogoutURL($url); |
|
1247 | + phpCAS :: traceEnd(); |
|
1248 | + } |
|
1249 | + |
|
1250 | + /** |
|
1251 | + * This method is used to logout from CAS. |
|
1252 | + * @params $params an array that contains the optional url and service parameters that will be passed to the CAS server |
|
1253 | + * @public |
|
1254 | + */ |
|
1255 | + function logout($params = "") { |
|
1256 | + global $PHPCAS_CLIENT; |
|
1257 | + phpCAS :: traceBegin(); |
|
1258 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1259 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1260 | + } |
|
1261 | + $parsedParams = array (); |
|
1262 | + if ($params != "") { |
|
1263 | + if (is_string($params)) { |
|
1264 | + phpCAS :: error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead'); |
|
1265 | + } |
|
1266 | + if (!is_array($params)) { |
|
1267 | + phpCAS :: error('type mismatched for parameter $params (should be `array\')'); |
|
1268 | + } |
|
1269 | + foreach ($params as $key => $value) { |
|
1270 | + if ($key != "service" && $key != "url") { |
|
1271 | + phpCAS :: error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\''); |
|
1272 | + } |
|
1273 | + $parsedParams[$key] = $value; |
|
1274 | + } |
|
1275 | + } |
|
1276 | + $PHPCAS_CLIENT->logout($parsedParams); |
|
1277 | + // never reached |
|
1278 | + phpCAS :: traceEnd(); |
|
1279 | + } |
|
1280 | + |
|
1281 | + /** |
|
1282 | + * This method is used to logout from CAS. Halts by redirecting to the CAS server. |
|
1283 | + * @param $service a URL that will be transmitted to the CAS server |
|
1284 | + */ |
|
1285 | + function logoutWithRedirectService($service) { |
|
1286 | + global $PHPCAS_CLIENT; |
|
1287 | + phpCAS :: traceBegin(); |
|
1288 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1289 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1290 | + } |
|
1291 | + if (!is_string($service)) { |
|
1292 | + phpCAS :: error('type mismatched for parameter $service (should be `string\')'); |
|
1293 | + } |
|
1294 | + $PHPCAS_CLIENT->logout(array ( |
|
1295 | + "service" => $service |
|
1296 | + )); |
|
1297 | + // never reached |
|
1298 | + phpCAS :: traceEnd(); |
|
1299 | + } |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * This method is used to logout from CAS. Halts by redirecting to the CAS server. |
|
1303 | + * @param $url a URL that will be transmitted to the CAS server |
|
1304 | + */ |
|
1305 | + function logoutWithUrl($url) { |
|
1306 | + global $PHPCAS_CLIENT; |
|
1307 | + phpCAS :: traceBegin(); |
|
1308 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1309 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1310 | + } |
|
1311 | + if (!is_string($url)) { |
|
1312 | + phpCAS :: error('type mismatched for parameter $url (should be `string\')'); |
|
1313 | + } |
|
1314 | + $PHPCAS_CLIENT->logout(array ( |
|
1315 | + "url" => $url |
|
1316 | + )); |
|
1317 | + // never reached |
|
1318 | + phpCAS :: traceEnd(); |
|
1319 | + } |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * This method is used to logout from CAS. Halts by redirecting to the CAS server. |
|
1323 | + * @param $service a URL that will be transmitted to the CAS server |
|
1324 | + * @param $url a URL that will be transmitted to the CAS server |
|
1325 | + */ |
|
1326 | + function logoutWithRedirectServiceAndUrl($service, $url) { |
|
1327 | + global $PHPCAS_CLIENT; |
|
1328 | + phpCAS :: traceBegin(); |
|
1329 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1330 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1331 | + } |
|
1332 | + if (!is_string($service)) { |
|
1333 | + phpCAS :: error('type mismatched for parameter $service (should be `string\')'); |
|
1334 | + } |
|
1335 | + if (!is_string($url)) { |
|
1336 | + phpCAS :: error('type mismatched for parameter $url (should be `string\')'); |
|
1337 | + } |
|
1338 | + $PHPCAS_CLIENT->logout(array ( |
|
1339 | + "service" => $service, |
|
1340 | + "url" => $url |
|
1341 | + )); |
|
1342 | + // never reached |
|
1343 | + phpCAS :: traceEnd(); |
|
1344 | + } |
|
1345 | + |
|
1346 | + /** |
|
1347 | + * Set the fixed URL that will be used by the CAS server to transmit the PGT. |
|
1348 | + * When this method is not called, a phpCAS script uses its own URL for the callback. |
|
1349 | + * |
|
1350 | + * @param $url the URL |
|
1351 | + */ |
|
1352 | + function setFixedCallbackURL($url = '') { |
|
1353 | + global $PHPCAS_CLIENT; |
|
1354 | + phpCAS :: traceBegin(); |
|
1355 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1356 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
1357 | + } |
|
1358 | + if (!$PHPCAS_CLIENT->isProxy()) { |
|
1359 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
1360 | + } |
|
1361 | + if (gettype($url) != 'string') { |
|
1362 | + phpCAS :: error('type mismatched for parameter $url (should be `string\')'); |
|
1363 | + } |
|
1364 | + $PHPCAS_CLIENT->setCallbackURL($url); |
|
1365 | + phpCAS :: traceEnd(); |
|
1366 | + } |
|
1367 | + |
|
1368 | + /** |
|
1369 | + * Set the fixed URL that will be set as the CAS service parameter. When this |
|
1370 | + * method is not called, a phpCAS script uses its own URL. |
|
1371 | + * |
|
1372 | + * @param $url the URL |
|
1373 | + */ |
|
1374 | + function setFixedServiceURL($url) { |
|
1375 | + global $PHPCAS_CLIENT; |
|
1376 | + phpCAS :: traceBegin(); |
|
1377 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1378 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
1379 | + } |
|
1380 | + if (gettype($url) != 'string') { |
|
1381 | + phpCAS :: error('type mismatched for parameter $url (should be `string\')'); |
|
1382 | + } |
|
1383 | + $PHPCAS_CLIENT->setURL($url); |
|
1384 | + phpCAS :: traceEnd(); |
|
1385 | + } |
|
1386 | + |
|
1387 | + /** |
|
1388 | + * Get the URL that is set as the CAS service parameter. |
|
1389 | + */ |
|
1390 | + function getServiceURL() { |
|
1391 | + global $PHPCAS_CLIENT; |
|
1392 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1393 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
1394 | + } |
|
1395 | + return ($PHPCAS_CLIENT->getURL()); |
|
1396 | + } |
|
1397 | + |
|
1398 | + /** |
|
1399 | + * Retrieve a Proxy Ticket from the CAS server. |
|
1400 | + */ |
|
1401 | + function retrievePT($target_service, & $err_code, & $err_msg) { |
|
1402 | + global $PHPCAS_CLIENT; |
|
1403 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1404 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::proxy()'); |
|
1405 | + } |
|
1406 | + if (gettype($target_service) != 'string') { |
|
1407 | + phpCAS :: error('type mismatched for parameter $target_service(should be `string\')'); |
|
1408 | + } |
|
1409 | + return ($PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg)); |
|
1410 | + } |
|
1411 | + |
|
1412 | + /** |
|
1413 | + * Set the certificate of the CAS server. |
|
1414 | + * |
|
1415 | + * @param $cert the PEM certificate |
|
1416 | + */ |
|
1417 | + function setCasServerCert($cert) { |
|
1418 | + global $PHPCAS_CLIENT; |
|
1419 | + phpCAS :: traceBegin(); |
|
1420 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1421 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1422 | + } |
|
1423 | + if (gettype($cert) != 'string') { |
|
1424 | + phpCAS :: error('type mismatched for parameter $cert (should be `string\')'); |
|
1425 | + } |
|
1426 | + $PHPCAS_CLIENT->setCasServerCert($cert); |
|
1427 | + phpCAS :: traceEnd(); |
|
1428 | + } |
|
1429 | + |
|
1430 | + /** |
|
1431 | + * Set the certificate of the CAS server CA. |
|
1432 | + * |
|
1433 | + * @param $cert the CA certificate |
|
1434 | + */ |
|
1435 | + function setCasServerCACert($cert) { |
|
1436 | + global $PHPCAS_CLIENT; |
|
1437 | + phpCAS :: traceBegin(); |
|
1438 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1439 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1440 | + } |
|
1441 | + if (gettype($cert) != 'string') { |
|
1442 | + phpCAS :: error('type mismatched for parameter $cert (should be `string\')'); |
|
1443 | + } |
|
1444 | + $PHPCAS_CLIENT->setCasServerCACert($cert); |
|
1445 | + phpCAS :: traceEnd(); |
|
1446 | + } |
|
1447 | + |
|
1448 | + /** |
|
1449 | + * Set no SSL validation for the CAS server. |
|
1450 | + */ |
|
1451 | + function setNoCasServerValidation() { |
|
1452 | + global $PHPCAS_CLIENT; |
|
1453 | + phpCAS :: traceBegin(); |
|
1454 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1455 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1456 | + } |
|
1457 | + $PHPCAS_CLIENT->setNoCasServerValidation(); |
|
1458 | + phpCAS :: traceEnd(); |
|
1459 | + } |
|
1460 | + |
|
1461 | + /** @} */ |
|
1462 | + |
|
1463 | + /** |
|
1464 | + * Change CURL options. |
|
1465 | + * CURL is used to connect through HTTPS to CAS server |
|
1466 | + * @param $key the option key |
|
1467 | + * @param $value the value to set |
|
1468 | + */ |
|
1469 | + function setExtraCurlOption($key, $value) { |
|
1470 | + global $PHPCAS_CLIENT; |
|
1471 | + phpCAS :: traceBegin(); |
|
1472 | + if (!is_object($PHPCAS_CLIENT)) { |
|
1473 | + phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()'); |
|
1474 | + } |
|
1475 | + $PHPCAS_CLIENT->setExtraCurlOption($key, $value); |
|
1476 | + phpCAS :: traceEnd(); |
|
1477 | + } |
|
1478 | 1478 | |
1479 | 1479 | } |
1480 | 1480 |
@@ -5,7 +5,7 @@ |
||
5 | 5 | $url = api_get_path(WEB_PATH).'main/auth/conditional_login/complete_phone_number.php'; |
6 | 6 | |
7 | 7 | if (! isset($_SESSION['conditional_login']['uid'])) |
8 | - die("Not Authorised"); |
|
8 | + die("Not Authorised"); |
|
9 | 9 | ?> |
10 | 10 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
11 | 11 | <html lang="fr" xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml"> |
@@ -32,135 +32,135 @@ |
||
32 | 32 | abstract class FacebookSignedRequestFromInputHelper |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var \Facebook\Entities\SignedRequest|null |
|
37 | - */ |
|
38 | - protected $signedRequest; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string the app id |
|
42 | - */ |
|
43 | - protected $appId; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var string the app secret |
|
47 | - */ |
|
48 | - protected $appSecret; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var string|null Random string to prevent CSRF. |
|
52 | - */ |
|
53 | - public $state = null; |
|
54 | - |
|
55 | - /** |
|
56 | - * Initialize the helper and process available signed request data. |
|
57 | - * |
|
58 | - * @param string|null $appId |
|
59 | - * @param string|null $appSecret |
|
60 | - */ |
|
61 | - public function __construct($appId = null, $appSecret = null) |
|
62 | - { |
|
35 | + /** |
|
36 | + * @var \Facebook\Entities\SignedRequest|null |
|
37 | + */ |
|
38 | + protected $signedRequest; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string the app id |
|
42 | + */ |
|
43 | + protected $appId; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var string the app secret |
|
47 | + */ |
|
48 | + protected $appSecret; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var string|null Random string to prevent CSRF. |
|
52 | + */ |
|
53 | + public $state = null; |
|
54 | + |
|
55 | + /** |
|
56 | + * Initialize the helper and process available signed request data. |
|
57 | + * |
|
58 | + * @param string|null $appId |
|
59 | + * @param string|null $appSecret |
|
60 | + */ |
|
61 | + public function __construct($appId = null, $appSecret = null) |
|
62 | + { |
|
63 | 63 | $this->appId = FacebookSession::_getTargetAppId($appId); |
64 | 64 | $this->appSecret = FacebookSession::_getTargetAppSecret($appSecret); |
65 | 65 | |
66 | 66 | $this->instantiateSignedRequest(); |
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Instantiates a new SignedRequest entity. |
|
71 | - * |
|
72 | - * @param string|null |
|
73 | - */ |
|
74 | - public function instantiateSignedRequest($rawSignedRequest = null) |
|
75 | - { |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Instantiates a new SignedRequest entity. |
|
71 | + * |
|
72 | + * @param string|null |
|
73 | + */ |
|
74 | + public function instantiateSignedRequest($rawSignedRequest = null) |
|
75 | + { |
|
76 | 76 | $rawSignedRequest = $rawSignedRequest ?: $this->getRawSignedRequest(); |
77 | 77 | |
78 | 78 | if (!$rawSignedRequest) { |
79 | - return; |
|
79 | + return; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $this->signedRequest = new SignedRequest($rawSignedRequest, $this->state, $this->appSecret); |
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Instantiates a FacebookSession from the signed request from input. |
|
87 | - * |
|
88 | - * @return FacebookSession|null |
|
89 | - */ |
|
90 | - public function getSession() |
|
91 | - { |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Instantiates a FacebookSession from the signed request from input. |
|
87 | + * |
|
88 | + * @return FacebookSession|null |
|
89 | + */ |
|
90 | + public function getSession() |
|
91 | + { |
|
92 | 92 | if ($this->signedRequest && $this->signedRequest->hasOAuthData()) { |
93 | - return FacebookSession::newSessionFromSignedRequest($this->signedRequest); |
|
93 | + return FacebookSession::newSessionFromSignedRequest($this->signedRequest); |
|
94 | 94 | } |
95 | 95 | return null; |
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Returns the SignedRequest entity. |
|
100 | - * |
|
101 | - * @return \Facebook\Entities\SignedRequest|null |
|
102 | - */ |
|
103 | - public function getSignedRequest() |
|
104 | - { |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Returns the SignedRequest entity. |
|
100 | + * |
|
101 | + * @return \Facebook\Entities\SignedRequest|null |
|
102 | + */ |
|
103 | + public function getSignedRequest() |
|
104 | + { |
|
105 | 105 | return $this->signedRequest; |
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns the user_id if available. |
|
110 | - * |
|
111 | - * @return string|null |
|
112 | - */ |
|
113 | - public function getUserId() |
|
114 | - { |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns the user_id if available. |
|
110 | + * |
|
111 | + * @return string|null |
|
112 | + */ |
|
113 | + public function getUserId() |
|
114 | + { |
|
115 | 115 | return $this->signedRequest ? $this->signedRequest->getUserId() : null; |
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Get raw signed request from input. |
|
120 | - * |
|
121 | - * @return string|null |
|
122 | - */ |
|
123 | - abstract public function getRawSignedRequest(); |
|
124 | - |
|
125 | - /** |
|
126 | - * Get raw signed request from GET input. |
|
127 | - * |
|
128 | - * @return string|null |
|
129 | - */ |
|
130 | - public function getRawSignedRequestFromGet() |
|
131 | - { |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Get raw signed request from input. |
|
120 | + * |
|
121 | + * @return string|null |
|
122 | + */ |
|
123 | + abstract public function getRawSignedRequest(); |
|
124 | + |
|
125 | + /** |
|
126 | + * Get raw signed request from GET input. |
|
127 | + * |
|
128 | + * @return string|null |
|
129 | + */ |
|
130 | + public function getRawSignedRequestFromGet() |
|
131 | + { |
|
132 | 132 | if (isset($_GET['signed_request'])) { |
133 | - return $_GET['signed_request']; |
|
133 | + return $_GET['signed_request']; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | return null; |
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Get raw signed request from POST input. |
|
141 | - * |
|
142 | - * @return string|null |
|
143 | - */ |
|
144 | - public function getRawSignedRequestFromPost() |
|
145 | - { |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Get raw signed request from POST input. |
|
141 | + * |
|
142 | + * @return string|null |
|
143 | + */ |
|
144 | + public function getRawSignedRequestFromPost() |
|
145 | + { |
|
146 | 146 | if (isset($_POST['signed_request'])) { |
147 | - return $_POST['signed_request']; |
|
147 | + return $_POST['signed_request']; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | return null; |
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Get raw signed request from cookie set from the Javascript SDK. |
|
155 | - * |
|
156 | - * @return string|null |
|
157 | - */ |
|
158 | - public function getRawSignedRequestFromCookie() |
|
159 | - { |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Get raw signed request from cookie set from the Javascript SDK. |
|
155 | + * |
|
156 | + * @return string|null |
|
157 | + */ |
|
158 | + public function getRawSignedRequestFromCookie() |
|
159 | + { |
|
160 | 160 | if (isset($_COOKIE['fbsr_' . $this->appId])) { |
161 | - return $_COOKIE['fbsr_' . $this->appId]; |
|
161 | + return $_COOKIE['fbsr_' . $this->appId]; |
|
162 | 162 | } |
163 | 163 | return null; |
164 | - } |
|
164 | + } |
|
165 | 165 | |
166 | 166 | } |
@@ -31,34 +31,34 @@ |
||
31 | 31 | class GraphPage extends GraphObject |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * Returns the ID for the user's page as a string if present. |
|
36 | - * |
|
37 | - * @return string|null |
|
38 | - */ |
|
39 | - public function getId() |
|
40 | - { |
|
34 | + /** |
|
35 | + * Returns the ID for the user's page as a string if present. |
|
36 | + * |
|
37 | + * @return string|null |
|
38 | + */ |
|
39 | + public function getId() |
|
40 | + { |
|
41 | 41 | return $this->getProperty('id'); |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Returns the Category for the user's page as a string if present. |
|
46 | - * |
|
47 | - * @return string|null |
|
48 | - */ |
|
49 | - public function getCategory() |
|
50 | - { |
|
44 | + /** |
|
45 | + * Returns the Category for the user's page as a string if present. |
|
46 | + * |
|
47 | + * @return string|null |
|
48 | + */ |
|
49 | + public function getCategory() |
|
50 | + { |
|
51 | 51 | return $this->getProperty('category'); |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns the Name of the user's page as a string if present. |
|
56 | - * |
|
57 | - * @return string|null |
|
58 | - */ |
|
59 | - public function getName() |
|
60 | - { |
|
54 | + /** |
|
55 | + * Returns the Name of the user's page as a string if present. |
|
56 | + * |
|
57 | + * @return string|null |
|
58 | + */ |
|
59 | + public function getName() |
|
60 | + { |
|
61 | 61 | return $this->getProperty('name'); |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | \ No newline at end of file |
@@ -32,293 +32,293 @@ |
||
32 | 32 | class FacebookRedirectLoginHelper |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var string The application id |
|
37 | - */ |
|
38 | - private $appId; |
|
35 | + /** |
|
36 | + * @var string The application id |
|
37 | + */ |
|
38 | + private $appId; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @var string The application secret |
|
42 | - */ |
|
43 | - private $appSecret; |
|
40 | + /** |
|
41 | + * @var string The application secret |
|
42 | + */ |
|
43 | + private $appSecret; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @var string The redirect URL for the application |
|
47 | - */ |
|
48 | - private $redirectUrl; |
|
45 | + /** |
|
46 | + * @var string The redirect URL for the application |
|
47 | + */ |
|
48 | + private $redirectUrl; |
|
49 | 49 | |
50 | - /** |
|
51 | - * @var string Prefix to use for session variables |
|
52 | - */ |
|
53 | - private $sessionPrefix = 'FBRLH_'; |
|
50 | + /** |
|
51 | + * @var string Prefix to use for session variables |
|
52 | + */ |
|
53 | + private $sessionPrefix = 'FBRLH_'; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var string State token for CSRF validation |
|
57 | - */ |
|
58 | - protected $state; |
|
55 | + /** |
|
56 | + * @var string State token for CSRF validation |
|
57 | + */ |
|
58 | + protected $state; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @var boolean Toggle for PHP session status check |
|
62 | - */ |
|
63 | - protected $checkForSessionStatus = true; |
|
60 | + /** |
|
61 | + * @var boolean Toggle for PHP session status check |
|
62 | + */ |
|
63 | + protected $checkForSessionStatus = true; |
|
64 | 64 | |
65 | - /** |
|
66 | - * Constructs a RedirectLoginHelper for a given appId and redirectUrl. |
|
67 | - * |
|
68 | - * @param string $redirectUrl The URL Facebook should redirect users to |
|
69 | - * after login |
|
70 | - * @param string $appId The application id |
|
71 | - * @param string $appSecret The application secret |
|
72 | - */ |
|
73 | - public function __construct($redirectUrl, $appId = null, $appSecret = null) |
|
74 | - { |
|
65 | + /** |
|
66 | + * Constructs a RedirectLoginHelper for a given appId and redirectUrl. |
|
67 | + * |
|
68 | + * @param string $redirectUrl The URL Facebook should redirect users to |
|
69 | + * after login |
|
70 | + * @param string $appId The application id |
|
71 | + * @param string $appSecret The application secret |
|
72 | + */ |
|
73 | + public function __construct($redirectUrl, $appId = null, $appSecret = null) |
|
74 | + { |
|
75 | 75 | $this->appId = FacebookSession::_getTargetAppId($appId); |
76 | 76 | $this->appSecret = FacebookSession::_getTargetAppSecret($appSecret); |
77 | 77 | $this->redirectUrl = $redirectUrl; |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Stores CSRF state and returns a URL to which the user should be sent to |
|
82 | - * in order to continue the login process with Facebook. The |
|
83 | - * provided redirectUrl should invoke the handleRedirect method. |
|
84 | - * |
|
85 | - * @param array $scope List of permissions to request during login |
|
86 | - * @param string $version Optional Graph API version if not default (v2.0) |
|
87 | - * @param boolean $displayAsPopup Indicate if the page will be displayed as a popup |
|
88 | - * |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getLoginUrl($scope = array(), $version = null, $displayAsPopup = false) |
|
92 | - { |
|
80 | + /** |
|
81 | + * Stores CSRF state and returns a URL to which the user should be sent to |
|
82 | + * in order to continue the login process with Facebook. The |
|
83 | + * provided redirectUrl should invoke the handleRedirect method. |
|
84 | + * |
|
85 | + * @param array $scope List of permissions to request during login |
|
86 | + * @param string $version Optional Graph API version if not default (v2.0) |
|
87 | + * @param boolean $displayAsPopup Indicate if the page will be displayed as a popup |
|
88 | + * |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getLoginUrl($scope = array(), $version = null, $displayAsPopup = false) |
|
92 | + { |
|
93 | 93 | |
94 | 94 | $version = ($version ?: FacebookRequest::GRAPH_API_VERSION); |
95 | 95 | $this->state = $this->random(16); |
96 | 96 | $this->storeState($this->state); |
97 | 97 | |
98 | 98 | $params = array( |
99 | - 'client_id' => $this->appId, |
|
100 | - 'redirect_uri' => $this->redirectUrl, |
|
101 | - 'state' => $this->state, |
|
102 | - 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, |
|
103 | - 'scope' => implode(',', $scope) |
|
99 | + 'client_id' => $this->appId, |
|
100 | + 'redirect_uri' => $this->redirectUrl, |
|
101 | + 'state' => $this->state, |
|
102 | + 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, |
|
103 | + 'scope' => implode(',', $scope) |
|
104 | 104 | ); |
105 | 105 | |
106 | 106 | if ($displayAsPopup) |
107 | 107 | { |
108 | - $params['display'] = 'popup'; |
|
108 | + $params['display'] = 'popup'; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | return 'https://www.facebook.com/' . $version . '/dialog/oauth?' . |
112 | - http_build_query($params, null, '&'); |
|
113 | - } |
|
112 | + http_build_query($params, null, '&'); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Returns a URL to which the user should be sent to re-request permissions. |
|
117 | - * |
|
118 | - * @param array $scope List of permissions to re-request |
|
119 | - * @param string $version Optional Graph API version if not default (v2.0) |
|
120 | - * |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function getReRequestUrl($scope = array(), $version = null) |
|
124 | - { |
|
115 | + /** |
|
116 | + * Returns a URL to which the user should be sent to re-request permissions. |
|
117 | + * |
|
118 | + * @param array $scope List of permissions to re-request |
|
119 | + * @param string $version Optional Graph API version if not default (v2.0) |
|
120 | + * |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function getReRequestUrl($scope = array(), $version = null) |
|
124 | + { |
|
125 | 125 | $version = ($version ?: FacebookRequest::GRAPH_API_VERSION); |
126 | 126 | $this->state = $this->random(16); |
127 | 127 | $this->storeState($this->state); |
128 | 128 | $params = array( |
129 | - 'client_id' => $this->appId, |
|
130 | - 'redirect_uri' => $this->redirectUrl, |
|
131 | - 'state' => $this->state, |
|
132 | - 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, |
|
133 | - 'auth_type' => 'rerequest', |
|
134 | - 'scope' => implode(',', $scope) |
|
129 | + 'client_id' => $this->appId, |
|
130 | + 'redirect_uri' => $this->redirectUrl, |
|
131 | + 'state' => $this->state, |
|
132 | + 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, |
|
133 | + 'auth_type' => 'rerequest', |
|
134 | + 'scope' => implode(',', $scope) |
|
135 | 135 | ); |
136 | 136 | return 'https://www.facebook.com/' . $version . '/dialog/oauth?' . |
137 | - http_build_query($params, null, '&'); |
|
138 | - } |
|
137 | + http_build_query($params, null, '&'); |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Returns the URL to send the user in order to log out of Facebook. |
|
142 | - * |
|
143 | - * @param FacebookSession $session The session that will be logged out |
|
144 | - * @param string $next The url Facebook should redirect the user to after |
|
145 | - * a successful logout |
|
146 | - * |
|
147 | - * @return string |
|
148 | - * |
|
149 | - * @throws FacebookSDKException |
|
150 | - */ |
|
151 | - public function getLogoutUrl(FacebookSession $session, $next) |
|
152 | - { |
|
140 | + /** |
|
141 | + * Returns the URL to send the user in order to log out of Facebook. |
|
142 | + * |
|
143 | + * @param FacebookSession $session The session that will be logged out |
|
144 | + * @param string $next The url Facebook should redirect the user to after |
|
145 | + * a successful logout |
|
146 | + * |
|
147 | + * @return string |
|
148 | + * |
|
149 | + * @throws FacebookSDKException |
|
150 | + */ |
|
151 | + public function getLogoutUrl(FacebookSession $session, $next) |
|
152 | + { |
|
153 | 153 | if ($session->getAccessToken()->isAppSession()) { |
154 | - throw new FacebookSDKException( |
|
154 | + throw new FacebookSDKException( |
|
155 | 155 | 'Cannot generate a Logout URL with an App Session.', 722 |
156 | - ); |
|
156 | + ); |
|
157 | 157 | } |
158 | 158 | $params = array( |
159 | - 'next' => $next, |
|
160 | - 'access_token' => $session->getToken() |
|
159 | + 'next' => $next, |
|
160 | + 'access_token' => $session->getToken() |
|
161 | 161 | ); |
162 | 162 | return 'https://www.facebook.com/logout.php?' . http_build_query($params, null, '&'); |
163 | - } |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Handles a response from Facebook, including a CSRF check, and returns a |
|
167 | - * FacebookSession. |
|
168 | - * |
|
169 | - * @return FacebookSession|null |
|
170 | - */ |
|
171 | - public function getSessionFromRedirect() |
|
172 | - { |
|
165 | + /** |
|
166 | + * Handles a response from Facebook, including a CSRF check, and returns a |
|
167 | + * FacebookSession. |
|
168 | + * |
|
169 | + * @return FacebookSession|null |
|
170 | + */ |
|
171 | + public function getSessionFromRedirect() |
|
172 | + { |
|
173 | 173 | $this->loadState(); |
174 | 174 | if ($this->isValidRedirect()) { |
175 | 175 | |
176 | - $params = array( |
|
176 | + $params = array( |
|
177 | 177 | 'client_id' => FacebookSession::_getTargetAppId($this->appId), |
178 | 178 | 'redirect_uri' => $this->redirectUrl, |
179 | 179 | 'client_secret' => |
180 | - FacebookSession::_getTargetAppSecret($this->appSecret), |
|
180 | + FacebookSession::_getTargetAppSecret($this->appSecret), |
|
181 | 181 | 'code' => $this->getCode() |
182 | - ); |
|
182 | + ); |
|
183 | 183 | |
184 | - $response = (new FacebookRequest( |
|
184 | + $response = (new FacebookRequest( |
|
185 | 185 | FacebookSession::newAppSession($this->appId, $this->appSecret), |
186 | 186 | 'GET', |
187 | 187 | '/oauth/access_token', |
188 | 188 | $params |
189 | - ))->execute()->getResponse(); |
|
189 | + ))->execute()->getResponse(); |
|
190 | 190 | |
191 | - if (isset($response['access_token'])) { |
|
191 | + if (isset($response['access_token'])) { |
|
192 | 192 | return new FacebookSession($response['access_token']); |
193 | - } |
|
193 | + } |
|
194 | 194 | } |
195 | 195 | return null; |
196 | - } |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
199 | - * Check if a redirect has a valid state. |
|
200 | - * |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - protected function isValidRedirect() |
|
204 | - { |
|
198 | + /** |
|
199 | + * Check if a redirect has a valid state. |
|
200 | + * |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + protected function isValidRedirect() |
|
204 | + { |
|
205 | 205 | return $this->getCode() && isset($_GET['state']) |
206 | 206 | && $_GET['state'] == $this->state; |
207 | - } |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Return the code. |
|
211 | - * |
|
212 | - * @return string|null |
|
213 | - */ |
|
214 | - protected function getCode() |
|
215 | - { |
|
209 | + /** |
|
210 | + * Return the code. |
|
211 | + * |
|
212 | + * @return string|null |
|
213 | + */ |
|
214 | + protected function getCode() |
|
215 | + { |
|
216 | 216 | |
217 | 217 | return isset($_GET['code']) ? $_GET['code'] : null; |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * Stores a state string in session storage for CSRF protection. |
|
222 | - * Developers should subclass and override this method if they want to store |
|
223 | - * this state in a different location. |
|
224 | - * |
|
225 | - * @param string $state |
|
226 | - * |
|
227 | - * @throws FacebookSDKException |
|
228 | - */ |
|
229 | - protected function storeState($state) |
|
230 | - { |
|
220 | + /** |
|
221 | + * Stores a state string in session storage for CSRF protection. |
|
222 | + * Developers should subclass and override this method if they want to store |
|
223 | + * this state in a different location. |
|
224 | + * |
|
225 | + * @param string $state |
|
226 | + * |
|
227 | + * @throws FacebookSDKException |
|
228 | + */ |
|
229 | + protected function storeState($state) |
|
230 | + { |
|
231 | 231 | if ($this->checkForSessionStatus === true |
232 | 232 | && session_status() !== PHP_SESSION_ACTIVE) { |
233 | - throw new FacebookSDKException( |
|
233 | + throw new FacebookSDKException( |
|
234 | 234 | 'Session not active, could not store state.', 720 |
235 | - ); |
|
235 | + ); |
|
236 | 236 | } |
237 | 237 | $_SESSION[$this->sessionPrefix . 'state'] = $state; |
238 | - } |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * Loads a state string from session storage for CSRF validation. May return |
|
242 | - * null if no object exists. Developers should subclass and override this |
|
243 | - * method if they want to load the state from a different location. |
|
244 | - * |
|
245 | - * @return string|null |
|
246 | - * |
|
247 | - * @throws FacebookSDKException |
|
248 | - */ |
|
249 | - protected function loadState() |
|
250 | - { |
|
240 | + /** |
|
241 | + * Loads a state string from session storage for CSRF validation. May return |
|
242 | + * null if no object exists. Developers should subclass and override this |
|
243 | + * method if they want to load the state from a different location. |
|
244 | + * |
|
245 | + * @return string|null |
|
246 | + * |
|
247 | + * @throws FacebookSDKException |
|
248 | + */ |
|
249 | + protected function loadState() |
|
250 | + { |
|
251 | 251 | |
252 | 252 | if ($this->checkForSessionStatus === true |
253 | 253 | && session_status() !== PHP_SESSION_ACTIVE) { |
254 | - throw new FacebookSDKException( |
|
254 | + throw new FacebookSDKException( |
|
255 | 255 | 'Session not active, could not load state.', 721 |
256 | - ); |
|
256 | + ); |
|
257 | 257 | } |
258 | 258 | if (isset($_SESSION[$this->sessionPrefix . 'state'])) { |
259 | - $this->state = $_SESSION[$this->sessionPrefix . 'state']; |
|
260 | - return $this->state; |
|
259 | + $this->state = $_SESSION[$this->sessionPrefix . 'state']; |
|
260 | + return $this->state; |
|
261 | 261 | } |
262 | 262 | return null; |
263 | - } |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * Generate a cryptographically secure pseudrandom number |
|
267 | - * |
|
268 | - * @param integer $bytes - number of bytes to return |
|
269 | - * |
|
270 | - * @return string |
|
271 | - * |
|
272 | - * @throws FacebookSDKException |
|
273 | - * |
|
274 | - * @todo Support Windows platforms |
|
275 | - */ |
|
276 | - public function random($bytes) |
|
277 | - { |
|
265 | + /** |
|
266 | + * Generate a cryptographically secure pseudrandom number |
|
267 | + * |
|
268 | + * @param integer $bytes - number of bytes to return |
|
269 | + * |
|
270 | + * @return string |
|
271 | + * |
|
272 | + * @throws FacebookSDKException |
|
273 | + * |
|
274 | + * @todo Support Windows platforms |
|
275 | + */ |
|
276 | + public function random($bytes) |
|
277 | + { |
|
278 | 278 | if (!is_numeric($bytes)) { |
279 | - throw new FacebookSDKException( |
|
279 | + throw new FacebookSDKException( |
|
280 | 280 | "random() expects an integer" |
281 | - ); |
|
281 | + ); |
|
282 | 282 | } |
283 | 283 | if ($bytes < 1) { |
284 | - throw new FacebookSDKException( |
|
284 | + throw new FacebookSDKException( |
|
285 | 285 | "random() expects an integer greater than zero" |
286 | - ); |
|
286 | + ); |
|
287 | 287 | } |
288 | 288 | $buf = ''; |
289 | 289 | // http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/ |
290 | 290 | if (!ini_get('open_basedir') |
291 | 291 | && is_readable('/dev/urandom')) { |
292 | - $fp = fopen('/dev/urandom', 'rb'); |
|
293 | - if ($fp !== FALSE) { |
|
292 | + $fp = fopen('/dev/urandom', 'rb'); |
|
293 | + if ($fp !== FALSE) { |
|
294 | 294 | $buf = fread($fp, $bytes); |
295 | 295 | fclose($fp); |
296 | 296 | if($buf !== FALSE) { |
297 | - return bin2hex($buf); |
|
297 | + return bin2hex($buf); |
|
298 | + } |
|
298 | 299 | } |
299 | - } |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | if (function_exists('mcrypt_create_iv')) { |
303 | 303 | $buf = mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM); |
304 | 304 | if ($buf !== FALSE) { |
305 | - return bin2hex($buf); |
|
305 | + return bin2hex($buf); |
|
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
309 | 309 | while (strlen($buf) < $bytes) { |
310 | - $buf .= md5(uniqid(mt_rand(), true), true); |
|
311 | - // We are appending raw binary |
|
310 | + $buf .= md5(uniqid(mt_rand(), true), true); |
|
311 | + // We are appending raw binary |
|
312 | 312 | } |
313 | 313 | return bin2hex(substr($buf, 0, $bytes)); |
314 | - } |
|
314 | + } |
|
315 | 315 | |
316 | - /** |
|
317 | - * Disables the session_status() check when using $_SESSION |
|
318 | - */ |
|
319 | - public function disableSessionStatusCheck() |
|
320 | - { |
|
316 | + /** |
|
317 | + * Disables the session_status() check when using $_SESSION |
|
318 | + */ |
|
319 | + public function disableSessionStatusCheck() |
|
320 | + { |
|
321 | 321 | $this->checkForSessionStatus = false; |
322 | - } |
|
322 | + } |
|
323 | 323 | |
324 | 324 | } |
@@ -32,29 +32,29 @@ |
||
32 | 32 | class FacebookCanvasLoginHelper extends FacebookSignedRequestFromInputHelper |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Returns the app data value. |
|
37 | - * |
|
38 | - * @return mixed|null |
|
39 | - */ |
|
40 | - public function getAppData() |
|
41 | - { |
|
35 | + /** |
|
36 | + * Returns the app data value. |
|
37 | + * |
|
38 | + * @return mixed|null |
|
39 | + */ |
|
40 | + public function getAppData() |
|
41 | + { |
|
42 | 42 | return $this->signedRequest ? $this->signedRequest->get('app_data') : null; |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Get raw signed request from POST. |
|
47 | - * |
|
48 | - * @return string|null |
|
49 | - */ |
|
50 | - public function getRawSignedRequest() |
|
51 | - { |
|
45 | + /** |
|
46 | + * Get raw signed request from POST. |
|
47 | + * |
|
48 | + * @return string|null |
|
49 | + */ |
|
50 | + public function getRawSignedRequest() |
|
51 | + { |
|
52 | 52 | $rawSignedRequest = $this->getRawSignedRequestFromPost(); |
53 | 53 | if ($rawSignedRequest) { |
54 | - return $rawSignedRequest; |
|
54 | + return $rawSignedRequest; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | return null; |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | 60 | } |
@@ -31,72 +31,72 @@ |
||
31 | 31 | class FacebookPageTabHelper extends FacebookCanvasLoginHelper |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * @var array|null |
|
36 | - */ |
|
37 | - protected $pageData; |
|
34 | + /** |
|
35 | + * @var array|null |
|
36 | + */ |
|
37 | + protected $pageData; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Initialize the helper and process available signed request data. |
|
41 | - * |
|
42 | - * @param string|null $appId |
|
43 | - * @param string|null $appSecret |
|
44 | - */ |
|
45 | - public function __construct($appId = null, $appSecret = null) |
|
46 | - { |
|
39 | + /** |
|
40 | + * Initialize the helper and process available signed request data. |
|
41 | + * |
|
42 | + * @param string|null $appId |
|
43 | + * @param string|null $appSecret |
|
44 | + */ |
|
45 | + public function __construct($appId = null, $appSecret = null) |
|
46 | + { |
|
47 | 47 | parent::__construct($appId, $appSecret); |
48 | 48 | |
49 | 49 | if (!$this->signedRequest) { |
50 | - return; |
|
50 | + return; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | $this->pageData = $this->signedRequest->get('page'); |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Returns a value from the page data. |
|
58 | - * |
|
59 | - * @param string $key |
|
60 | - * @param mixed|null $default |
|
61 | - * |
|
62 | - * @return mixed|null |
|
63 | - */ |
|
64 | - public function getPageData($key, $default = null) |
|
65 | - { |
|
56 | + /** |
|
57 | + * Returns a value from the page data. |
|
58 | + * |
|
59 | + * @param string $key |
|
60 | + * @param mixed|null $default |
|
61 | + * |
|
62 | + * @return mixed|null |
|
63 | + */ |
|
64 | + public function getPageData($key, $default = null) |
|
65 | + { |
|
66 | 66 | if (isset($this->pageData[$key])) { |
67 | - return $this->pageData[$key]; |
|
67 | + return $this->pageData[$key]; |
|
68 | 68 | } |
69 | 69 | return $default; |
70 | - } |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Returns true if the page is liked by the user. |
|
74 | - * |
|
75 | - * @return boolean |
|
76 | - */ |
|
77 | - public function isLiked() |
|
78 | - { |
|
72 | + /** |
|
73 | + * Returns true if the page is liked by the user. |
|
74 | + * |
|
75 | + * @return boolean |
|
76 | + */ |
|
77 | + public function isLiked() |
|
78 | + { |
|
79 | 79 | return $this->getPageData('liked') === true; |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Returns true if the user is an admin. |
|
84 | - * |
|
85 | - * @return boolean |
|
86 | - */ |
|
87 | - public function isAdmin() |
|
88 | - { |
|
82 | + /** |
|
83 | + * Returns true if the user is an admin. |
|
84 | + * |
|
85 | + * @return boolean |
|
86 | + */ |
|
87 | + public function isAdmin() |
|
88 | + { |
|
89 | 89 | return $this->getPageData('admin') === true; |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Returns the page id if available. |
|
94 | - * |
|
95 | - * @return string|null |
|
96 | - */ |
|
97 | - public function getPageId() |
|
98 | - { |
|
92 | + /** |
|
93 | + * Returns the page id if available. |
|
94 | + * |
|
95 | + * @return string|null |
|
96 | + */ |
|
97 | + public function getPageId() |
|
98 | + { |
|
99 | 99 | return $this->getPageData('id'); |
100 | - } |
|
100 | + } |
|
101 | 101 | |
102 | 102 | } |
@@ -32,84 +32,84 @@ |
||
32 | 32 | class GraphSessionInfo extends GraphObject |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Returns the application id the token was issued for. |
|
37 | - * |
|
38 | - * @return string|null |
|
39 | - */ |
|
40 | - public function getAppId() |
|
41 | - { |
|
35 | + /** |
|
36 | + * Returns the application id the token was issued for. |
|
37 | + * |
|
38 | + * @return string|null |
|
39 | + */ |
|
40 | + public function getAppId() |
|
41 | + { |
|
42 | 42 | return $this->getProperty('app_id'); |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Returns the application name the token was issued for. |
|
47 | - * |
|
48 | - * @return string|null |
|
49 | - */ |
|
50 | - public function getApplication() |
|
51 | - { |
|
45 | + /** |
|
46 | + * Returns the application name the token was issued for. |
|
47 | + * |
|
48 | + * @return string|null |
|
49 | + */ |
|
50 | + public function getApplication() |
|
51 | + { |
|
52 | 52 | return $this->getProperty('application'); |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Returns the date & time that the token expires. |
|
57 | - * |
|
58 | - * @return \DateTime|null |
|
59 | - */ |
|
60 | - public function getExpiresAt() |
|
61 | - { |
|
55 | + /** |
|
56 | + * Returns the date & time that the token expires. |
|
57 | + * |
|
58 | + * @return \DateTime|null |
|
59 | + */ |
|
60 | + public function getExpiresAt() |
|
61 | + { |
|
62 | 62 | $stamp = $this->getProperty('expires_at'); |
63 | 63 | if ($stamp) { |
64 | - return (new \DateTime())->setTimestamp($stamp); |
|
64 | + return (new \DateTime())->setTimestamp($stamp); |
|
65 | 65 | } else { |
66 | - return null; |
|
66 | + return null; |
|
67 | + } |
|
67 | 68 | } |
68 | - } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Returns whether the token is valid. |
|
72 | - * |
|
73 | - * @return boolean |
|
74 | - */ |
|
75 | - public function isValid() |
|
76 | - { |
|
70 | + /** |
|
71 | + * Returns whether the token is valid. |
|
72 | + * |
|
73 | + * @return boolean |
|
74 | + */ |
|
75 | + public function isValid() |
|
76 | + { |
|
77 | 77 | return $this->getProperty('is_valid'); |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Returns the date & time the token was issued at. |
|
82 | - * |
|
83 | - * @return \DateTime|null |
|
84 | - */ |
|
85 | - public function getIssuedAt() |
|
86 | - { |
|
80 | + /** |
|
81 | + * Returns the date & time the token was issued at. |
|
82 | + * |
|
83 | + * @return \DateTime|null |
|
84 | + */ |
|
85 | + public function getIssuedAt() |
|
86 | + { |
|
87 | 87 | $stamp = $this->getProperty('issued_at'); |
88 | 88 | if ($stamp) { |
89 | - return (new \DateTime())->setTimestamp($stamp); |
|
89 | + return (new \DateTime())->setTimestamp($stamp); |
|
90 | 90 | } else { |
91 | - return null; |
|
91 | + return null; |
|
92 | + } |
|
92 | 93 | } |
93 | - } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Returns the scope permissions associated with the token. |
|
97 | - * |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - public function getScopes() |
|
101 | - { |
|
95 | + /** |
|
96 | + * Returns the scope permissions associated with the token. |
|
97 | + * |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + public function getScopes() |
|
101 | + { |
|
102 | 102 | return $this->getPropertyAsArray('scopes'); |
103 | - } |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Returns the login id of the user associated with the token. |
|
107 | - * |
|
108 | - * @return string|null |
|
109 | - */ |
|
110 | - public function getId() |
|
111 | - { |
|
105 | + /** |
|
106 | + * Returns the login id of the user associated with the token. |
|
107 | + * |
|
108 | + * @return string|null |
|
109 | + */ |
|
110 | + public function getId() |
|
111 | + { |
|
112 | 112 | return $this->getProperty('user_id'); |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | 115 | } |
116 | 116 | \ No newline at end of file |
@@ -32,58 +32,58 @@ discard block |
||
32 | 32 | class FacebookRequestException extends FacebookSDKException |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var int Status code for the response causing the exception |
|
37 | - */ |
|
38 | - private $statusCode; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string Raw response |
|
42 | - */ |
|
43 | - private $rawResponse; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var array Decoded response |
|
47 | - */ |
|
48 | - private $responseData; |
|
49 | - |
|
50 | - /** |
|
51 | - * Creates a FacebookRequestException. |
|
52 | - * |
|
53 | - * @param string $rawResponse The raw response from the Graph API |
|
54 | - * @param array $responseData The decoded response from the Graph API |
|
55 | - * @param int $statusCode |
|
56 | - */ |
|
57 | - public function __construct($rawResponse, $responseData, $statusCode) |
|
58 | - { |
|
35 | + /** |
|
36 | + * @var int Status code for the response causing the exception |
|
37 | + */ |
|
38 | + private $statusCode; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string Raw response |
|
42 | + */ |
|
43 | + private $rawResponse; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var array Decoded response |
|
47 | + */ |
|
48 | + private $responseData; |
|
49 | + |
|
50 | + /** |
|
51 | + * Creates a FacebookRequestException. |
|
52 | + * |
|
53 | + * @param string $rawResponse The raw response from the Graph API |
|
54 | + * @param array $responseData The decoded response from the Graph API |
|
55 | + * @param int $statusCode |
|
56 | + */ |
|
57 | + public function __construct($rawResponse, $responseData, $statusCode) |
|
58 | + { |
|
59 | 59 | $this->rawResponse = $rawResponse; |
60 | 60 | $this->statusCode = $statusCode; |
61 | 61 | $this->responseData = self::convertToArray($responseData); |
62 | 62 | parent::__construct( |
63 | - $this->get('message', 'Unknown Exception'), $this->get('code', -1), null |
|
63 | + $this->get('message', 'Unknown Exception'), $this->get('code', -1), null |
|
64 | 64 | ); |
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Process an error payload from the Graph API and return the appropriate |
|
69 | - * exception subclass. |
|
70 | - * |
|
71 | - * @param string $raw the raw response from the Graph API |
|
72 | - * @param array $data the decoded response from the Graph API |
|
73 | - * @param int $statusCode the HTTP response code |
|
74 | - * |
|
75 | - * @return FacebookRequestException |
|
76 | - */ |
|
77 | - public static function create($raw, $data, $statusCode) |
|
78 | - { |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Process an error payload from the Graph API and return the appropriate |
|
69 | + * exception subclass. |
|
70 | + * |
|
71 | + * @param string $raw the raw response from the Graph API |
|
72 | + * @param array $data the decoded response from the Graph API |
|
73 | + * @param int $statusCode the HTTP response code |
|
74 | + * |
|
75 | + * @return FacebookRequestException |
|
76 | + */ |
|
77 | + public static function create($raw, $data, $statusCode) |
|
78 | + { |
|
79 | 79 | $data = self::convertToArray($data); |
80 | 80 | if (!isset($data['error']['code']) && isset($data['code'])) { |
81 | - $data = array('error' => $data); |
|
81 | + $data = array('error' => $data); |
|
82 | 82 | } |
83 | 83 | $code = (isset($data['error']['code']) ? $data['error']['code'] : null); |
84 | 84 | |
85 | 85 | if (isset($data['error']['error_subcode'])) { |
86 | - switch ($data['error']['error_subcode']) { |
|
86 | + switch ($data['error']['error_subcode']) { |
|
87 | 87 | // Other authentication issues |
88 | 88 | case 458: |
89 | 89 | case 459: |
@@ -92,131 +92,131 @@ discard block |
||
92 | 92 | case 464: |
93 | 93 | case 467: |
94 | 94 | return new FacebookAuthorizationException($raw, $data, $statusCode); |
95 | - break; |
|
96 | - } |
|
95 | + break; |
|
96 | + } |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | switch ($code) { |
100 | - // Login status or token expired, revoked, or invalid |
|
101 | - case 100: |
|
100 | + // Login status or token expired, revoked, or invalid |
|
101 | + case 100: |
|
102 | 102 | case 102: |
103 | 103 | case 190: |
104 | 104 | return new FacebookAuthorizationException($raw, $data, $statusCode); |
105 | 105 | break; |
106 | 106 | |
107 | - // Server issue, possible downtime |
|
108 | - case 1: |
|
107 | + // Server issue, possible downtime |
|
108 | + case 1: |
|
109 | 109 | case 2: |
110 | 110 | return new FacebookServerException($raw, $data, $statusCode); |
111 | 111 | break; |
112 | 112 | |
113 | - // API Throttling |
|
114 | - case 4: |
|
113 | + // API Throttling |
|
114 | + case 4: |
|
115 | 115 | case 17: |
116 | 116 | case 341: |
117 | 117 | return new FacebookThrottleException($raw, $data, $statusCode); |
118 | 118 | break; |
119 | 119 | |
120 | - // Duplicate Post |
|
121 | - case 506: |
|
120 | + // Duplicate Post |
|
121 | + case 506: |
|
122 | 122 | return new FacebookClientException($raw, $data, $statusCode); |
123 | 123 | break; |
124 | 124 | } |
125 | 125 | |
126 | 126 | // Missing Permissions |
127 | 127 | if ($code == 10 || ($code >= 200 && $code <= 299)) { |
128 | - return new FacebookPermissionException($raw, $data, $statusCode); |
|
128 | + return new FacebookPermissionException($raw, $data, $statusCode); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | // OAuth authentication error |
132 | 132 | if (isset($data['error']['type']) |
133 | 133 | and $data['error']['type'] === 'OAuthException') { |
134 | - return new FacebookAuthorizationException($raw, $data, $statusCode); |
|
134 | + return new FacebookAuthorizationException($raw, $data, $statusCode); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | // All others |
138 | 138 | return new FacebookOtherException($raw, $data, $statusCode); |
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Checks isset and returns that or a default value. |
|
143 | - * |
|
144 | - * @param string $key |
|
145 | - * @param mixed $default |
|
146 | - * |
|
147 | - * @return mixed |
|
148 | - */ |
|
149 | - private function get($key, $default = null) |
|
150 | - { |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Checks isset and returns that or a default value. |
|
143 | + * |
|
144 | + * @param string $key |
|
145 | + * @param mixed $default |
|
146 | + * |
|
147 | + * @return mixed |
|
148 | + */ |
|
149 | + private function get($key, $default = null) |
|
150 | + { |
|
151 | 151 | if (isset($this->responseData['error'][$key])) { |
152 | - return $this->responseData['error'][$key]; |
|
152 | + return $this->responseData['error'][$key]; |
|
153 | 153 | } |
154 | 154 | return $default; |
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Returns the HTTP status code |
|
159 | - * |
|
160 | - * @return int |
|
161 | - */ |
|
162 | - public function getHttpStatusCode() |
|
163 | - { |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Returns the HTTP status code |
|
159 | + * |
|
160 | + * @return int |
|
161 | + */ |
|
162 | + public function getHttpStatusCode() |
|
163 | + { |
|
164 | 164 | return $this->statusCode; |
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Returns the sub-error code |
|
169 | - * |
|
170 | - * @return int |
|
171 | - */ |
|
172 | - public function getSubErrorCode() |
|
173 | - { |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Returns the sub-error code |
|
169 | + * |
|
170 | + * @return int |
|
171 | + */ |
|
172 | + public function getSubErrorCode() |
|
173 | + { |
|
174 | 174 | return $this->get('error_subcode', -1); |
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Returns the error type |
|
179 | - * |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function getErrorType() |
|
183 | - { |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Returns the error type |
|
179 | + * |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function getErrorType() |
|
183 | + { |
|
184 | 184 | return $this->get('type', ''); |
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Returns the raw response used to create the exception. |
|
189 | - * |
|
190 | - * @return string |
|
191 | - */ |
|
192 | - public function getRawResponse() |
|
193 | - { |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Returns the raw response used to create the exception. |
|
189 | + * |
|
190 | + * @return string |
|
191 | + */ |
|
192 | + public function getRawResponse() |
|
193 | + { |
|
194 | 194 | return $this->rawResponse; |
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Returns the decoded response used to create the exception. |
|
199 | - * |
|
200 | - * @return array |
|
201 | - */ |
|
202 | - public function getResponse() |
|
203 | - { |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Returns the decoded response used to create the exception. |
|
199 | + * |
|
200 | + * @return array |
|
201 | + */ |
|
202 | + public function getResponse() |
|
203 | + { |
|
204 | 204 | return $this->responseData; |
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Converts a stdClass object to an array |
|
209 | - * |
|
210 | - * @param mixed $object |
|
211 | - * |
|
212 | - * @return array |
|
213 | - */ |
|
214 | - private static function convertToArray($object) |
|
215 | - { |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Converts a stdClass object to an array |
|
209 | + * |
|
210 | + * @param mixed $object |
|
211 | + * |
|
212 | + * @return array |
|
213 | + */ |
|
214 | + private static function convertToArray($object) |
|
215 | + { |
|
216 | 216 | if ($object instanceof \stdClass) { |
217 | - return get_object_vars($object); |
|
217 | + return get_object_vars($object); |
|
218 | 218 | } |
219 | 219 | return $object; |
220 | - } |
|
220 | + } |
|
221 | 221 | |
222 | 222 | } |
223 | 223 | \ No newline at end of file |