summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2012-03-26 10:45:27 +0200
committerAleksander Machniak <machniak@kolabsys.com>2012-03-26 10:45:27 +0200
commitdc6628c308868b1091439b1e16ec1c45548c64ed (patch)
tree3cee88edc155644d7b07c996087fa9868e74a30c
parent4faca4946e79246feaa8939a3906981dca368ad6 (diff)
downloadwebadmin-dc6628c308868b1091439b1e16ec1c45548c64ed.tar.gz
Limit ldap_search() calls by fetching all extra user attributes in one call
-rw-r--r--lib/Auth.php4
-rw-r--r--lib/Auth/LDAP.php18
-rw-r--r--lib/api/kolab_api_service_user.php15
3 files changed, 24 insertions, 13 deletions
diff --git a/lib/Auth.php b/lib/Auth.php
index aae59e7..a9f11c0 100644
--- a/lib/Auth.php
+++ b/lib/Auth.php
@@ -268,9 +268,9 @@ class Auth {
return $this->_auth[$_SESSION['user']->get_domain()]->user_find_by_attribute($attribute);
}
- public function user_get_attribute($user, $attribute)
+ public function user_attributes($user, $attributes)
{
- return $this->_auth[$_SESSION['user']->get_domain()]->user_get_attribute($user, $attribute);
+ return $this->_auth[$_SESSION['user']->get_domain()]->user_attributes($user, $attributes);
}
public function user_info($userdata)
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index bd9cfc8..b5a94bf 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -437,16 +437,22 @@ class LDAP
}
}
- public function user_get_attribute($user_dn, $attribute)
+ /**
+ * User attributes
+ *
+ *
+ */
+ public function user_attributes($user_dn, $attributes)
{
- $result = $this->search($user_dn, '(objectclass=*)', array($attribute));
+ $result = $this->search($user_dn, '(objectclass=*)', $attributes);
$result = self::normalize_result($result);
- if (!empty($result) && array_key_exists($attribute, $result[$user_dn])) {
- return $result[$user_dn][$attribute];
- } else {
- return FALSE;
+ if (!empty($result)) {
+ $result = array_pop($result);
+ return $result;
}
+
+ return false;
}
public function user_info($user)
diff --git a/lib/api/kolab_api_service_user.php b/lib/api/kolab_api_service_user.php
index 61cd7ce..8c60d33 100644
--- a/lib/api/kolab_api_service_user.php
+++ b/lib/api/kolab_api_service_user.php
@@ -159,18 +159,23 @@ class kolab_api_service_user extends kolab_api_service
// Search for attributes associated with the type_id that are not part
// of the results returned earlier. Example: nsrole / nsroledn / aci, etc.
if ($result['user_type_id']) {
- $uta = $this->user_type_attributes($result['user_type_id']);
+ $uta = $this->user_type_attributes($result['user_type_id']);
+ $attrs = array();
foreach ($uta as $field_type => $attributes) {
foreach ($attributes as $attribute => $data) {
if (!array_key_exists($attribute, $result)) {
- $attribute_value = $auth->user_get_attribute($result['entrydn'], $attribute);
- if ($attribute_value) {
- $result[$attribute] = $attribute_value;
- }
+ $attrs[] = $attribute;
}
}
}
+
+ if (!empty($attrs)) {
+ $attrs = $auth->user_attributes($result['entrydn'], $attrs);
+ if (!empty($attrs)) {
+ $result = array_merge($result, $attrs);
+ }
+ }
}
if ($result) {