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