Skip to content

Commit 53180dc

Browse files
committed
fix user creation using LDAP Plugin
Signed-off-by: Vinicius Cubas Brand <[email protected]>
1 parent fef5189 commit 53180dc

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

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 | null The group DN if group creation was successful.
8888
* @throws \Exception
8989
*/
9090
public function createUser($username, $password) {

apps/user_ldap/lib/User_LDAP.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,13 +615,23 @@ 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+
* @return bool
619+
* @throws \Exception
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 group mapping
626+
$this->access->dn2ocname($dn, $username, true);
627+
$this->access->connection->writeToCache("userExists".$username, true);
628+
} else {
629+
throw new \Exception("LDAP Plugin: Method createUser changed to return the user DN instead of boolean.");
630+
}
631+
}
632+
return $dn != null;
623633
}
624-
return false;
634+
throw new \Exception('Could not create user in LDAP backend.');
625635
}
626636

627637
}

apps/user_ldap/tests/User_LDAPTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,16 +1422,19 @@ 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

1428+
/**
1429+
* @expectedException \Exception
1430+
*/
14281431
public function testCreateUserFailing() {
14291432
$this->pluginManager->expects($this->once())
14301433
->method('implementsActions')
14311434
->with(Backend::CREATE_USER)
14321435
->willReturn(false);
14331436

1434-
$this->assertFalse($this->backend->createUser('uid', 'password'));
1437+
$this->backend->createUser('uid', 'password');
14351438
}
14361439

14371440
public function actionProvider() {

0 commit comments

Comments
 (0)