Source for file AuthNMethodManager.class.php

Documentation is available at AuthNMethodManager.class.php

  1. <?php
  2. /**
  3. * @package harmoni.osid_v2.agentmanagement.authn_methods
  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: AuthNMethodManager.class.php,v 1.8 2007/09/04 20:25:37 adamfranco Exp $
  9. */
  10.  
  11. /**
  12. * The AuthNMethodManager handles the management of Authentication Types and the
  13. * AuthNMethods that correspond to those types. Neither the AuthNMethodManager nor
  14. * AuthNMethods maintain any information about authentication states. They simply
  15. * provide the means of checking that authentication when desired.
  16. *
  17. * @package harmoni.osid_v2.agentmanagement.authn_methods
  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: AuthNMethodManager.class.php,v 1.8 2007/09/04 20:25:37 adamfranco Exp $
  23. */
  24. class AuthNMethodManager
  25. extends OsidManager
  26. {
  27. /**
  28. * Constructor. We wish to ensure that the manager is properly configured
  29. * via the assignConfiguration() method and any needed context information
  30. * has been passed via assignOsidContext(), so an instance variable is set
  31. * here to false untill the necessary initialization has occurred.
  32. *
  33. * @return object
  34. * @access public
  35. * @since 3/1/05
  36. */
  37. function AuthNMethodManager () {
  38. $this->_isInitialized = FALSE;
  39. $this->_osidContext = NULL;
  40. $this->_configuration = NULL;
  41. $this->_authNTypes = array();
  42. $this->_authNMethods = array();
  43. }
  44. /**
  45. * Return context of this OsidManager.
  46. *
  47. * @return object OsidContext
  48. *
  49. * @throws object OsidException
  50. *
  51. * @access public
  52. */
  53. function getOsidContext () {
  54. return $this->_osidContext;
  55. }
  56.  
  57. /**
  58. * Assign the context of this OsidManager.
  59. *
  60. * @param object OsidContext $context
  61. *
  62. * @throws object OsidException An exception with one of the following
  63. * messages defined in org.osid.OsidException: {@link }
  64. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  65. *
  66. * @access public
  67. */
  68. function assignOsidContext ( $context ) {
  69. $this->_osidContext =$context;
  70. }
  71.  
  72. /**
  73. * Assign the configuration of this OsidManager.
  74. *
  75. * @param object Properties $configuration (original type: java.util.Properties)
  76. *
  77. * @throws object OsidException An exception with one of the following
  78. * messages defined in org.osid.OsidException: {@link }
  79. * org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  80. * {@link org.osid.OsidException#PERMISSION_DENIED}
  81. * PERMISSION_DENIED}, {@link }
  82. * org.osid.OsidException#CONFIGURATION_ERROR
  83. * CONFIGURATION_ERROR}, {@link }
  84. * org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link }
  85. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  86. *
  87. * @access public
  88. */
  89. function assignConfiguration ( $configuration ) {
  90. $this->_configuration =$configuration;
  91. $keys =$configuration->getKeys();
  92. while($keys->hasNextObject()) {
  93. $authNType =$keys->nextObject();
  94. $this->addAuthNMethodWithType(
  95. $configuration->getProperty($authNType),
  96. $authNType);
  97. }
  98. }
  99. /**
  100. * Add an Authentication Type-Method pair.
  101. *
  102. * @param object AuthNMethod $authNMethod
  103. * @param object Type $authNType
  104. * @return object AuthNMethod The method that was passed.
  105. * @access public
  106. * @since 3/2/05
  107. */
  108. function addAuthNMethodWithType ( $authNMethod, $authNType ) {
  109. ArgumentValidator::validate($authNMethod, ExtendsValidatorRule::getRule("AuthNMethod"));
  110. ArgumentValidator::validate($authNType, ExtendsValidatorRule::getRule("Type"));
  111. if ($this->_getKey($authNType) !== NULL)
  112. throwError( new Error("Cannot add again, Type '"
  113. .$this->_typeToString($authNType)."' already added.",
  114. "AuthNMethodManager", true));
  115. $this->_authNTypes[] =$authNType;
  116. $this->_authNMethods[] =$authNMethod;
  117. $authNMethod->setType($authNType);
  118. return $authNMethod;
  119. }
  120. /**
  121. * Get all AuthN Types
  122. *
  123. * @return object TypeIterator
  124. * @access public
  125. * @since 3/2/05
  126. */
  127. function getAuthNTypes () {
  128. $iterator = new HarmoniTypeIterator($this->_authNTypes);
  129. return $iterator;
  130. }
  131. /**
  132. * Get an AuthNMethod based on its Type
  133. *
  134. * @param object Type $authNType
  135. * @return object AuthNMethod
  136. * @access public
  137. * @since 3/2/05
  138. */
  139. function getAuthNMethodForType ( $authNType ) {
  140. $key = $this->_getKey($authNType);
  141. if (!isset($this->_authNMethods[$key]))
  142. throwError(new Error("Unknown AuthNMethod Type, '"
  143. .$authNType->getDomain()."::"
  144. .$authNType->getAuthority()."::"
  145. .$authNType->getKeyword()."'",
  146. "AuthNMethodManager", 1));
  147. return $this->_authNMethods[$key];
  148. }
  149. /**
  150. * Private method for matching keys to Types.
  151. *
  152. * @param object Type $authNType
  153. * @return integer
  154. * @access public
  155. * @since 3/2/05
  156. */
  157. function _getKey ( $authNType ) {
  158. foreach(array_keys($this->_authNTypes) as $key) {
  159. if ($authNType->isEqual($this->_authNTypes[$key]))
  160. return $key;
  161. }
  162. // If not found, return NULL
  163. return NULL;
  164. }
  165. /**
  166. * Private method for converting Types to strings.
  167. *
  168. * @param object Type $type
  169. * @return string
  170. * @access public
  171. * @since 3/2/05
  172. */
  173. function _typeToString ( $type ) {
  174. return $type->getDomain()."::".$type->getAuthority()."::".$type->getKeyword();
  175. }
  176. }
  177.  
  178. ?>

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