summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-11-03 12:06:04 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-11-03 12:06:04 (GMT)
commit3e93d76e5163daf454c06d335960b7350b035aba (patch)
tree6eab40165562454d3b36366c9a1490130db84fd4
parent7bc79c68dd1635821fb4d379c15590b521d98979 (diff)
downloadkolab-wap-3e93d76e5163daf454c06d335960b7350b035aba.tar.gz
Skip redundant ldap read for additional attributes (#3859)
-rw-r--r--lib/Auth.php28
-rw-r--r--lib/api/kolab_api_service_domain.php3
-rw-r--r--lib/api/kolab_api_service_group.php6
-rw-r--r--lib/api/kolab_api_service_ou.php6
-rw-r--r--lib/api/kolab_api_service_resource.php6
-rw-r--r--lib/api/kolab_api_service_role.php6
-rw-r--r--lib/api/kolab_api_service_sharedfolder.php6
-rw-r--r--lib/api/kolab_api_service_user.php8
-rw-r--r--lib/kolab_api_service.php50
9 files changed, 84 insertions, 35 deletions
diff --git a/lib/Auth.php b/lib/Auth.php
index b492f86..465f29d 100644
--- a/lib/Auth.php
+++ b/lib/Auth.php
@@ -211,9 +211,9 @@ class Auth {
return $this->auth_instance()->domain_find_by_attribute($attribute);
}
- public function domain_info($domaindata)
+ public function domain_info($domaindata, $attributes = array('*'))
{
- return $this->auth_instance()->domain_info($domaindata);
+ return $this->auth_instance()->domain_info($domaindata, $attributes);
}
public function domain_is_empty($domain)
@@ -262,9 +262,9 @@ class Auth {
return $this->auth_instance()->group_find_by_attribute($attribute);
}
- public function group_info($groupdata)
+ public function group_info($groupdata, $attributes = array('*'))
{
- return $this->auth_instance()->group_info($groupdata);
+ return $this->auth_instance()->group_info($groupdata, $attributes);
}
public function group_members_list($groupdata, $recurse = true)
@@ -332,9 +332,9 @@ class Auth {
return $this->auth_instance()->organizationalunit_find_by_attribute($attribute);
}
- public function organizationalunit_info($resourcedata)
+ public function organizationalunit_info($resourcedata, $attributes = array('*'))
{
- return $this->auth_instance()->organizationalunit_info($resourcedata);
+ return $this->auth_instance()->organizationalunit_info($resourcedata, $attributes);
}
public function resource_add($attributes, $typeid = null)
@@ -357,9 +357,9 @@ class Auth {
return $this->auth_instance()->resource_find_by_attribute($attribute);
}
- public function resource_info($resourcedata)
+ public function resource_info($resourcedata, $attributes = array('*'))
{
- return $this->auth_instance()->resource_info($resourcedata);
+ return $this->auth_instance()->resource_info($resourcedata, $attributes);
}
public function role_add($role, $typeid = null)
@@ -382,9 +382,9 @@ class Auth {
return $this->auth_instance()->role_find_by_attribute($attribute);
}
- public function role_info($roledata)
+ public function role_info($roledata, $attributes = array('*'))
{
- return $this->auth_instance()->role_info($roledata);
+ return $this->auth_instance()->role_info($roledata, $attributes);
}
public function sharedfolder_add($attributes, $typeid = null)
@@ -407,9 +407,9 @@ class Auth {
return $this->auth_instance()->sharedfolder_find_by_attribute($attribute);
}
- public function sharedfolder_info($sharedfolderdata)
+ public function sharedfolder_info($sharedfolderdata, $attributes = array('*'))
{
- return $this->auth_instance()->sharedfolder_info($sharedfolderdata);
+ return $this->auth_instance()->sharedfolder_info($sharedfolderdata, $attributes);
}
public function search()
@@ -449,9 +449,9 @@ class Auth {
return $this->auth_instance()->user_find_by_attribute($attribute);
}
- public function user_info($userdata)
+ public function user_info($userdata, $attributes = array('*'))
{
- return $this->auth_instance()->user_info($userdata);
+ return $this->auth_instance()->user_info($userdata, $attributes);
}
public function schema_attributes($object_classes)
diff --git a/lib/api/kolab_api_service_domain.php b/lib/api/kolab_api_service_domain.php
index 16b1908..dcc8778 100644
--- a/lib/api/kolab_api_service_domain.php
+++ b/lib/api/kolab_api_service_domain.php
@@ -250,7 +250,8 @@ class kolab_api_service_domain extends kolab_api_service
}
$auth = Auth::get_instance();
- $result = $auth->domain_info($getdata['id']);
+ $attrs = $this->object_attributes('domain');
+ $result = $auth->domain_info($getdata['id'], $attrs);
// normalize result
$result = $this->parse_result_attributes('domain', $result);
diff --git a/lib/api/kolab_api_service_group.php b/lib/api/kolab_api_service_group.php
index ebcd43e..3b3d547 100644
--- a/lib/api/kolab_api_service_group.php
+++ b/lib/api/kolab_api_service_group.php
@@ -155,7 +155,8 @@ class kolab_api_service_group extends kolab_api_service
}
$auth = Auth::get_instance();
- $result = $auth->group_info($getdata['id']);
+ $attrs = $this->object_attributes('group');
+ $result = $auth->group_info($getdata['id'], $attrs);
// normalize result
$result = $this->parse_result_attributes('group', $result);
@@ -194,7 +195,8 @@ class kolab_api_service_group extends kolab_api_service
}
// get group data
- $result = $auth->group_info(key($groups['list']));
+ $attrs = $this->object_attributes('group');
+ $result = $auth->group_info(key($groups['list']), $attrs);
// normalize result
$result = $this->parse_result_attributes('group', $result);
diff --git a/lib/api/kolab_api_service_ou.php b/lib/api/kolab_api_service_ou.php
index 871e932..7d0c7d7 100644
--- a/lib/api/kolab_api_service_ou.php
+++ b/lib/api/kolab_api_service_ou.php
@@ -163,7 +163,8 @@ class kolab_api_service_ou extends kolab_api_service
}
$auth = Auth::get_instance();
- $result = $auth->organizationalunit_info($getdata['id']);
+ $attrs = $this->object_attributes('ou');
+ $result = $auth->organizationalunit_info($getdata['id'], $attrs);
// normalize result
$result = $this->parse_result_attributes('ou', $result);
@@ -206,7 +207,8 @@ class kolab_api_service_ou extends kolab_api_service
}
// get OU data
- $result = $auth->organizationalunit_info(key($units['list']));
+ $attrs = $this->object_attributes('ou');
+ $result = $auth->organizationalunit_info(key($units['list']), $attrs);
// normalize result
$result = $this->parse_result_attributes('ou', $result);
diff --git a/lib/api/kolab_api_service_resource.php b/lib/api/kolab_api_service_resource.php
index 55c93de..4e96070 100644
--- a/lib/api/kolab_api_service_resource.php
+++ b/lib/api/kolab_api_service_resource.php
@@ -168,7 +168,8 @@ class kolab_api_service_resource extends kolab_api_service
}
// get resource data
- $result = $auth->resource_info(key($resources['list']));
+ $attrs = $this->object_attributes('resource');
+ $result = $auth->resource_info(key($resources['list']), $attrs);
// normalize result
$result = $this->parse_result_attributes('resource', $result);
@@ -195,7 +196,8 @@ class kolab_api_service_resource extends kolab_api_service
}
$auth = Auth::get_instance();
- $result = $auth->resource_info($getdata['id']);
+ $attrs = $this->object_attributes('resource');
+ $result = $auth->resource_info($getdata['id'], $attrs);
// normalize result
$result = $this->parse_result_attributes('resource', $result);
diff --git a/lib/api/kolab_api_service_role.php b/lib/api/kolab_api_service_role.php
index 04d4c52..f6353b0 100644
--- a/lib/api/kolab_api_service_role.php
+++ b/lib/api/kolab_api_service_role.php
@@ -169,7 +169,8 @@ class kolab_api_service_role extends kolab_api_service
}
$auth = Auth::get_instance();
- $result = $auth->role_info($getdata['id']);
+ $attrs = $this->object_attributes('role');
+ $result = $auth->role_info($getdata['id'], $attrs);
// normalize result
$result = $this->parse_result_attributes('role', $result);
@@ -206,7 +207,8 @@ class kolab_api_service_role extends kolab_api_service
}
// get role data
- $result = $auth->role_info(key($roles['list']));
+ $attrs = $this->object_attributes('role');
+ $result = $auth->role_info(key($roles['list']), $attrs);
// normalize result
$result = $this->parse_result_attributes('role', $result);
diff --git a/lib/api/kolab_api_service_sharedfolder.php b/lib/api/kolab_api_service_sharedfolder.php
index 1b02431..b828f81 100644
--- a/lib/api/kolab_api_service_sharedfolder.php
+++ b/lib/api/kolab_api_service_sharedfolder.php
@@ -158,7 +158,8 @@ class kolab_api_service_sharedfolder extends kolab_api_service
}
$auth = Auth::get_instance();
- $result = $auth->sharedfolder_info($getdata['id']);
+ $attrs = $this->object_attributes('sharedfolder');
+ $result = $auth->sharedfolder_info($getdata['id'], $attrs);
// normalize result
$result = $this->parse_result_attributes('sharedfolder', $result);
@@ -195,7 +196,8 @@ class kolab_api_service_sharedfolder extends kolab_api_service
}
// get shared folder data
- $result = $auth->sharedfolder_info(key($sharedfolders['list']));
+ $attrs = $this->object_attributes('sharedfolder');
+ $result = $auth->sharedfolder_info(key($sharedfolders['list']), $attrs);
// normalize result
$result = $this->parse_result_attributes('sharedfolder', $result);
diff --git a/lib/api/kolab_api_service_user.php b/lib/api/kolab_api_service_user.php
index 33e055a..436f96b 100644
--- a/lib/api/kolab_api_service_user.php
+++ b/lib/api/kolab_api_service_user.php
@@ -168,9 +168,8 @@ class kolab_api_service_user extends kolab_api_service
}
$auth = Auth::get_instance();
- $result = $auth->user_info($getdata['id']);
-
- Log::trace("user.info on " . $getdata['id'] . " result: " . var_export($result, TRUE));
+ $attrs = $this->object_attributes('user');
+ $result = $auth->user_info($getdata['id'], $attrs);
// normalize result
$result = $this->parse_result_attributes('user', $result);
@@ -213,7 +212,8 @@ class kolab_api_service_user extends kolab_api_service
}
// get user data
- $result = $auth->user_info(key($users['list']));
+ $attrs = $this->object_attributes('user');
+ $result = $auth->user_info(key($users['list']), $attrs);
// normalize result
$result = $this->parse_result_attributes('user', $result);
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 0049b8f..e881a78 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -471,13 +471,10 @@ abstract class kolab_api_service
*/
protected function parse_result_attributes($object_name, $attrs = array())
{
- //console("parse_result_attributes($object_name, \$attrs = ", $attrs);
-
if (empty($attrs) || !is_array($attrs)) {
return $attrs;
}
- $auth = Auth::get_instance();
$dn = key($attrs);
$attrs = $attrs[$dn];
$extra_attrs = array();
@@ -486,7 +483,6 @@ abstract class kolab_api_service
// Search for attributes associated with the type_id that are not part
// of the result returned earlier. Example: nsrole / nsroledn / aci, etc.
- // @TODO: this should go to LDAP class
if ($type_id) {
$uta = $this->object_type_attributes($object_name, $type_id);
@@ -506,8 +502,10 @@ abstract class kolab_api_service
// remove attributes not listed in object type definition
// @TODO: make this optional?
$attributes = array_flip(array_merge($attributes, array($unique_attr)));
- $attrs = array_intersect_key($attrs, $attributes);
+ $attrs = array_intersect_key($attrs, $attributes);
}
+/*
+ $auth = Auth::get_instance();
// Insert the persistent, unique attribute
if (!array_key_exists($unique_attr, $attrs)) {
@@ -522,7 +520,7 @@ abstract class kolab_api_service
$attrs = array_merge($attrs, $extra_attrs);
}
}
-
+*/
// Replace unique attribute with 'id' key
$attrs['id'] = $attrs[$unique_attr];
unset($attrs[$unique_attr]);
@@ -545,6 +543,46 @@ abstract class kolab_api_service
}
/**
+ * Returns all supported attributes of specified object type
+ *
+ * @param string $object_name Name of the object (user, group, etc.)
+ *
+ * @return array Entry attributes
+ */
+ protected function object_attributes($object_name)
+ {
+ $unique_attr = self::unique_attribute();
+ $object_types = $this->object_types($object_name);
+ $attributes = array();
+
+ // because we don't know the object type identifier before
+ // we get it from LDAP we need to get try attributes of all types
+ foreach ($object_types as $type) {
+ $attributes = array_merge(
+ $attributes,
+ array_keys((array) $type['attributes']['auto_form_fields']),
+ array_keys((array) $type['attributes']['form_fields']),
+ array_keys((array) $type['attributes']['fields'])
+ );
+ }
+
+ // use array_values, because ldap_read() does not like an array
+ // with removed elements (holes in the index)
+ $attributes = array_values(array_unique($attributes));
+
+ if (empty($attributes)) {
+ $attributes = array('*');
+ }
+
+ // Insert the persistent, unique attribute
+ if (!array_key_exists($unique_attr, $attributes)) {
+ $attributes[] = $unique_attr;
+ }
+
+ return $attributes;
+ }
+
+ /**
* Compare two score values
*
* @param string $s1 Score