Skip to content

Commit 0155edc

Browse files
authored
Merge pull request #14778 from nextcloud/user_ldap_createuser_fix
Fix user creation using LDAP Plugin
2 parents 651495e + 61572a5 commit 0155edc

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

apps/user_ldap/lib/Group_LDAP.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ public function addToGroup($uid, $gid) {
11711171
if ($this->groupPluginManager->implementsActions(GroupInterface::ADD_TO_GROUP)) {
11721172
if ($ret = $this->groupPluginManager->addToGroup($uid, $gid)) {
11731173
$this->access->connection->clearCache();
1174+
unset($this->cachedGroupMembers[$gid]);
11741175
}
11751176
return $ret;
11761177
}
@@ -1188,6 +1189,7 @@ public function removeFromGroup($uid, $gid) {
11881189
if ($this->groupPluginManager->implementsActions(GroupInterface::REMOVE_FROM_GROUP)) {
11891190
if ($ret = $this->groupPluginManager->removeFromGroup($uid, $gid)) {
11901191
$this->access->connection->clearCache();
1192+
unset($this->cachedGroupMembers[$gid]);
11911193
}
11921194
return $ret;
11931195
}

apps/user_ldap/lib/UserPluginManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function implementsActions($actions) {
8484
*
8585
* @param string $username The username of the user to create
8686
* @param string $password The password of the new user
87-
* @return bool
87+
* @return string | false The user DN if user creation was successful.
8888
* @throws \Exception
8989
*/
9090
public function createUser($username, $password) {

apps/user_ldap/lib/User_LDAP.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,20 @@ public function getNewLDAPConnection($uid) {
615615
* create new user
616616
* @param string $username username of the new user
617617
* @param string $password password of the new user
618-
* @return bool was the user created?
618+
* @throws \UnexpectedValueException
619+
* @return bool
619620
*/
620621
public function createUser($username, $password) {
621622
if ($this->userPluginManager->implementsActions(Backend::CREATE_USER)) {
622-
return $this->userPluginManager->createUser($username, $password);
623+
if ($dn = $this->userPluginManager->createUser($username, $password)) {
624+
if (is_string($dn)) {
625+
//updates user mapping
626+
$this->access->dn2ocname($dn, $username, true);
627+
} else {
628+
throw new \UnexpectedValueException("LDAP Plugin: Method createUser changed to return the user DN instead of boolean.");
629+
}
630+
}
631+
return (bool) $dn;
623632
}
624633
return false;
625634
}

apps/user_ldap/tests/User_LDAPTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ public function testCreateUserWithPlugin() {
14221422
->with('uid','password')
14231423
->willReturn('result');
14241424

1425-
$this->assertEquals($this->backend->createUser('uid', 'password'),'result');
1425+
$this->assertEquals($this->backend->createUser('uid', 'password'),true);
14261426
}
14271427

14281428
public function testCreateUserFailing() {

0 commit comments

Comments
 (0)