Source for file HTTPAuthNamePassTokenCollector.class.php

Documentation is available at HTTPAuthNamePassTokenCollector.class.php

  1. <?php
  2. /**
  3. * @package harmoni.osid_v2.authentication
  4. *
  5. * @copyright Copyright &copy; 2005, Middlebury College
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  7. *
  8. * @version $Id: HTTPAuthNamePassTokenCollector.class.php,v 1.3 2006/11/30 22:02:18 adamfranco Exp $
  9. */
  10.  
  11. require_once(dirname(__FILE__)."/NamePassTokenCollector.abstract.php");
  12.  
  13. /**
  14. * The HTTPAuthNamePassTokenCollector prompts a user for their name and password
  15. * by sending HTTP Authenticatio headers to the user.
  16. *
  17. * @package harmoni.osid_v2.authentication
  18. *
  19. * @copyright Copyright &copy; 2005, Middlebury College
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  21. *
  22. * @version $Id: HTTPAuthNamePassTokenCollector.class.php,v 1.3 2006/11/30 22:02:18 adamfranco Exp $
  23. */
  24. class HTTPAuthNamePassTokenCollector
  25. extends NamePassTokenCollector
  26. {
  27. /**
  28. * Constructor, pass params
  29. *
  30. * @param <##>
  31. * @return <##>
  32. * @access public
  33. * @since 8/7/06
  34. */
  35. function HTTPAuthNamePassTokenCollector ($relm = null, $cancelFunction = null)
  36. {
  37. if (is_null($relm))
  38. $this->relm = "Harmoni-protected Realm";
  39. else
  40. $this->relm = $relm;
  41. if (is_null($cancelFunction))
  42. $this->cancelFunction = '$this->printCancelMessage();';
  43. else
  44. $this->cancelFunction = $cancelFunction;
  45. }
  46. /**
  47. * Run the token collection sequence involving prompting for and collecting
  48. * tokens.
  49. *
  50. * @param string $authTypeKey Allows the token colletor to know whether it
  51. * has prompted for tokens for the particular auth type yet, allowing
  52. * one prompting to return tokens for each authtype in an execution cycle.
  53. * @return mixed
  54. * @access public
  55. * @since 3/18/05
  56. */
  57. function collectTokens ($authTypeKey) {
  58. if ((isset($_SESSION['__LastLoginTokens '.$authTypeKey])
  59. && md5($_SERVER['PHP_AUTH_USER'].$_SERVER['PHP_AUTH_PW'])
  60. == $_SESSION['__LastLoginTokens '.$authTypeKey])
  61. || !isset($_SERVER['PHP_AUTH_USER']) || !$_SERVER['PHP_AUTH_USER'])
  62. {
  63. $this->prompt();
  64. }
  65. $_SESSION['__LastLoginTokens '.$authTypeKey]
  66. = md5($_SERVER['PHP_AUTH_USER'].$_SERVER['PHP_AUTH_PW']);
  67. return $this->collect();
  68. }
  69. /**
  70. * Prompt the user to supply their tokens
  71. *
  72. * @return void
  73. * @access public
  74. * @since 3/16/05
  75. */
  76. function prompt () {
  77. header("WWW-Authenticate: Basic realm=\"".$this->relm."\"");
  78. header('HTTP/1.0 401 Unauthorized');
  79. eval($this->cancelFunction);
  80. exit;
  81. }
  82. /**
  83. * Collect the name that the user may have supplied, Reply NULL if none
  84. * are found.
  85. *
  86. * @return mixed
  87. * @access public
  88. * @since 3/16/05
  89. */
  90. function collectName () {
  91. return $_SERVER['PHP_AUTH_USER'];
  92. }
  93. /**
  94. * Collect the password that the user may have supplied, Reply NULL if none
  95. * are found.
  96. *
  97. * @return mixed
  98. * @access public
  99. * @since 3/16/05
  100. */
  101. function collectPassword () {
  102. return $_SERVER['PHP_AUTH_PW'];
  103. }
  104. /**
  105. * Print out a message if the user hits cancel in the HTTP authentication
  106. * dialog.
  107. *
  108. * @return void
  109. * @access public
  110. * @since 8/7/06
  111. */
  112. function printCancelMessage () {
  113. print _("The Username/Password pair that you entered were not valid. <br />Please go back and try again.");
  114. }
  115. }
  116.  
  117. ?>

Documentation generated on Wed, 19 Sep 2007 10:24:35 -0400 by phpDocumentor 1.3.0RC3