* Fetch a Kolab object.
*
* This method will not necessarily retrieve any data from the server and
- * might simply generate a new instance for hte desired object. This method
+ * might simply generate a new instance for the desired object. This method
* can also be used in order to fetch non-existing objects that will be
* saved later.
*
}
/**
+ * Generates a unique ID for the given information.
+ *
+ * @param string $type The type of the object to create.
+ * @param array $info Any additional information about the object to create.
+ *
+ * @return string|PEAR_Error The UID.
+ */
+ public function generateUid($type, $info)
+ {
+ if (!class_exists($type)) {
+ $result = Horde_Kolab_Server_Object::loadClass($type);
+ if (is_a($result, 'PEAR_Error')) {
+ return $result;
+ }
+ }
+
+ $id = call_user_func(array($type, 'generateId'), $info);
+ if (is_a($id, 'PEAR_Error')) {
+ return $id;
+ }
+ return $this->generateServerUid($type, $id, $info);
+ }
+
+ /**
* Add a Kolab object.
*
* @param array $info The object to store.
}
/**
- * Return the root of the UID values on this server.
- *
- * @return string The base UID on this server (base DN on ldap).
- */
- public function getBaseUid()
- {
- return '';
- }
-
- /**
- * Identify the primary mail attribute for the first object found
- * with the given ID or mail.
- *
- * @param string $id Search for objects with this ID/mail.
- *
- * @return mixed|PEAR_Error The mail address or false if there was
- * no result.
- */
- public function mailForIdOrMail($id)
- {
- /* In the default class we just return the id */
- return $id;
- }
-
- /**
- * Returns a list of allowed email addresses for the given user.
- *
- * @param string $user The user name.
- *
- * @return array|PEAR_Error An array of allowed mail addresses.
- */
- public function addrsForIdOrMail($user)
- {
- /* In the default class we just return the user name */
- return $user;
- }
-
- /**
- * Return the UID for a given primary mail, uid, or alias.
- *
- * @param string $mail A valid mail address for the user.
- *
- * @return mixed|PEAR_Error The UID or false if there was no result.
- */
- public function uidForMailAddress($mail)
- {
- /* In the default class we just return the mail address */
- return $mail;
- }
-
- /**
- * Identify the UID for the first user found using a specified
- * attribute value.
- *
- * @param string $attr The name of the attribute used for searching.
- * @param string $value The desired value of the attribute.
- * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction.
- *
- * @return mixed|PEAR_Error The UID or false if there was no result.
- */
- public function uidForAttr($attr, $value,
- $restrict = KOLAB_SERVER_RESULT_SINGLE)
- {
- /* In the default class we just return false */
- return false;
- }
-
- /**
- * Identify the GID for the first group found using a specified
- * attribute value.
- *
- * @param string $attr The name of the attribute used for searching.
- * @param string $value The desired value of the attribute.
- * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction.
- *
- * @return mixed|PEAR_Error The GID or false if there was no result.
- */
- public function gidForAttr($attr, $value,
- $restrict = KOLAB_SERVER_RESULT_SINGLE)
- {
- /* In the default class we just return false */
- return false;
- }
-
- /**
- * Is the given UID member of the group with the given mail address?
- *
- * @param string $uid UID of the user.
- * @param string $mail Search the group with this mail address.
- *
- * @return boolean|PEAR_Error True in case the user is in the
- * group, false otherwise.
- */
- public function memberOfGroupAddress($uid, $mail)
- {
- /* No groups in the default class */
- return false;
- }
-
- /**
* Identify the UID for the first object found with the given ID.
*
* @param string $id Search for objects with this ID.
}
/**
- * Identify the GID for the first group found with the given mail.
+ * Identify the UID for the first object found with the given alias.
*
- * @param string $mail Search for groups with this mail address.
+ * @param string $mail Search for objects with this mail alias.
* @param int $restrict A KOLAB_SERVER_RESULT_* result restriction.
*
- * @return mixed|PEAR_Error The GID or false if there was no result.
+ * @return mixed|PEAR_Error The UID or false if there was no result.
*/
- public function gidForMail($mail,
- $restrict = KOLAB_SERVER_RESULT_SINGLE)
+ public function uidForAlias($mail,
+ $restrict = KOLAB_SERVER_RESULT_SINGLE)
{
- return $this->gidForAttr('mail', $mail);
+ return $this->uidForAttr('alias', $mail);
}
/**
}
/**
- * Identify the UID for the first object found with the given alias.
- *
- * @param string $mail Search for objects with this mail alias.
- * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction.
- *
- * @return mixed|PEAR_Error The UID or false if there was no result.
- */
- public function uidForAlias($mail,
- $restrict = KOLAB_SERVER_RESULT_SINGLE)
- {
- return $this->uidForAttr('alias', $mail);
- }
-
- /**
* Identify the UID for the first object found with the given mail
* address or alias.
*
*
* @return mixed|PEAR_Error The UID or false if there was no result.
*/
- public function uidForMailOrIdOrAlias($id)
+ public function uidForIdOrMailOrAlias($id)
{
$uid = $this->uidForAttr('uid', $id);
if (!$uid) {
}
/**
+ * Identify the primary mail attribute for the first object found
+ * with the given ID or mail.
+ *
+ * @param string $id Search for objects with this ID/mail.
+ *
+ * @return mixed|PEAR_Error The mail address or false if there was
+ * no result.
+ */
+ public function mailForIdOrMail($id)
+ {
+ $uid = $this->uidForIdOrMail($id);
+ $data = $this->read($uid, array('mail'));
+ return $data['mail'];
+ }
+
+ /**
+ * Returns a list of allowed email addresses for the given user.
+ *
+ * @param string $id Search for objects with this ID/mail.
+ *
+ * @return array|PEAR_Error An array of allowed mail addresses.
+ */
+ public function addrsForIdOrMail($id)
+ {
+ $uid = $this->uidForIdOrMail($id);
+ $data = $this->read($uid, array('mail', 'alias'));
+ return array_merge($data['mail'], $data['alias']);
+ }
+
+ /**
+ * Identify the GID for the first group found with the given mail.
+ *
+ * @param string $mail Search for groups with this mail address.
+ * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction.
+ *
+ * @return mixed|PEAR_Error The GID or false if there was no result.
+ */
+ public function gidForMail($mail,
+ $restrict = KOLAB_SERVER_RESULT_SINGLE)
+ {
+ return $this->gidForAttr('mail', $mail);
+ }
+
+ /**
+ * Is the given UID member of the group with the given mail address?
+ *
+ * @param string $uid UID of the user.
+ * @param string $mail Search the group with this mail address.
+ *
+ * @return boolean|PEAR_Error True in case the user is in the
+ * group, false otherwise.
+ */
+ public function memberOfGroupAddress($uid, $mail)
+ {
+ $gid = $this->gidForMail($mail);
+ $data = $this->read($gid, array('member'));
+ return in_array($uid, $data['member']);
+ }
+
+ /**
* Generate a hash representation for a list of objects.
*
* @param string $type The type of the objects to be listed
}
/**
- * Generates a unique ID for the given information.
- *
- * @param string $type The type of the object to create.
- * @param array $info Any additional information about the object to create.
- *
- * @return string|PEAR_Error The UID.
- */
- public function generateUid($type, $info)
- {
- if (!class_exists($type)) {
- $result = Horde_Kolab_Server_Object::loadClass($type);
- if (is_a($result, 'PEAR_Error')) {
- return $result;
- }
- }
-
- $id = call_user_func(array($type, 'generateId'), $info);
- if (is_a($id, 'PEAR_Error')) {
- return $id;
- }
- return $this->generateServerUid($type, $id, $info);
- }
-
- /**
* Stub for reading object data.
*
* @param string $uid The object to retrieve.
*/
abstract protected function generateServerUid($type, $id, $info);
+ /**
+ * Return the root of the UID values on this server.
+ *
+ * @return string The base UID on this server (base DN on ldap).
+ */
+ abstract public function getBaseUid();
+
+ /**
+ * Identify the UID for the first user found using a specified
+ * attribute value.
+ *
+ * @param string $attr The name of the attribute used for searching.
+ * @param string $value The desired value of the attribute.
+ * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction.
+ *
+ * @return mixed|PEAR_Error The UID or false if there was no result.
+ */
+ abstract public function uidForAttr($attr, $value,
+ $restrict = KOLAB_SERVER_RESULT_SINGLE);
+
+ /**
+ * Identify the GID for the first group found using a specified
+ * attribute value.
+ *
+ * @param string $attr The name of the attribute used for searching.
+ * @param string $value The desired value of the attribute.
+ * @param int $restrict A KOLAB_SERVER_RESULT_* result restriction.
+ *
+ * @return mixed|PEAR_Error The GID or false if there was no result.
+ */
+ abstract public function gidForAttr($attr, $value,
+ $restrict = KOLAB_SERVER_RESULT_SINGLE);
+
}
*/
public function testUidForMailOrIdOrAlias()
{
- $uid = $this->ldap->uidForMailOrIdOrAlias('g.wrobel@example.org');
+ $uid = $this->ldap->uidForIdOrMailOrAlias('g.wrobel@example.org');
$this->assertNoError($uid);
$this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid);
- $uid = $this->ldap->uidForMailOrIdOrAlias('wrobel@example.org');
+ $uid = $this->ldap->uidForIdOrMailOrAlias('wrobel@example.org');
$this->assertNoError($uid);
$this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid);
- $uid = $this->ldap->uidForMailOrIdOrAlias('wrobel');
+ $uid = $this->ldap->uidForIdOrMailOrAlias('wrobel');
$this->assertNoError($uid);
$this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid);
- $uid = $this->ldap->uidForMailOrIdOrAlias('DOES NOT EXIST');
+ $uid = $this->ldap->uidForIdOrMailOrAlias('DOES NOT EXIST');
$this->assertNoError($uid);
$this->assertSame(false, $uid);
}
*/
public function testUidForMailAddress()
{
- $uid = $this->ldap->uidForMailAddress('wrobel@example.org');
+ $uid = $this->ldap->uidForIdOrMailOrAlias('wrobel@example.org');
$this->assertNoError($uid);
$this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid);
- $uid = $this->ldap->uidForMailAddress('test@example.org');
+ $uid = $this->ldap->uidForIdOrMailOrAlias('test@example.org');
$this->assertNoError($uid);
$this->assertEquals('cn=Test Test,dc=example,dc=org', $uid);
- $uid = $this->ldap->uidForMailAddress('gunnar@example.org');
+ $uid = $this->ldap->uidForIdOrMailOrAlias('gunnar@example.org');
$this->assertNoError($uid);
$this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid);
- $uid = $this->ldap->uidForMailAddress('wrobel');
+ $uid = $this->ldap->uidForIdOrMailOrAlias('wrobel');
$this->assertNoError($uid);
$this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $uid);
}
*/
public function testMemberOfGroupAddress()
{
- $uid = $this->ldap->uidForMailAddress('g.wrobel@example.org');
+ $uid = $this->ldap->uidForIdOrMailOrAlias('g.wrobel@example.org');
$this->assertNoError($uid);
$member = $this->ldap->memberOfGroupAddress($uid, 'group@example.org');
$this->assertNoError($member);
$this->assertTrue($member);
$member = $this->ldap->memberOfGroupAddress(
- $this->ldap->uidForMailAddress('test@example.org'),
+ $this->ldap->uidForIdOrMailOrAlias('test@example.org'),
'group@example.org');
$this->assertNoError($member);
$this->assertTrue($member);
$member = $this->ldap->memberOfGroupAddress(
- $this->ldap->uidForMailAddress('somebody@example.org'),
+ $this->ldap->uidForIdOrMailOrAlias('somebody@example.org'),
'group@example.org');
$this->assertNoError($member);
$this->assertFalse($member);
$this->assertNoError($groups);
$this->assertTrue(!empty($groups));
- $groups = $this->ldap->getGroups($this->ldap->uidForMailAddress('g.wrobel@example.org'));
+ $groups = $this->ldap->getGroups($this->ldap->uidForIdOrMailOrAlias('g.wrobel@example.org'));
$this->assertNoError($groups);
$this->assertContains('cn=group@example.org,dc=example,dc=org', $groups);
- $groups = $this->ldap->getGroups($this->ldap->uidForMailAddress('test@example.org'));
+ $groups = $this->ldap->getGroups($this->ldap->uidForIdOrMailOrAlias('test@example.org'));
$this->assertNoError($groups);
$this->assertContains('cn=group@example.org,dc=example,dc=org', $groups);