/framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Person.php

https://github.com/ewandor/horde · PHP · 164 lines · 60 code · 9 blank · 95 comment · 14 complexity · 48fc7c689f8e8885cd24c32a798cc2f5 MD5 · raw file

  1. <?php
  2. /**
  3. * A person (objectclass 2.5.6.6).
  4. *
  5. * PHP version 5
  6. *
  7. * @category Kolab
  8. * @package Kolab_Server
  9. * @author Gunnar Wrobel <wrobel@pardus.de>
  10. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
  11. * @link http://pear.horde.org/index.php?package=Kolab_Server
  12. */
  13. /**
  14. * This class provides methods for the person objectclass.
  15. *
  16. * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
  17. *
  18. * See the enclosed file COPYING for license information (LGPL). If you
  19. * did not receive this file, see http://www.horde.org/licenses/lgpl21.
  20. *
  21. * @category Kolab
  22. * @package Kolab_Server
  23. * @author Gunnar Wrobel <wrobel@pardus.de>
  24. * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
  25. * @link http://pear.horde.org/index.php?package=Kolab_Server
  26. */
  27. class Horde_Kolab_Server_Object_Person extends Horde_Kolab_Server_Object_Top
  28. {
  29. /** The specific object class of this object type */
  30. const OBJECTCLASS_PERSON = 'person';
  31. /**
  32. * A structure to initialize the attribute structure for this class.
  33. *
  34. * @var array
  35. */
  36. static public $init_attributes = array(
  37. 'Cn', 'Sn', 'Userpassword', 'Userpasswordraw',
  38. /* 'Telephonenumber' */
  39. /* 'defined' => array( */
  40. /* self::ATTRIBUTE_CN, */
  41. /* self::ATTRIBUTE_SN, */
  42. /* self::ATTRIBUTE_USERPASSWORD, */
  43. /* self::ATTRIBUTE_TELNO, */
  44. /* ), */
  45. /* 'derived' => array( */
  46. /* self::ATTRIBUTE_USERPASSWORD => array( */
  47. /* 'base' => array( */
  48. /* self::ATTRIBUTE_USERPASSWORD */
  49. /* ), */
  50. /* 'method' => 'getEmpty', */
  51. /* ), */
  52. /* self::ATTRIBUTE_USERPASSWORDRAW => array( */
  53. /* 'base' => array( */
  54. /* self::ATTRIBUTE_USERPASSWORD */
  55. /* ), */
  56. /* 'method' => '_get', */
  57. /* 'args' => array( */
  58. /* self::ATTRIBUTE_USERPASSWORD, */
  59. /* ), */
  60. /* ), */
  61. /* ), */
  62. /* 'required' => array( */
  63. /* self::ATTRIBUTE_CN, */
  64. /* self::ATTRIBUTE_SN, */
  65. /* ), */
  66. /* 'object_classes' => array( */
  67. /* self::OBJECTCLASS_PERSON */
  68. /* ), */
  69. );
  70. /**
  71. * Salt and hash the password.
  72. *
  73. * @param string $password The password.
  74. *
  75. * @return string The salted hashed password.
  76. */
  77. protected function hashPassword($password)
  78. {
  79. $type = isset($this->server->params['hashtype'])
  80. ? $this->server->params['hashtype'] : 'ssha';
  81. return Horde_Auth::getCryptedPassword($password, '', $type, true);
  82. }
  83. /**
  84. * Return the filter string to retrieve this object type.
  85. *
  86. * @static
  87. *
  88. * @return string The filter to retrieve this object type from the server
  89. * database.
  90. */
  91. public static function getFilter()
  92. {
  93. return new Horde_Kolab_Server_Query_Element_Equals(
  94. Horde_Kolab_Server_Object_Attribute_Objectclass::NAME,
  95. self::OBJECTCLASS_PERSON
  96. );
  97. }
  98. /**
  99. * Generates an ID for the given information.
  100. *
  101. * @param array $info The data of the object.
  102. *
  103. * @static
  104. *
  105. * @return string The ID.
  106. */
  107. public function generateId(array &$info)
  108. {
  109. $cn = Horde_Kolab_Server_Object_Attribute_Cn::NAME;
  110. $sn = Horde_Kolab_Server_Object_Attribute_Sn::NAME;
  111. if ($this->exists()) {
  112. if (!isset($info[$cn])
  113. && !isset($info[$sn])) {
  114. return $this->getGuid();
  115. }
  116. if (!isset($info[$cn])) {
  117. $old = $this->getInternal($cn);
  118. if (!empty($old)) {
  119. return $this->getGuid();
  120. }
  121. }
  122. }
  123. if (!empty($info[$cn])) {
  124. $id = $info[$cn];
  125. } else {
  126. $id = $info[$sn];
  127. }
  128. if (is_array($id)) {
  129. $id = $id[0];
  130. }
  131. return $cn . '=' . $this->server->structure->quoteForUid($id);
  132. }
  133. /**
  134. * Distill the server side object information to save.
  135. *
  136. * @param array $info The information about the object.
  137. *
  138. * @return array The set of information.
  139. *
  140. * @throws Horde_Kolab_Server_Exception If the given information contains errors.
  141. */
  142. public function prepareObjectInformation(array &$info)
  143. {
  144. $cn = Horde_Kolab_Server_Object_Attribute_Cn::NAME;
  145. $sn = Horde_Kolab_Server_Object_Attribute_Sn::NAME;
  146. if (!$this->exists() && empty($info[$cn]) && !empty($info[$sn])) {
  147. $info[$cn] = $info[$sn];
  148. }
  149. if (!empty($info[self::ATTRIBUTE_USERPASSWORD])) {
  150. $info[self::ATTRIBUTE_USERPASSWORD] = $this->hashPassword($info[self::ATTRIBUTE_USERPASSWORD]);
  151. } else if (isset($info[self::ATTRIBUTE_USERPASSWORD])) {
  152. unset($info[self::ATTRIBUTE_USERPASSWORD]);
  153. }
  154. }
  155. }