Source for file LDAPGroup.class.php

Documentation is available at LDAPGroup.class.php

  1. <?php
  2. /**
  3. * @since 2/24/06
  4. * @package harmoni.osid_v2.agentmanagement.authn_methods
  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: LDAPGroup.class.php,v 1.3 2007/08/22 14:45:45 adamfranco Exp $
  10. */
  11.  
  12. require_once(OKI2."/osid/agent/Group.php");
  13. require_once(dirname(__FILE__)."/LDAPAgentIterator.class.php");
  14.  
  15. /**
  16. * <##>
  17. *
  18. * @since 2/24/06
  19. * @package harmoni.osid_v2.agentmanagement.authn_methods
  20. *
  21. * @copyright Copyright &copy; 2005, Middlebury College
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  23. *
  24. * @version $Id: LDAPGroup.class.php,v 1.3 2007/08/22 14:45:45 adamfranco Exp $
  25. */
  26. class LDAPGroup
  27. implements Group
  28. {
  29. /**
  30. * Constructor.
  31. *
  32. * @param string $idString
  33. * @param object Properties $configuration
  34. * @return object
  35. * @access public
  36. * @since 2/24/06
  37. */
  38. function LDAPGroup ( $idString, $type, $configuration, $authNMethod ) {
  39. ArgumentValidator::validate($idString, StringValidatorRule::getRule(), true);
  40. ArgumentValidator::validate($type,
  41. ExtendsValidatorRule::getRule("Type"), true);
  42. ArgumentValidator::validate($configuration,
  43. ExtendsValidatorRule::getRule("Properties"), true);
  44. ArgumentValidator::validate($authNMethod,
  45. ExtendsValidatorRule::getRule("LDAPAuthNMethod"), true);
  46. $this->_type = $type;
  47. $this->_idString = $idString;
  48. $this->_configuration = $configuration;
  49. $this->_authNMethod = $authNMethod;
  50. }
  51. /**
  52. * Update the Description of this Group.
  53. *
  54. * @param string $description
  55. *
  56. * @throws object AgentException An exception with one of the
  57. * following messages defined in org.osid.agent.AgentException may
  58. * be thrown: {@link }
  59. * org.osid.agent.AgentException#OPERATION_FAILED
  60. * OPERATION_FAILED}, {@link }
  61. * org.osid.agent.AgentException#PERMISSION_DENIED
  62. * PERMISSION_DENIED}, {@link }
  63. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  64. * CONFIGURATION_ERROR}, {@link }
  65. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  66. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  67. * NULL_ARGUMENT}
  68. *
  69. * @access public
  70. */
  71. function updateDescription ( $description ) {
  72. throwError(new Error(AgentException::UNIMPLEMENTED(), "LDAPGroup", true));
  73. }
  74.  
  75. /**
  76. * Get the Description of this Group.
  77. *
  78. * @return string
  79. *
  80. * @throws object AgentException An exception with one of the
  81. * following messages defined in org.osid.agent.AgentException may
  82. * be thrown: {@link }
  83. * org.osid.agent.AgentException#OPERATION_FAILED
  84. * OPERATION_FAILED}, {@link }
  85. * org.osid.agent.AgentException#PERMISSION_DENIED
  86. * PERMISSION_DENIED}, {@link }
  87. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  88. * CONFIGURATION_ERROR}, {@link }
  89. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  90. *
  91. * @access public
  92. */
  93. function getDescription () {
  94. return "";
  95. }
  96.  
  97. /**
  98. * Get the unique Id of this Group.
  99. *
  100. * @return object Id
  101. *
  102. * @throws object AgentException An exception with one of the
  103. * following messages defined in org.osid.agent.AgentException may
  104. * be thrown: {@link }
  105. * org.osid.agent.AgentException#OPERATION_FAILED
  106. * OPERATION_FAILED}, {@link }
  107. * org.osid.agent.AgentException#PERMISSION_DENIED
  108. * PERMISSION_DENIED}, {@link }
  109. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  110. * CONFIGURATION_ERROR}, {@link }
  111. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  112. *
  113. * @access public
  114. */
  115. function getId () {
  116. if (!isset($this->_id)) {
  117. $idManager = Services::getService("Id");
  118. $this->_id = $idManager->getId($this->_idString);
  119. }
  120. return $this->_id;
  121. }
  122.  
  123. /**
  124. * Get the DisplayName of this Group.
  125. *
  126. * @return string
  127. *
  128. * @throws object AgentException An exception with one of the
  129. * following messages defined in org.osid.agent.AgentException may
  130. * be thrown: {@link }
  131. * org.osid.agent.AgentException#OPERATION_FAILED
  132. * OPERATION_FAILED}, {@link }
  133. * org.osid.agent.AgentException#PERMISSION_DENIED
  134. * PERMISSION_DENIED}, {@link }
  135. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  136. * CONFIGURATION_ERROR}, {@link }
  137. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  138. *
  139. * @access public
  140. */
  141. function getDisplayName () {
  142. $connector = $this->_configuration->getProperty('connector');
  143. $fields = array("name");
  144. $results = $connector->getInfo($this->_idString, $fields);
  145. return $results['name'][0];
  146. }
  147.  
  148. /**
  149. * Get the Type of this Group.
  150. *
  151. * @return object Type
  152. *
  153. * @throws object AgentException An exception with one of the
  154. * following messages defined in org.osid.agent.AgentException may
  155. * be thrown: {@link }
  156. * org.osid.agent.AgentException#OPERATION_FAILED
  157. * OPERATION_FAILED}, {@link }
  158. * org.osid.agent.AgentException#PERMISSION_DENIED
  159. * PERMISSION_DENIED}, {@link }
  160. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  161. * CONFIGURATION_ERROR}, {@link }
  162. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  163. *
  164. * @access public
  165. */
  166. function getType () {
  167. return $this->_type;
  168. }
  169.  
  170. /**
  171. * Add an Agent or a Group to this Group. The Agent or Group will not be
  172. * added if it already exists in the group.
  173. *
  174. * @param object Agent $memberOrGroup
  175. *
  176. * @throws object AgentException An exception with one of the
  177. * following messages defined in org.osid.agent.AgentException may
  178. * be thrown: {@link }
  179. * org.osid.agent.AgentException#OPERATION_FAILED
  180. * OPERATION_FAILED}, {@link }
  181. * org.osid.agent.AgentException#PERMISSION_DENIED
  182. * PERMISSION_DENIED}, {@link }
  183. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  184. * CONFIGURATION_ERROR}, {@link }
  185. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  186. * {@link org.osid.agent.AgentException#ALREADY_ADDED}
  187. * ALREADY_ADDED}, {@link }
  188. * org.osid.agent.AgentException#NULL_ARGUMENT NULL_ARGUMENT}
  189. *
  190. * @access public
  191. */
  192. function add ( $memberOrGroup ) {
  193. throwError(new Error(AgentException::UNIMPLEMENTED(), "LDAPGroup", true));
  194. }
  195.  
  196. /**
  197. * Remove an Agent member or a Group from this Group. If the Agent or Group
  198. * is not in this group no action is taken and no exception is thrown.
  199. *
  200. * @param object Agent $memberOrGroup
  201. *
  202. * @throws object AgentException An exception with one of the
  203. * following messages defined in org.osid.agent.AgentException may
  204. * be thrown: {@link }
  205. * org.osid.agent.AgentException#OPERATION_FAILED
  206. * OPERATION_FAILED}, {@link }
  207. * org.osid.agent.AgentException#PERMISSION_DENIED
  208. * PERMISSION_DENIED}, {@link }
  209. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  210. * CONFIGURATION_ERROR}, {@link }
  211. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  212. * {@link org.osid.agent.AgentException#UNKNOWN_ID UNKNOWN_ID},
  213. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  214. * NULL_ARGUMENT}
  215. *
  216. * @access public
  217. */
  218. function remove ( $memberOrGroup ) {
  219. throwError(new Error(AgentException::UNIMPLEMENTED(), "LDAPGroup", true));
  220. }
  221.  
  222. /**
  223. * Get all the Members of this group and optionally all the Members from
  224. * all subgroups. Duplicates are not returned.
  225. *
  226. * @param boolean $includeSubgroups
  227. *
  228. * @return object AgentIterator
  229. *
  230. * @throws object AgentException An exception with one of the
  231. * following messages defined in org.osid.agent.AgentException may
  232. * be thrown: {@link }
  233. * org.osid.agent.AgentException#OPERATION_FAILED
  234. * OPERATION_FAILED}, {@link }
  235. * org.osid.agent.AgentException#PERMISSION_DENIED
  236. * PERMISSION_DENIED}, {@link }
  237. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  238. * CONFIGURATION_ERROR}, {@link }
  239. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  240. *
  241. * @access public
  242. */
  243. function getMembers ( $includeSubgroups ) {
  244. if ($includeSubgroups) {
  245. return $this->_getSubgroupMembers();
  246. } else {
  247. return $this->_getMyMembers();
  248. }
  249. }
  250. /**
  251. * Answer the direct members of this group
  252. *
  253. * @return object AgentIterator
  254. * @access private
  255. * @since 2/27/06
  256. */
  257. function _getMyMembers () {
  258. if (!isset($this->_myMembers)) {
  259. $connector = $this->_configuration->getProperty('connector');
  260. $fields = array("member");
  261. $results = $connector->getInfo($this->_idString, $fields);
  262. // printpre($results);
  263. $this->_myMembers = array();
  264. $this->_myMembersDNs = array();
  265. if (isset($results['member']) && is_array($results['member'])) {
  266. $this->_myMembersDNs = $results['member'];
  267. }
  268. }
  269. if (count($this->_myMembers) || count($this->_myMembersDNs))
  270. $iterator = new LDAPAgentIterator($this->_authNMethod, $this->_myMembers,
  271. $this->_myMembersDNs);
  272. else
  273. $iterator = new HarmoniIterator($this->_myMembers);
  274. return $iterator;
  275. }
  276. /**
  277. * Answer the members of this group both directly and in subgroups
  278. *
  279. * @return object AgentIterator
  280. * @access private
  281. * @since 2/27/06
  282. */
  283. function _getSubgroupMembers () {
  284. throwError(new Error(AgentException::UNIMPLEMENTED(), "LDAPGroup", true));
  285. if (!isset($this->_subgroupMembers)) {
  286. $connector = $this->_configuration->getProperty('connector');
  287. $fields = array("member");
  288. $results = $connector->getInfo($this->_idString, $fields);
  289. // printpre($results);
  290. $this->_subgroupMembers = array();
  291. if (isset($results['member']) && is_array($results['member'])) {
  292. $authenticationManager = Services::getService("AuthN");
  293. $agentManager = Services::getService("AgentManager");
  294. foreach ($results['member'] as $dn) {
  295. $tokens = $this->_authNMethod->createTokensForIdentifier($dn);
  296. $agentId = $authenticationManager->_getAgentIdForAuthNTokens($tokens, $this->_type);
  297. $this->_subgroupMembers[] = $agentManager->getAgent($agentId);
  298. }
  299. }
  300. }
  301. $iterator = new HarmoniIterator($this->_subgroupMembers);
  302. return $iterator;
  303. }
  304.  
  305. /**
  306. * Get all the Groups in this group and optionally all the subgroups in
  307. * this group. Note since Groups subclass Agents, we are returning an
  308. * AgentIterator and there is no GroupIterator.
  309. *
  310. * @param boolean $includeSubgroups
  311. *
  312. * @return object AgentIterator
  313. *
  314. * @throws object AgentException An exception with one of the
  315. * following messages defined in org.osid.agent.AgentException may
  316. * be thrown: {@link }
  317. * org.osid.agent.AgentException#OPERATION_FAILED
  318. * OPERATION_FAILED}, {@link }
  319. * org.osid.agent.AgentException#PERMISSION_DENIED
  320. * PERMISSION_DENIED}, {@link }
  321. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  322. * CONFIGURATION_ERROR}, {@link }
  323. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  324. *
  325. * @access public
  326. */
  327. function getGroups ( $includeSubgroups ) {
  328. if ($includeSubgroups) {
  329. return $this->_getSubgroupGroups();
  330. } else {
  331. return $this->_getMyGroups();
  332. }
  333. }
  334. /**
  335. * Answer the direct child groups of this group
  336. *
  337. * @return object AgentIterator
  338. * @access private
  339. * @since 2/27/06
  340. */
  341. function _getMyGroups () {
  342. if (!isset($this->_myGroups)) {
  343. $connector = $this->_configuration->getProperty('connector');
  344. $filter = "(objectclass=*)";
  345. $dns = $connector->getDNsByList($filter, $this->_idString);
  346. $this->_myGroups = array();
  347. foreach ($dns as $dn) {
  348. if ($dn != $this->_idString)
  349. $this->_myGroups[] = new LDAPGroup($dn, $this->_type,
  350. $this->_configuration,
  351. $this->_authNMethod);
  352. }
  353. }
  354. $iterator = new HarmoniIterator($this->_myGroups);
  355. return $iterator;
  356. }
  357. /**
  358. * Answer the descendent groups of this group
  359. *
  360. * @return object AgentIterator
  361. * @access private
  362. * @since 2/27/06
  363. */
  364. function _getSubgroupGroups () {
  365. throwError(new Error(AgentException::UNIMPLEMENTED(), "LDAPGroup", true));
  366. if (!isset($this->_subgroupGroups)) {
  367. $connector = $this->_configuration->getProperty('connector');
  368. $filter = "(objectclass=*)";
  369. $dns = $connector->getDNsBySearch($filter, $this->_idString);
  370. $this->_subgroupGroups = array();
  371. foreach ($dns as $dn) {
  372. if ($dn != $this->_idString)
  373. $this->_subgroupGroups[] = new LDAPGroup($dn, $this->_type,
  374. $this->_configuration,
  375. $this->_authNMethod);
  376. }
  377. }
  378. $iterator = new HarmoniIterator($this->_subgroupGroups);
  379. return $iterator;
  380. }
  381.  
  382. /**
  383. * Return <code>true</code> if the Member or Group is in the Group,
  384. * optionally including subgroups, <code>false</code> otherwise.
  385. *
  386. * @param object Agent $memberOrGroup
  387. * @param boolean $searchSubgroups
  388. *
  389. * @return boolean
  390. *
  391. * @throws object AgentException An exception with one of the
  392. * following messages defined in org.osid.agent.AgentException may
  393. * be thrown: {@link }
  394. * org.osid.agent.AgentException#OPERATION_FAILED
  395. * OPERATION_FAILED}, {@link }
  396. * org.osid.agent.AgentException#PERMISSION_DENIED
  397. * PERMISSION_DENIED}, {@link }
  398. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  399. * CONFIGURATION_ERROR}, {@link }
  400. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  401. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  402. * NULL_ARGUMENT}
  403. *
  404. * @access public
  405. */
  406. function contains ( $memberOrGroup, $searchSubgroups ) {
  407. $myMembers = $this->getMembers(false);
  408. while ($myMembers->hasNext()) {
  409. if ($memberOrGroup->isEqual($myMembers->next()->getId())) {
  410. return true;
  411. }
  412. }
  413. $myGroups = $this->getGroups(false);
  414. while ($myGroups->hasNext()) {
  415. if ($memberOrGroup->isEqual($myGroups->next()->getId())) {
  416. return true;
  417. }
  418. }
  419. if ($searchSubgroups) {
  420. $myGroups = $this->getGroups();
  421. while ($myGroups->hasNext()) {
  422. if ($myGroups->next()->contains($memberOrGroup, true)) {
  423. return true;
  424. }
  425. }
  426. }
  427. return false;
  428. }
  429.  
  430. /**
  431. * Get the Properties of this Type associated with this Group.
  432. *
  433. * @param object Type $propertiesType
  434. *
  435. * @return object Properties
  436. *
  437. * @throws object AgentException An exception with one of the
  438. * following messages defined in org.osid.agent.AgentException may
  439. * be thrown: {@link }
  440. * org.osid.agent.AgentException#OPERATION_FAILED
  441. * OPERATION_FAILED}, {@link }
  442. * org.osid.agent.AgentException#PERMISSION_DENIED
  443. * PERMISSION_DENIED}, {@link }
  444. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  445. * CONFIGURATION_ERROR}, {@link }
  446. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  447. * {@link org.osid.agent.AgentException#NULL_ARGUMENT}
  448. * NULL_ARGUMENT}, {@link }
  449. * org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE}
  450. *
  451. * @access public
  452. */
  453. function getPropertiesByType ( $propertiesType ) {
  454. throwError(new Error(AgentException::UNIMPLEMENTED(), "LDAPGroup", true));
  455. }
  456.  
  457. /**
  458. * Get all the property Types. The returned iterator provides access to
  459. * the property Types from this implementation one at a time. Iterators
  460. * have a method hasNextType() which returns true if there is another
  461. * property Type available and a method nextType() which returns the next
  462. * property Type. Group.
  463. *
  464. * @return object TypeIterator
  465. *
  466. * @throws object AgentException An exception with one of the
  467. * following messages defined in org.osid.agent.AgentException may
  468. * be thrown: {@link }
  469. * org.osid.agent.AgentException#OPERATION_FAILED
  470. * OPERATION_FAILED}, {@link }
  471. * org.osid.agent.AgentException#PERMISSION_DENIED
  472. * PERMISSION_DENIED}, {@link }
  473. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  474. * CONFIGURATION_ERROR}, {@link }
  475. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  476. *
  477. * @access public
  478. */
  479. function getPropertyTypes () {
  480. throwError(new Error(AgentException::UNIMPLEMENTED(), "LDAPGroup", true));
  481. }
  482.  
  483. /**
  484. * Get the Properties associated with this Group.
  485. *
  486. * @return object PropertiesIterator
  487. *
  488. * @throws object AgentException An exception with one of the
  489. * following messages defined in org.osid.agent.AgentException may
  490. * be thrown: {@link }
  491. * org.osid.agent.AgentException#OPERATION_FAILED
  492. * OPERATION_FAILED}, {@link }
  493. * org.osid.agent.AgentException#PERMISSION_DENIED
  494. * PERMISSION_DENIED}, {@link }
  495. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  496. * CONFIGURATION_ERROR}, {@link }
  497. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  498. *
  499. * @access public
  500. */
  501. function getProperties () {
  502. $a = array();
  503. $i = new HarmoniIterator($a);
  504. return $i;
  505. }
  506. /**
  507. * Answer true if this Agent is an Agent, not a group
  508. *
  509. * WARNING: NOT IN OSID
  510. *
  511. * @return boolean
  512. * @access public
  513. * @since 12/7/06
  514. */
  515. function isAgent () {
  516. return !$this->isGroup();
  517. }
  518. /**
  519. * Answer true if this Agent is an Group
  520. *
  521. * WARNING: NOT IN OSID
  522. *
  523. * @return boolean
  524. * @access public
  525. * @since 12/7/06
  526. */
  527. function isGroup () {
  528. return true;
  529. }
  530. }
  531.  
  532. ?>

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