/tine20/Tinebase/User/Plugin/LdapAbstract.php

https://gitlab.com/rsilveira1987/Expresso · PHP · 156 lines · 52 code · 17 blank · 87 comment · 7 complexity · 5d4efc38c6f8791936713210ce85620a MD5 · raw file

  1. <?php
  2. /**
  3. * Tine 2.0
  4. *
  5. * @package Tinebase
  6. * @subpackage User
  7. * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
  8. * @copyright Copyright (c) 2009 Metaways Infosystems GmbH (http://www.metaways.de)
  9. * @author Philipp Schuele <p.schuele@metaways.de>
  10. *
  11. */
  12. /**
  13. * base class for ldap user plugins
  14. *
  15. * @package Tinebase
  16. * @subpackage User
  17. */
  18. abstract class Tinebase_User_Plugin_LdapAbstract implements Tinebase_User_Plugin_LdapInterface
  19. {
  20. /**
  21. * @var Tinebase_Ldap
  22. */
  23. protected $_ldap = NULL;
  24. /**
  25. * user properties mapping
  26. * -> we need to use lowercase for ldap fields because ldap_fetch returns lowercase keys
  27. *
  28. * @var array
  29. */
  30. protected $_propertyMapping = array();
  31. /**
  32. * objectclasses required for users
  33. *
  34. * @var array
  35. */
  36. protected $_requiredObjectClass = array();
  37. /**
  38. * ldap / email user options array
  39. *
  40. * @var array
  41. */
  42. protected $_options = array();
  43. /**
  44. * the constructor
  45. *
  46. */
  47. public function __construct(array $_options = array())
  48. {
  49. if (Tinebase_User::getConfiguredBackend() != Tinebase_User::LDAP) {
  50. throw new Tinebase_Exception('No LDAP config found.');
  51. }
  52. $this->_options = array_merge($this->_options, $_options);
  53. }
  54. /**
  55. * (non-PHPdoc)
  56. * @see Tinebase_User_Plugin_LdapInterface::getSupportedAttributes()
  57. */
  58. public function getSupportedAttributes()
  59. {
  60. return array_values($this->_propertyMapping);
  61. }
  62. /**
  63. * (non-PHPdoc)
  64. * @see Tinebase_User_Plugin_LdapAbstract::inspectAddUser()
  65. */
  66. public function inspectAddUser(Tinebase_Model_FullUser $_user, array &$_ldapData)
  67. {
  68. $this->_user2ldap($_user, $_ldapData);
  69. }
  70. /**
  71. * (non-PHPdoc)
  72. * @see Tinebase_User_Plugin_LdapAbstract::inspectGetUserByProperty()
  73. */
  74. public function inspectGetUserByProperty(Tinebase_Model_User $_user, array &$_ldapEntry)
  75. {
  76. if (! $_user instanceof Tinebase_Model_FullUser) {
  77. return;
  78. }
  79. $this->_ldap2User($_user, $_ldapEntry);
  80. if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_user->toArray(), true));
  81. }
  82. /**
  83. * inspect set password
  84. *
  85. * @param string $_userId
  86. * @param string $_password
  87. * @param boolean $_encrypt
  88. * @param boolean $_mustChange
  89. * @param array $_ldapData the data to be written to ldap
  90. */
  91. public function inspectSetPassword($_userId, $_password, $_encrypt, $_mustChange, array &$_ldapData)
  92. {
  93. if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Nothing to be done on password change.');
  94. }
  95. /**
  96. * inspect setStatus
  97. *
  98. * @param string $_status the status
  99. * @param array $_ldapData the data to be written to ldap
  100. */
  101. public function inspectStatus($_status, array &$_ldapData)
  102. {
  103. if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Nothing to be done on status change.');
  104. }
  105. /**
  106. * inspect set expiry date
  107. *
  108. * @param Tinebase_DateTime $_expiryDate the expirydate
  109. * @param array $_ldapData the data to be written to ldap
  110. */
  111. public function inspectExpiryDate($_expiryDate, array &$_ldapData)
  112. {
  113. if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Nothing to be done on expiry change.');
  114. }
  115. /**
  116. * (non-PHPdoc)
  117. * @see Tinebase_User_Plugin_LdapAbstract::inspectUpdateUser()
  118. */
  119. public function inspectUpdateUser(Tinebase_Model_FullUser $_user, array &$_ldapData, array &$_ldapEntry)
  120. {
  121. $this->_user2ldap($_user, $_ldapData, $_ldapEntry);
  122. }
  123. /**
  124. * (non-PHPdoc)
  125. * @see Tinebase_User_Plugin_LdapInterface::setLdap()
  126. */
  127. public function setLdap(Tinebase_Ldap $_ldap)
  128. {
  129. $this->_ldap = $_ldap;
  130. }
  131. /**
  132. * convert object with user data to ldap data array
  133. *
  134. * @param Tinebase_Model_FullUser $_user
  135. * @param array $_ldapData the data to be written to ldap
  136. * @param array $_ldapEntry the data currently stored in ldap
  137. */
  138. abstract protected function _user2ldap(Tinebase_Model_FullUser $_user, array &$_ldapData, array &$_ldapEntry = array());
  139. }