From c4dbc428f9677a03b3f873eaba9282cfd227d876 Mon Sep 17 00:00:00 2001 From: Vinicius Cubas Brand Date: Fri, 1 Mar 2019 12:12:19 -0300 Subject: [PATCH 1/3] fix user creation using LDAP Plugin Signed-off-by: Vinicius Cubas Brand --- apps/user_ldap/lib/UserPluginManager.php | 2 +- apps/user_ldap/lib/User_LDAP.php | 12 ++++++++++-- apps/user_ldap/tests/User_LDAPTest.php | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/user_ldap/lib/UserPluginManager.php b/apps/user_ldap/lib/UserPluginManager.php index 5bf36dfe08fe5..85eaae29daa4f 100644 --- a/apps/user_ldap/lib/UserPluginManager.php +++ b/apps/user_ldap/lib/UserPluginManager.php @@ -84,7 +84,7 @@ public function implementsActions($actions) { * * @param string $username The username of the user to create * @param string $password The password of the new user - * @return bool + * @return string | false The user DN if user creation was successful. * @throws \Exception */ public function createUser($username, $password) { diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index fbdf1cc255132..855c13e13fba6 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -615,11 +615,19 @@ public function getNewLDAPConnection($uid) { * create new user * @param string $username username of the new user * @param string $password password of the new user - * @return bool was the user created? + * @return bool */ public function createUser($username, $password) { if ($this->userPluginManager->implementsActions(Backend::CREATE_USER)) { - return $this->userPluginManager->createUser($username, $password); + if ($dn = $this->userPluginManager->createUser($username, $password)) { + if (is_string($dn)) { + //updates user mapping + $this->access->dn2ocname($dn, $username, true); + } else { + throw new \Exception("LDAP Plugin: Method createUser changed to return the user DN instead of boolean."); + } + } + return (bool) $dn; } return false; } diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php index 693159dc72b15..f58c5f881f941 100644 --- a/apps/user_ldap/tests/User_LDAPTest.php +++ b/apps/user_ldap/tests/User_LDAPTest.php @@ -1422,7 +1422,7 @@ public function testCreateUserWithPlugin() { ->with('uid','password') ->willReturn('result'); - $this->assertEquals($this->backend->createUser('uid', 'password'),'result'); + $this->assertEquals($this->backend->createUser('uid', 'password'),true); } public function testCreateUserFailing() { From a2c38148e7b7390884e89b8fee252a1914b6ccf9 Mon Sep 17 00:00:00 2001 From: Vinicius Cubas Brand Date: Mon, 4 Mar 2019 14:09:27 -0300 Subject: [PATCH 2/3] Cache cleaning when subadmin adds user to group This commit fix an error happening when the subadmin tries to create an user, adding him/her to the group s/he is subadmin of, using a LDAP User/Group plugin. This just forces the cache to be reset after an user is added to a group. Signed-off-by: Vinicius Cubas Brand --- apps/user_ldap/lib/Group_LDAP.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php index 1658807c0dd96..cd4bd18cb4465 100644 --- a/apps/user_ldap/lib/Group_LDAP.php +++ b/apps/user_ldap/lib/Group_LDAP.php @@ -1171,6 +1171,7 @@ public function addToGroup($uid, $gid) { if ($this->groupPluginManager->implementsActions(GroupInterface::ADD_TO_GROUP)) { if ($ret = $this->groupPluginManager->addToGroup($uid, $gid)) { $this->access->connection->clearCache(); + unset($this->cachedGroupMembers[$gid]); } return $ret; } @@ -1188,6 +1189,7 @@ public function removeFromGroup($uid, $gid) { if ($this->groupPluginManager->implementsActions(GroupInterface::REMOVE_FROM_GROUP)) { if ($ret = $this->groupPluginManager->removeFromGroup($uid, $gid)) { $this->access->connection->clearCache(); + unset($this->cachedGroupMembers[$gid]); } return $ret; } From 61572a5b2e92182c6fea17855abd9b2b4f942334 Mon Sep 17 00:00:00 2001 From: Vinicius Cubas Brand Date: Thu, 14 Mar 2019 11:59:27 -0300 Subject: [PATCH 3/3] LDAP plugin: force createUser to return new user's DN LDAP plugins must change the createUser method to return the DN, as we need this to update the cache. Signed-off-by: Vinicius Cubas Brand --- apps/user_ldap/lib/User_LDAP.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index 855c13e13fba6..e69eafecc86db 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -615,6 +615,7 @@ public function getNewLDAPConnection($uid) { * create new user * @param string $username username of the new user * @param string $password password of the new user + * @throws \UnexpectedValueException * @return bool */ public function createUser($username, $password) { @@ -624,7 +625,7 @@ public function createUser($username, $password) { //updates user mapping $this->access->dn2ocname($dn, $username, true); } else { - throw new \Exception("LDAP Plugin: Method createUser changed to return the user DN instead of boolean."); + throw new \UnexpectedValueException("LDAP Plugin: Method createUser changed to return the user DN instead of boolean."); } } return (bool) $dn;