Source for file AuthNMethod.abstract.php

Documentation is available at AuthNMethod.abstract.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: AuthNMethod.abstract.php,v 1.13 2007/09/04 20:25:37 adamfranco Exp $
  9. */
  10.  
  11. /**
  12. * An AuthNMethod is an abstract class that corresponds to a method of
  13. * authenticating Agents. It deals with verifying the tokens passed to it and
  14. * authenticating them. AuthNMethods do not keep track of any authentication
  15. * state information. They simply provide a means of querying stores of information
  16. * to determine if tokens are valid or not.
  17. *
  18. * AuthNMethods deal with two types of tokens. The first are arbitrary data that
  19. * is passed by the user trying to authenticate. This data may be an array with
  20. * elements for 'username' and 'password', it might be a string operated on by a
  21. * private key, it might be a Kerberos Ticket, or pretty much anything else. It is
  22. * up to a given AuthNMethod to pass the tokens passed to it to appropriate
  23. * AuthNTokens objects for the handling of this data. AuthNTokens objects provide
  24. * access to a string 'identifier' for given tokens data that can be used by
  25. * other systems to identify this set of tokens. Additionally, the AuthNTokens
  26. * objects can be initialized with an identifier and then passed to the authentication
  27. * method for querying on the existance or associated properties of the user
  28. * that corresponds to the identifier.
  29. *
  30. * @package harmoni.osid_v2.agentmanagement.authn_methods
  31. *
  32. * @copyright Copyright &copy; 2005, Middlebury College
  33. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  34. *
  35. * @version $Id: AuthNMethod.abstract.php,v 1.13 2007/09/04 20:25:37 adamfranco Exp $
  36. */
  37. class AuthNMethod {
  38. /**
  39. * Constructor. Does not take any configuration. assignConfiguration() Should be
  40. * used for this purpose.
  41. *
  42. * @return object
  43. * @access public
  44. * @since 3/1/05
  45. */
  46. function AuthNMethod () {}
  47. /**
  48. * Store the configuration.
  49. *
  50. * @param object Properties $configuration
  51. * @return void
  52. * @access public
  53. * @since 3/24/05
  54. */
  55. function assignConfiguration ( $configuration ) {
  56. ArgumentValidator::validate ($configuration, ExtendsValidatorRule::getRule("Properties"));
  57. $this->_configuration =$configuration;
  58. }
  59. /**
  60. * Set the Type of this AuthNMethod. This should only be used by the
  61. * AuthNMethod manager, not classes outside of this package.
  62. *
  63. * @param object Type
  64. * @return void
  65. * @access protected
  66. * @since 3/2/05
  67. */
  68. function setType ( $type ) {
  69. ArgumentValidator::validate($type, ExtendsValidatorRule::getRule("Type"));
  70. $this->_type =$type;
  71. }
  72. /**
  73. * Return the Type of this AuthNMethod
  74. *
  75. * @return object Type
  76. * @access public
  77. * @since 3/1/05
  78. */
  79. function getType () {
  80. return $this->_type;
  81. }
  82. /**
  83. * Create a Tokens Object
  84. *
  85. * @return object Tokens
  86. * @access public
  87. * @since 3/1/05
  88. */
  89. function createTokensObject () {
  90. $tokensClass = $this->_configuration->getProperty('tokens_class');
  91. $newTokens = new $tokensClass($this->_configuration);
  92. $validatorRule = ExtendsValidatorRule::getRule('AuthNTokens');
  93. if ($validatorRule->check($newTokens))
  94. return $newTokens;
  95. else
  96. throwError( new Error("Configuration Error: tokens_class, '".$tokensClass."' does not extend AuthNTokens.",
  97. "AuthNMethod", true));
  98. }
  99. /**
  100. * Create a Tokens object that provides common access to the contents
  101. * of the tokens passed to the system by the user or returned from the
  102. * underlying system.
  103. *
  104. * @param mixed $tokens
  105. * @return object Tokens
  106. * @access public
  107. * @since 3/1/05
  108. */
  109. function createTokens ($tokens) {
  110. $tokensObject =$this->createTokensObject();
  111. $tokensObject->initializeForTokens($tokens);
  112. return $tokensObject;
  113. }
  114. /**
  115. * Create a Tokens object for a given identifier. An identifier is often a
  116. * username, but does not have to be as long as it is a string unique within this
  117. * authentication method.
  118. *
  119. * @param string $identifier
  120. * @return object Tokens
  121. * @access public
  122. * @since 3/1/05
  123. */
  124. function createTokensForIdentifier ( $identifier ) {
  125. $tokensObject =$this->createTokensObject();
  126. $tokensObject->initializeForIdentifier($identifier);
  127. return $tokensObject;
  128. }
  129. /**
  130. * Authenticate a agent tokens
  131. *
  132. * @param mixed $tokens
  133. * @return boolean
  134. * @access public
  135. * @since 3/1/05
  136. */
  137. function authenticate ( $tokens ) {
  138. return $this->authenticateTokens($this->createTokens($tokens));
  139. }
  140. /**
  141. * Authenticate a Tokens object
  142. *
  143. * @param object AuthNTokens $authNTokens
  144. * @return boolean
  145. * @access public
  146. * @since 3/1/05
  147. */
  148. function authenticateTokens ( $authNTokens ) {
  149. throwError( new Error("AuthNMethod::authenticate() should have been overridden in a child class.",
  150. "AuthNMethod", true));
  151. }
  152. /**
  153. * Return true if the tokens can be matched in the system.
  154. *
  155. * @param mixed $tokens
  156. * @return boolean
  157. * @access public
  158. * @since 3/1/05
  159. */
  160. function exists ( $tokens ) {
  161. return $this->tokensExist($this->createTokens($tokens));
  162. }
  163. /**
  164. * Return true if the AuthNTokens can be matched in the system.
  165. *
  166. * @param object AuthNTokens $authNTokens
  167. * @return boolean
  168. * @access public
  169. * @since 3/1/05
  170. */
  171. function tokensExist ( $authNTokens ) {
  172. throwError( new Error("AuthNMethod::authenticate() should have been overridden in a child class.",
  173. "AuthNMethod", true));
  174. }
  175. /**
  176. * Return Properties associated with the tokens. The properties will have
  177. * the AuthNMethod Type as their Type. One Property that should always be
  178. * included is 'identifier' which corresponds to the identifier for the tokens.
  179. *
  180. * @param mixed $tokens
  181. * @return object Properties
  182. * @access public
  183. * @since 3/1/05
  184. */
  185. function getProperties ( $tokens ) {
  186. return $this->getPropertiesForTokens($this->createTokens($tokens));
  187. }
  188. /**
  189. * Return Properties associated with the Tokens. The properties will have
  190. * the AuthNMethod Type as their Type. One Property that should always be
  191. * included is 'identifier' which corresponds to the identifier for the tokens
  192. *
  193. * @param object AuthNTokens $authNTokens
  194. * @return object Properties
  195. * @access public
  196. * @since 3/1/05
  197. */
  198. function getPropertiesForTokens ( $authNTokens ) {
  199. ArgumentValidator::validate($authNTokens, ExtendsValidatorRule::getRule("AuthNTokens"));
  200. $properties = new HarmoniProperties($this->getType());
  201.  
  202. // Properties take values by reference, so we have to work around
  203. // that by creating/unsetting variables.
  204. $value = $authNTokens->getIdentifier();
  205. $properties->addProperty('identifier', $value);
  206. unset($value);
  207. $this->_populateProperties( $authNTokens, $properties );
  208. return $properties;
  209. }
  210. /**
  211. * A private method used to populate the Properties that correspond to the
  212. * given AuthNTokens
  213. *
  214. * @param object AuthNTokens $authNTokens
  215. * @param object Properties $properties
  216. * @return void
  217. * @access private
  218. * @since 3/1/05
  219. */
  220. function _populateProperties ( $authNTokens, $properties ) {
  221. throwError( new Error("AuthNMethod::_populateProperties() should have been overridden in a child class.",
  222. "AuthNMethod", true));
  223. }
  224. /**
  225. * Get an iterator of the AuthNTokens that match the search string passed.
  226. * The '*' wildcard character can be present in the string and will be
  227. * converted to the system wildcard for the AuthNMethod if wildcards are
  228. * supported or removed (and the exact string searched for) if they are not
  229. * supported.
  230. *
  231. * When multiple fields are searched on an OR search is performed, i.e.
  232. * '*ach*' would match username/fullname 'achapin'/'Chapin, Alex' as well as
  233. * 'zsmith'/'Smith, Zach'.
  234. *
  235. * @param string $searchString
  236. * @return object ObjectIterator
  237. * @access public
  238. * @since 3/3/05
  239. */
  240. function getTokensBySearch ( $searchString ) {
  241. throwError( new Error("AuthNMethod::getTokensBySearch() should have been overridden in a child class.",
  242. "AuthNMethod", true));
  243. }
  244. /**
  245. * Return TRUE if this method supports token addition.
  246. *
  247. * @return boolean
  248. * @access public
  249. * @since 3/1/05
  250. */
  251. function supportsTokenAddition () {
  252. // Override if implementing
  253. return FALSE;
  254. }
  255. /**
  256. * Add tokens to the system.
  257. *
  258. * @param object AuthNTokens $authNTokens
  259. * @return void
  260. * @access public
  261. * @since 3/1/05
  262. */
  263. function addTokens ( $authNTokens ) {
  264. throwError( new Error("AuthNMethod::addTokens() should have been overridden in a child class.",
  265. "AuthNMethod", true));
  266. }
  267. /**
  268. * Return TRUE if this method supports token deletion.
  269. *
  270. * @return boolean
  271. * @access public
  272. * @since 3/1/05
  273. */
  274. function supportsTokenDeletion () {
  275. // Override if implementing
  276. return FALSE;
  277. }
  278. /**
  279. * Add tokens and associated Properties to the system.
  280. *
  281. * @param object AuthNTokens $authNTokens
  282. * @return void
  283. * @access public
  284. * @since 3/1/05
  285. */
  286. function deleteTokens ( $authNTokens ) {
  287. throwError( new Error("AuthNMethod::deleteTokens() should have been overridden in a child class.",
  288. "AuthNMethod", true));
  289. }
  290. /**
  291. * Return TRUE if this method supports token updates.
  292. *
  293. * @return boolean
  294. * @access public
  295. * @since 3/1/05
  296. */
  297. function supportsTokenUpdates () {
  298. // Override if implementing
  299. return FALSE;
  300. }
  301. /**
  302. * Update old tokens to new tokens in the system.
  303. *
  304. * @param object AuthNTokens $oldAuthNTokens
  305. * @param object AuthNTokens $newAuthNTokens
  306. * @return void
  307. * @access public
  308. * @since 3/1/05
  309. */
  310. function updateTokens ( $oldAuthNTokens, $newAuthNTokens ) {
  311. throwError( new Error("AuthNMethod::updateTokens() should have been overridden in a child class.",
  312. "AuthNMethod", true));
  313. }
  314. /**
  315. * Return TRUE if this method supports property updates.
  316. *
  317. * @return boolean
  318. * @access public
  319. * @since 3/1/05
  320. */
  321. function supportsPropertyUpdates () {
  322. // Override if implementing
  323. return FALSE;
  324. }
  325. /**
  326. * Update the properties for the given tokens
  327. *
  328. * @param object AuthNTokens $authNTokens
  329. * @param object Properties $newProperties
  330. * @return void
  331. * @access public
  332. * @since 3/1/05
  333. */
  334. function updatePropertiesForTokens ( $authNTokens, $newProperties ) {
  335. throwError( new Error("AuthNMethod::updateTokens() should have been overridden in a child class.",
  336. "AuthNMethod", true));
  337. }
  338. /**
  339. * Should return the 'display_name_property' value for tokens
  340. *
  341. * @param object AuthNTokens
  342. * @return string
  343. * @access public
  344. * @since 10/25/05
  345. */
  346. function getDisplayNameForTokens ($authNTokens) {
  347. if (!is_null(
  348. $this->_configuration->getProperty("display_name_property"))) {
  349. $property =
  350. $this->_configuration->getProperty("display_name_property");
  351. $properties =$this->getPropertiesForTokens($authNTokens);
  352.  
  353. if ($properties->getProperty($property) != NULL)
  354. return $properties->getProperty($property);
  355. }
  356. return $authNTokens->getIdentifier();
  357. }
  358. /*******************************************************
  359. * Directory methods
  360. *********************************************************/
  361.  
  362. /**
  363. * Answer TRUE if this AuthN method supports directory functionality
  364. *
  365. * @return boolean
  366. * @access public
  367. * @since 2/23/06
  368. */
  369. function supportsDirectory () {
  370. // Override if implementing
  371. return FALSE;
  372. }
  373. /**
  374. * Answer an iterator of all groups
  375. *
  376. * @param object AuthNTokens $authNTokens
  377. * @return object AgentIterator
  378. * @access public
  379. * @since 2/23/06
  380. */
  381. function getAllGroups () {
  382. die ("Method <b>".__FUNCTION__."()</b> declared in interface<b> ".__CLASS__."</b> has not been overloaded in a child class.");
  383. }
  384. /**
  385. * Answer an iterator of the top-level groups, may be equivalent to
  386. * getAllGroups() if this directory is not hierarchically organized.
  387. *
  388. * @param object AuthNTokens $authNTokens
  389. * @return object AgentIterator
  390. * @access public
  391. * @since 2/23/06
  392. */
  393. function getRootGroups () {
  394. die ("Method <b>".__FUNCTION__."()</b> declared in interface<b> ".__CLASS__."</b> has not been overloaded in a child class.");
  395. }
  396. /**
  397. * Answer a group by Id
  398. *
  399. * @param object Id $id
  400. * @return object AgentIterator
  401. * @access public
  402. * @since 2/23/06
  403. */
  404. function getGroup ( $id ) {
  405. die ("Method <b>".__FUNCTION__."()</b> declared in interface<b> ".__CLASS__."</b> has not been overloaded in a child class.");
  406. }
  407. /**
  408. * Answer a true if the Id corresponds to a valid group
  409. *
  410. * @param object Id $id
  411. * @return boolean
  412. * @access public
  413. * @since 2/23/06
  414. */
  415. function isGroup ( $id ) {
  416. die ("Method <b>".__FUNCTION__."()</b> declared in interface<b> ".__CLASS__."</b> has not been overloaded in a child class.");
  417. }
  418. /**
  419. * Answer an iterator of groups that contain the tokens. If $includeSubgroups
  420. * is true then groups will be returned if any descendent group contains
  421. * the tokens.
  422. *
  423. * @param object AuthNTokens $authNTokens
  424. * @return object AgentIterator
  425. * @access public
  426. * @since 2/23/06
  427. */
  428. function getGroupsContainingTokens ( $authNTokens, $includeSubgroups ) {
  429. die ("Method <b>".__FUNCTION__."()</b> declared in interface<b> ".__CLASS__."</b> has not been overloaded in a child class.");
  430. }
  431. /**
  432. * Answer an iterator of groups that contain the Id. If $includeSubgroups
  433. * is true then groups will be returned if any descendent group contains
  434. * the Id.
  435. *
  436. * @param object Id $id
  437. * @return object AgentIterator
  438. * @access public
  439. * @since 2/23/06
  440. */
  441. function getGroupsContainingGroup ( $id, $includeSubgroups ) {
  442. die ("Method <b>".__FUNCTION__."()</b> declared in interface<b> ".__CLASS__."</b> has not been overloaded in a child class.");
  443. }
  444. }
  445.  
  446. ?>

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