RootDse.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Ldap
  17. * @subpackage RootDSE
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Ldap_Node_Abstract
  24. */
  25. require_once 'Zend/Ldap/Node/Abstract.php';
  26. /**
  27. * Zend_Ldap_Node_RootDse provides a simple data-container for the RootDSE node.
  28. *
  29. * @category Zend
  30. * @package Zend_Ldap
  31. * @subpackage RootDSE
  32. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Ldap_Node_RootDse extends Zend_Ldap_Node_Abstract
  36. {
  37. const SERVER_TYPE_GENERIC = 1;
  38. const SERVER_TYPE_OPENLDAP = 2;
  39. const SERVER_TYPE_ACTIVEDIRECTORY = 3;
  40. const SERVER_TYPE_EDIRECTORY = 4;
  41. /**
  42. * Factory method to create the RootDSE.
  43. *
  44. * @param Zend_Ldap $ldap
  45. * @return Zend_Ldap_Node_RootDse
  46. * @throws Zend_Ldap_Exception
  47. */
  48. public static function create(Zend_Ldap $ldap)
  49. {
  50. $dn = Zend_Ldap_Dn::fromString('');
  51. $data = $ldap->getEntry($dn, array('*', '+'), true);
  52. if (isset($data['domainfunctionality'])) {
  53. /**
  54. * @see Zend_Ldap_Node_RootDse_ActiveDirectory
  55. */
  56. require_once 'Zend/Ldap/Node/RootDse/ActiveDirectory.php';
  57. return new Zend_Ldap_Node_RootDse_ActiveDirectory($dn, $data);
  58. } else if (isset($data['dsaname'])) {
  59. /**
  60. * @see Zend_Ldap_Node_RootDse_ActiveDirectory
  61. */
  62. require_once 'Zend/Ldap/Node/RootDse/eDirectory.php';
  63. return new Zend_Ldap_Node_RootDse_eDirectory($dn, $data);
  64. } else if (isset($data['structuralobjectclass']) &&
  65. $data['structuralobjectclass'][0] === 'OpenLDAProotDSE') {
  66. /**
  67. * @see Zend_Ldap_Node_RootDse_OpenLdap
  68. */
  69. require_once 'Zend/Ldap/Node/RootDse/OpenLdap.php';
  70. return new Zend_Ldap_Node_RootDse_OpenLdap($dn, $data);
  71. } else {
  72. return new self($dn, $data);
  73. }
  74. }
  75. /**
  76. * Constructor.
  77. *
  78. * Constructor is protected to enforce the use of factory methods.
  79. *
  80. * @param Zend_Ldap_Dn $dn
  81. * @param array $data
  82. */
  83. protected function __construct(Zend_Ldap_Dn $dn, array $data)
  84. {
  85. parent::__construct($dn, $data, true);
  86. }
  87. /**
  88. * Gets the namingContexts.
  89. *
  90. * @return array
  91. */
  92. public function getNamingContexts()
  93. {
  94. return $this->getAttribute('namingContexts', null);
  95. }
  96. /**
  97. * Gets the subschemaSubentry.
  98. *
  99. * @return string|null
  100. */
  101. public function getSubschemaSubentry()
  102. {
  103. return $this->getAttribute('subschemaSubentry', 0);
  104. }
  105. /**
  106. * Determines if the version is supported
  107. *
  108. * @param string|int|array $versions version(s) to check
  109. * @return boolean
  110. */
  111. public function supportsVersion($versions)
  112. {
  113. return $this->attributeHasValue('supportedLDAPVersion', $versions);
  114. }
  115. /**
  116. * Determines if the sasl mechanism is supported
  117. *
  118. * @param string|array $mechlist SASL mechanisms to check
  119. * @return boolean
  120. */
  121. public function supportsSaslMechanism($mechlist)
  122. {
  123. return $this->attributeHasValue('supportedSASLMechanisms', $mechlist);
  124. }
  125. /**
  126. * Gets the server type
  127. *
  128. * @return int
  129. */
  130. public function getServerType()
  131. {
  132. return self::SERVER_TYPE_GENERIC;
  133. }
  134. /**
  135. * Returns the schema DN
  136. *
  137. * @return Zend_Ldap_Dn
  138. */
  139. public function getSchemaDn()
  140. {
  141. $schemaDn = $this->getSubschemaSubentry();
  142. /**
  143. * @see Zend_Ldap_Dn
  144. */
  145. require_once 'Zend/Ldap/Dn.php';
  146. return Zend_Ldap_Dn::fromString($schemaDn);
  147. }
  148. }