summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorBrice Maron <brice@bmaron.net>2012-06-07 19:11:55 +0000
committerBrice Maron <brice@bmaron.net>2012-06-07 19:11:55 +0000
commitcf02f3c1078b4b46fbf20d6269759b2b9b55aed8 (patch)
treebc299b72312734184deae602d87c57b0d45dee6d /apps/user_ldap
parente8447e0bda25744c4836a8fdf009a98174264eda (diff)
parentd4f6f3e9355979aedb174d6f9b5f60380934aca9 (diff)
downloadnextcloud-server-cf02f3c1078b4b46fbf20d6269759b2b9b55aed8.tar.gz
nextcloud-server-cf02f3c1078b4b46fbf20d6269759b2b9b55aed8.zip
Merge branch 'master' into multi_app_dir
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/group_ldap.php40
-rw-r--r--apps/user_ldap/lib_ldap.php45
-rw-r--r--apps/user_ldap/user_ldap.php13
3 files changed, 57 insertions, 41 deletions
diff --git a/apps/user_ldap/group_ldap.php b/apps/user_ldap/group_ldap.php
index baca1d32bad..62e7c8ca6bc 100644
--- a/apps/user_ldap/group_ldap.php
+++ b/apps/user_ldap/group_ldap.php
@@ -27,6 +27,11 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
protected $ldapGroupMemberAssocAttr;
protected $configured = false;
+ protected $_group_user = array();
+ protected $_user_groups = array();
+ protected $_group_users = array();
+ protected $_groups = array();
+
public function __construct() {
$this->ldapGroupFilter = OCP\Config::getAppValue('user_ldap', 'ldap_group_filter', '(objectClass=posixGroup)');
$this->ldapGroupMemberAssocAttr = OCP\Config::getAppValue('user_ldap', 'ldap_group_member_assoc_attribute', 'uniqueMember');
@@ -48,6 +53,9 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
if(!$this->configured) {
return false;
}
+ if(isset($this->_group_user[$gid][$uid])) {
+ return $this->_group_user[$gid][$uid];
+ }
$dn_user = OC_LDAP::username2dn($uid);
$dn_group = OC_LDAP::groupname2dn($gid);
// just in case
@@ -64,8 +72,8 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
//TODO: this can be done with one LDAP query
if(strtolower($this->ldapGroupMemberAssocAttr) == 'memberuid') {
$dns = array();
- foreach($members as $uid) {
- $filter = str_replace('%uid', $uid, OC_LDAP::conf('ldapLoginFilter'));
+ foreach($members as $mid) {
+ $filter = str_replace('%uid', $mid, OC_LDAP::conf('ldapLoginFilter'));
$ldap_users = OC_LDAP::fetchListOfUsers($filter, 'dn');
if(count($ldap_users) < 1) {
continue;
@@ -75,7 +83,8 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
$members = $dns;
}
- return in_array($dn_user, $members);
+ $this->_group_user[$gid][$uid] = in_array($dn_user, $members);
+ return $this->_group_user[$gid][$uid];
}
/**
@@ -90,8 +99,12 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
if(!$this->configured) {
return array();
}
+ if(isset($this->_user_groups[$uid])) {
+ return $this->_user_groups[$uid];
+ }
$userDN = OC_LDAP::username2dn($uid);
if(!$userDN) {
+ $this->_user_groups[$uid] = array();
return array();
}
@@ -112,9 +125,9 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
$this->ldapGroupMemberAssocAttr.'='.$uid
));
$groups = OC_LDAP::fetchListOfGroups($filter, array(OC_LDAP::conf('ldapGroupDisplayName'),'dn'));
- $userGroups = OC_LDAP::ownCloudGroupNames($groups);
+ $this->_user_groups[$uid] = array_unique(OC_LDAP::ownCloudGroupNames($groups), SORT_LOCALE_STRING);
- return array_unique($userGroups, SORT_LOCALE_STRING);
+ return $this->_user_groups[$uid];
}
/**
@@ -125,14 +138,19 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
if(!$this->configured) {
return array();
}
+ if(isset($this->_group_users[$gid])) {
+ return $this->_group_users[$gid];
+ }
$groupDN = OC_LDAP::groupname2dn($gid);
if(!$groupDN) {
+ $this->_group_users[$gid] = array();
return array();
}
$members = OC_LDAP::readAttribute($groupDN, $this->ldapGroupMemberAssocAttr);
if(!$members) {
+ $this->_group_users[$gid] = array();
return array();
}
@@ -154,7 +172,8 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
if(!$isMemberUid) {
$result = array_intersect($result, OCP\User::getUsers());
}
- return array_unique($result, SORT_LOCALE_STRING);
+ $this->_group_users[$gid] = array_unique($result, SORT_LOCALE_STRING);
+ return $this->_group_users[$gid];
}
/**
@@ -167,10 +186,11 @@ class OC_GROUP_LDAP extends OC_Group_Backend {
if(!$this->configured) {
return array();
}
-
- $ldap_groups = OC_LDAP::fetchListOfGroups($this->ldapGroupFilter, array(OC_LDAP::conf('ldapGroupDisplayName'), 'dn'));
- $groups = OC_LDAP::ownCloudGroupNames($ldap_groups);
- return $groups;
+ if(is_null($this->_groups)) {
+ $ldap_groups = OC_LDAP::fetchListOfGroups($this->ldapGroupFilter, array(OC_LDAP::conf('ldapGroupDisplayName'), 'dn'));
+ $this->_groups = OC_LDAP::ownCloudGroupNames($ldap_groups);
+ }
+ return $this->groups;
}
/**
diff --git a/apps/user_ldap/lib_ldap.php b/apps/user_ldap/lib_ldap.php
index f6942ad326e..22d464b65a2 100644
--- a/apps/user_ldap/lib_ldap.php
+++ b/apps/user_ldap/lib_ldap.php
@@ -52,6 +52,8 @@ class OC_LDAP {
static protected $ldapGroupDisplayName;
static protected $ldapLoginFilter;
+ static protected $__d;
+
/**
* @brief initializes the LDAP backend
* @param $force read the config settings no matter what
@@ -59,6 +61,9 @@ class OC_LDAP {
* initializes the LDAP backend
*/
static public function init($force = false) {
+ if(is_null(self::$__d)) {
+ self::$__d = new OC_LDAP_DESTRUCTOR();
+ }
self::readConfiguration($force);
self::establishConnection();
}
@@ -258,7 +263,7 @@ class OC_LDAP {
$key = self::recursiveArraySearch($knownObjects, $ldapObject['dn']);
//everything is fine when we know the group
- if($key) {
+ if($key !== false) {
$ownCloudNames[] = $knownObjects[$key]['owncloud_name'];
continue;
}
@@ -330,30 +335,6 @@ class OC_LDAP {
}
/**
- * @brief inserts a new group into the mappings table
- * @param $dn the record in question
- * @param $ocname the name to use in ownCloud
- * @returns true on success, false otherwise
- *
- * inserts a new group into the mappings table
- */
- static private function mapGroup($dn, $ocname) {
- return self::mapComponent($dn, $ocname, false);
- }
-
- /**
- * @brief inserts a new user into the mappings table
- * @param $dn the record in question
- * @param $ocname the name to use in ownCloud
- * @returns true on success, false otherwise
- *
- * inserts a new user into the mappings table
- */
- static private function mapUser($dn, $ocname) {
- return self::mapComponent($dn, $ocname, true);
- }
-
- /**
* @brief inserts a new user or group into the mappings table
* @param $dn the record in question
* @param $ocname the name to use in ownCloud
@@ -380,12 +361,22 @@ class OC_LDAP {
SELECT 1
FROM '.$table.'
WHERE ldap_dn = ?
- AND owncloud_name = ? )
+ OR owncloud_name = ? )
');
$res = $insert->execute(array($dn, $ocname, $dn, $ocname));
- return !OCP\DB::isError($res);
+ if(OCP\DB::isError($res)) {
+ return false;
+ }
+
+ $insRows = $res->numRows();
+
+ if($insRows == 0) {
+ return false;
+ }
+
+ return true;
}
static public function fetchListOfUsers($filter, $attr) {
diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php
index ba66c7a9ca8..9281aebe81d 100644
--- a/apps/user_ldap/user_ldap.php
+++ b/apps/user_ldap/user_ldap.php
@@ -34,6 +34,9 @@ class OC_USER_LDAP extends OC_User_Backend {
// will be retrieved from LDAP server
protected $ldap_dc = false;
+ // cache getUsers()
+ protected $_users = null;
+
public function __construct() {
$this->ldapUserFilter = OCP\Config::getAppValue('user_ldap', 'ldap_userlist_filter', '(objectClass=posixAccount)');
$this->ldapQuotaAttribute = OCP\Config::getAppValue('user_ldap', 'ldap_quota_attr', '');
@@ -108,9 +111,11 @@ class OC_USER_LDAP extends OC_User_Backend {
* Get a list of all users.
*/
public function getUsers(){
- $ldap_users = OC_LDAP::fetchListOfUsers($this->ldapUserFilter, array(OC_LDAP::conf('ldapUserDisplayName'), 'dn'));
- $users = OC_LDAP::ownCloudUserNames($ldap_users);
- return $users;
+ if(is_null($this->_users)) {
+ $ldap_users = OC_LDAP::fetchListOfUsers($this->ldapUserFilter, array(OC_LDAP::conf('ldapUserDisplayName'), 'dn'));
+ $this->_users = OC_LDAP::ownCloudUserNames($ldap_users);
+ }
+ return $this->_users;
}
/**
@@ -119,7 +124,7 @@ class OC_USER_LDAP extends OC_User_Backend {
* @return boolean
*/
public function userExists($uid){
- return in_array($uid, self::getUsers());
+ return in_array($uid, $this->getUsers());
}
}