summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2018-03-15 14:16:43 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2018-04-05 12:38:39 +0200
commit8fe914f07e1b4d41c02e127e2242e0a770535455 (patch)
treeb101bce725bf2b9a385077008fe4b9999285acb0 /apps/user_ldap
parentfeef3cbba03c4517b25a60820e8c4534b0a02b67 (diff)
downloadnextcloud-server-8fe914f07e1b4d41c02e127e2242e0a770535455.tar.gz
nextcloud-server-8fe914f07e1b4d41c02e127e2242e0a770535455.zip
LDAP backend to emit announce and revoke signals on mapping changes
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/ajax/clearMappings.php22
-rw-r--r--apps/user_ldap/lib/Access.php2
-rw-r--r--apps/user_ldap/lib/Mapping/AbstractMapping.php26
-rw-r--r--apps/user_ldap/lib/User_LDAP.php2
-rw-r--r--apps/user_ldap/tests/Mapping/AbstractMappingTest.php23
5 files changed, 68 insertions, 7 deletions
diff --git a/apps/user_ldap/ajax/clearMappings.php b/apps/user_ldap/ajax/clearMappings.php
index 01b6b7f0ef2..009a491d349 100644
--- a/apps/user_ldap/ajax/clearMappings.php
+++ b/apps/user_ldap/ajax/clearMappings.php
@@ -33,13 +33,23 @@ use OCA\User_LDAP\Mapping\GroupMapping;
$subject = (string)$_POST['ldap_clear_mapping'];
$mapping = null;
-if($subject === 'user') {
- $mapping = new UserMapping(\OC::$server->getDatabaseConnection());
-} else if($subject === 'group') {
- $mapping = new GroupMapping(\OC::$server->getDatabaseConnection());
-}
try {
- if(is_null($mapping) || !$mapping->clear()) {
+ if($subject === 'user') {
+ $mapping = new UserMapping(\OC::$server->getDatabaseConnection());
+ $result = $mapping->clearCb(
+ function ($uid) {
+ \OC::$server->getUserManager()->emit('\OC\User', 'preRevokeUser', [$uid]);
+ },
+ function ($uid) {
+ \OC::$server->getUserManager()->emit('\OC\User', 'postRevokeUser', [$uid]);
+ }
+ );
+ } else if($subject === 'group') {
+ $mapping = new GroupMapping(\OC::$server->getDatabaseConnection());
+ $result = $mapping->clear();
+ }
+
+ if($mapping === null || !$result) {
$l = \OC::$server->getL10N('user_ldap');
throw new \Exception($l->t('Failed to clear the mappings.'));
}
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php
index 9fb37090270..c9a7cd557a1 100644
--- a/apps/user_ldap/lib/Access.php
+++ b/apps/user_ldap/lib/Access.php
@@ -609,6 +609,7 @@ class Access extends LDAPUtility implements IUserTools {
|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) {
if($mapper->map($fdn, $intName, $uuid)) {
$this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL));
+ \OC::$server->getUserManager()->emit('\OC\User', 'announceUser', [$intName]);
$newlyMapped = true;
return $intName;
}
@@ -617,6 +618,7 @@ class Access extends LDAPUtility implements IUserTools {
$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
if(is_string($altName) && $mapper->map($fdn, $altName, $uuid)) {
+ \OC::$server->getUserManager()->emit('\OC\User', 'announceUser', [$intName]);
$newlyMapped = true;
return $altName;
}
diff --git a/apps/user_ldap/lib/Mapping/AbstractMapping.php b/apps/user_ldap/lib/Mapping/AbstractMapping.php
index f5f56ce03d6..c7d737a7631 100644
--- a/apps/user_ldap/lib/Mapping/AbstractMapping.php
+++ b/apps/user_ldap/lib/Mapping/AbstractMapping.php
@@ -279,6 +279,32 @@ abstract class AbstractMapping {
}
/**
+ * clears the mapping table one by one and executing a callback with
+ * each row's id (=owncloud_name col)
+ *
+ * @param callable $preCallback
+ * @param callable $postCallback
+ * @return bool true on success, false when at least one row was not
+ * deleted
+ */
+ public function clearCb(Callable $preCallback, Callable $postCallback): bool {
+ $picker = $this->dbc->getQueryBuilder();
+ $picker->select('owncloud_name')
+ ->from($this->getTableName());
+ $cursor = $picker->execute();
+ $result = true;
+ while($id = $cursor->fetchColumn(0)) {
+ $preCallback($id);
+ if($isUnmapped = $this->unmap($id)) {
+ $postCallback($id);
+ }
+ $result &= $isUnmapped;
+ }
+ $cursor->closeCursor();
+ return $result;
+ }
+
+ /**
* returns the number of entries in the mappings table
*
* @return int
diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php
index 5a2b993c334..3868645caec 100644
--- a/apps/user_ldap/lib/User_LDAP.php
+++ b/apps/user_ldap/lib/User_LDAP.php
@@ -396,7 +396,7 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
\OC::$server->getLogger()->info('Cleaning up after user ' . $uid,
array('app' => 'user_ldap'));
- $this->access->getUserMapper()->unmap($uid);
+ $this->access->getUserMapper()->unmap($uid); // we don't emit revoke signals here, since it is implicit to delete signals fired from core
$this->access->userManager->invalidate($uid);
return true;
}
diff --git a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php b/apps/user_ldap/tests/Mapping/AbstractMappingTest.php
index d3d33a82da9..54d8b49cdc8 100644
--- a/apps/user_ldap/tests/Mapping/AbstractMappingTest.php
+++ b/apps/user_ldap/tests/Mapping/AbstractMappingTest.php
@@ -235,6 +235,29 @@ abstract class AbstractMappingTest extends \Test\TestCase {
}
/**
+ * tests clear() for successful update.
+ */
+ public function testClearCb() {
+ list($mapper, $data) = $this->initTest();
+
+ $callbackCalls = 0;
+ $test = $this;
+
+ $callback = function (string $id) use ($test, &$callbackCalls) {
+ $test->assertTrue(trim($id) !== '');
+ $callbackCalls++;
+ };
+
+ $done = $mapper->clearCb($callback, $callback);
+ $this->assertTrue($done);
+ $this->assertSame(count($data) * 2, $callbackCalls);
+ foreach($data as $entry) {
+ $name = $mapper->getNameByUUID($entry['uuid']);
+ $this->assertFalse($name);
+ }
+ }
+
+ /**
* tests getList() method
*/
public function testList() {