Source for file ForceAuthAction.class.php

Documentation is available at ForceAuthAction.class.php

  1. <?php
  2. /**
  3. * @since 8/4/06
  4. * @package polyphony.AbstractActions
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: ForceAuthAction.class.php,v 1.4 2007/09/19 14:04:41 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/AbstractActions/Action.class.php");
  13.  
  14.  
  15. /**
  16. * The ForceAuthAction forces token collection via HTTP Authentication to allow
  17. * authentication outside of the context of a browser Harmoni-Application
  18. * environment. For instance, this can be used to authenticate an RSS reader for
  19. * an RSS feed, or to prompt for authentication for a file that is directly linked
  20. * from another website.
  21. *
  22. * @since 8/4/06
  23. * @package polyphony.AbstractActions
  24. *
  25. * @copyright Copyright &copy; 2005, Middlebury College
  26. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  27. *
  28. * @version $Id: ForceAuthAction.class.php,v 1.4 2007/09/19 14:04:41 adamfranco Exp $
  29. */
  30. class ForceAuthAction
  31. extends Action
  32. {
  33. /**
  34. * Check Authorizations
  35. *
  36. * @return boolean
  37. * @access public
  38. * @since 4/26/05
  39. */
  40. function isAuthorizedToExecute () {
  41. if ($this->isExecutionAuthorized()) {
  42. return true;
  43. }
  44. // if we aren't authorized, check if we are authenticated
  45. // and try to re-authorize after that.
  46. if (!$this->isAuthenticated()) {
  47. $this->authenticate();
  48. if ($this->isAuthenticated())
  49. return $this->isExecutionAuthorized();
  50. }
  51. return false;
  52. }
  53. /**
  54. * Loop through the authentication types and see if the user is authenticated.
  55. *
  56. * @return boolean
  57. * @access public
  58. * @since 8/4/06
  59. */
  60. function isAuthenticated () {
  61. $isAuthenticated = FALSE;
  62. $authN = Services::getService("AuthN");
  63. // authenticate.
  64. $authTypes =$authN->getAuthenticationTypes();
  65. while ($authTypes->hasNext()) {
  66. $authType =$authTypes->next();
  67. // If they are authenticated, quit
  68. if ($authN->isUserAuthenticated($authType)) {
  69. return TRUE;
  70. }
  71. }
  72. return FALSE;
  73. }
  74. /**
  75. * Loop through the authentication types and try to authenticate the user.
  76. *
  77. * @return void
  78. * @access public
  79. * @since 8/4/06
  80. */
  81. function authenticate () {
  82. $authN = Services::getService("AuthN");
  83. // Reconfigure the AuthNManager to use HTTP Auth rather than forms
  84. // :: Start the AuthenticationManager OSID Impl.
  85. $configuration = new ConfigurationProperties;
  86. $tokenCollectors = array();
  87. $authNTypes =$authN->getAuthenticationTypes();
  88. while ($authNTypes->hasNext()) {
  89. $tokenCollectors[serialize($authNTypes->next())] =
  90. new HTTPAuthNamePassTokenCollector($this->getRelm(),
  91. $this->getCancelFunction());
  92. }
  93. $configuration->addProperty('token_collectors', $tokenCollectors);
  94. $authN->assignConfiguration($configuration);
  95. // Authenticate with HTTP Authentication.
  96. $harmoni = Harmoni::instance();
  97. $isAuthenticated = FALSE;
  98. $authTypes =$authN->getAuthenticationTypes();
  99. while ($authTypes->hasNext() && !$isAuthenticated) {
  100. $authType =$authTypes->next();
  101. // Try authenticating with this type
  102. $authN->authenticateUser($authType);
  103. // If they are authenticated, quit
  104. if ($authN->isUserAuthenticated($authType)) {
  105. $isAuthenticated = TRUE;
  106. }
  107. }
  108. }
  109. /**
  110. * Check Authorizations
  111. *
  112. * @return boolean
  113. * @access public
  114. * @since 8/4/06
  115. */
  116. function isExecutionAuthorized () {
  117. throwError(new Error(__CLASS__."::".__FUNCTION__."() must be overridded in child classes."));
  118. }
  119. /**
  120. * Answer the HTTP Authentication 'Relm' to present to the user for authentication.
  121. *
  122. * @return mixed string or null
  123. * @access public
  124. * @since 8/7/06
  125. */
  126. function getRelm () {
  127. return null; // Override for custom relm.
  128. }
  129. /**
  130. * Answer the cancel function for this action, to use if the user hits
  131. * the 'cancel' button in the http authentication dialog.
  132. *
  133. * @return mixed string or null
  134. * @access public
  135. * @since 8/7/06
  136. */
  137. function getCancelFunction () {
  138. return null; // Override for custom functions.
  139. }
  140. }
  141.  
  142. ?>

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