aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-11-06 11:25:28 +0100
committerJoas Schilling <coding@schilljs.com>2020-11-06 11:25:28 +0100
commit5fba0e562f1e9e7e53b28ce5e2a31346c70a7810 (patch)
treeea1230042e41ddec42a77d094d63358d72fe1f33 /apps/user_ldap
parent2c6bbe783a6ab0f75f9ad85d66d9b4511a7543be (diff)
downloadnextcloud-server-5fba0e562f1e9e7e53b28ce5e2a31346c70a7810.tar.gz
nextcloud-server-5fba0e562f1e9e7e53b28ce5e2a31346c70a7810.zip
Use query builder instead of OC_DB in user_ldap
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/user_ldap')
-rw-r--r--apps/user_ldap/ajax/deleteConfiguration.php2
-rw-r--r--apps/user_ldap/ajax/getNewServerConfigPrefix.php2
-rw-r--r--apps/user_ldap/ajax/wizard.php2
-rw-r--r--apps/user_ldap/appinfo/install.php2
-rw-r--r--apps/user_ldap/appinfo/update.php2
-rw-r--r--apps/user_ldap/lib/Command/Search.php2
-rw-r--r--apps/user_ldap/lib/Command/SetConfig.php2
-rw-r--r--apps/user_ldap/lib/Command/TestConfig.php2
-rw-r--r--apps/user_ldap/lib/Connection.php2
-rw-r--r--apps/user_ldap/lib/Helper.php48
-rw-r--r--apps/user_ldap/lib/Jobs/CleanUp.php2
-rw-r--r--apps/user_ldap/lib/Jobs/Sync.php2
-rw-r--r--apps/user_ldap/lib/Proxy.php2
-rw-r--r--apps/user_ldap/lib/Settings/Admin.php2
-rw-r--r--apps/user_ldap/lib/Wizard.php2
-rw-r--r--apps/user_ldap/tests/AccessTest.php2
-rw-r--r--apps/user_ldap/tests/HelperTest.php2
-rw-r--r--apps/user_ldap/tests/Integration/AbstractIntegrationTest.php2
-rw-r--r--apps/user_ldap/tests/LDAPProviderTest.php4
19 files changed, 40 insertions, 46 deletions
diff --git a/apps/user_ldap/ajax/deleteConfiguration.php b/apps/user_ldap/ajax/deleteConfiguration.php
index f4f6eaf267d..61a3e8b673a 100644
--- a/apps/user_ldap/ajax/deleteConfiguration.php
+++ b/apps/user_ldap/ajax/deleteConfiguration.php
@@ -32,7 +32,7 @@
\OC_JSON::callCheck();
$prefix = (string)$_POST['ldap_serverconfig_chooser'];
-$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
+$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
if ($helper->deleteServerConfiguration($prefix)) {
\OC_JSON::success();
} else {
diff --git a/apps/user_ldap/ajax/getNewServerConfigPrefix.php b/apps/user_ldap/ajax/getNewServerConfigPrefix.php
index 4e95d6e02b5..ec38fbb8ff0 100644
--- a/apps/user_ldap/ajax/getNewServerConfigPrefix.php
+++ b/apps/user_ldap/ajax/getNewServerConfigPrefix.php
@@ -29,7 +29,7 @@
\OC_JSON::checkAppEnabled('user_ldap');
\OC_JSON::callCheck();
-$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
+$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
$serverConnections = $helper->getServerConfigurationPrefixes();
sort($serverConnections);
$lk = array_pop($serverConnections);
diff --git a/apps/user_ldap/ajax/wizard.php b/apps/user_ldap/ajax/wizard.php
index 9c7b26b54ac..360e121766d 100644
--- a/apps/user_ldap/ajax/wizard.php
+++ b/apps/user_ldap/ajax/wizard.php
@@ -70,7 +70,7 @@ $access = new \OCA\User_LDAP\Access(
$con,
$ldapWrapper,
$userManager,
- new \OCA\User_LDAP\Helper(\OC::$server->getConfig()),
+ new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
\OC::$server->getConfig(),
\OC::$server->getUserManager()
);
diff --git a/apps/user_ldap/appinfo/install.php b/apps/user_ldap/appinfo/install.php
index 7dec03ffab0..731630000de 100644
--- a/apps/user_ldap/appinfo/install.php
+++ b/apps/user_ldap/appinfo/install.php
@@ -29,5 +29,5 @@ if ($state === 'doSet') {
\OC::$server->getConfig()->setSystemValue('ldapIgnoreNamingRules', false);
}
-$helper = new \OCA\User_LDAP\Helper($config);
+$helper = new \OCA\User_LDAP\Helper($config, \OC::$server->getDatabaseConnection());
$helper->setLDAPProvider();
diff --git a/apps/user_ldap/appinfo/update.php b/apps/user_ldap/appinfo/update.php
index 035fecba1f8..8fed2988096 100644
--- a/apps/user_ldap/appinfo/update.php
+++ b/apps/user_ldap/appinfo/update.php
@@ -23,5 +23,5 @@
*
*/
-$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
+$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
$helper->setLDAPProvider();
diff --git a/apps/user_ldap/lib/Command/Search.php b/apps/user_ldap/lib/Command/Search.php
index 2ee83e0f22b..5d2e72483ba 100644
--- a/apps/user_ldap/lib/Command/Search.php
+++ b/apps/user_ldap/lib/Command/Search.php
@@ -109,7 +109,7 @@ class Search extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $helper = new Helper($this->ocConfig);
+ $helper = new Helper($this->ocConfig, \OC::$server->getDatabaseConnection());
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
$ldapWrapper = new LDAP();
diff --git a/apps/user_ldap/lib/Command/SetConfig.php b/apps/user_ldap/lib/Command/SetConfig.php
index 2b2fdfe5c8b..4b20ad65e9f 100644
--- a/apps/user_ldap/lib/Command/SetConfig.php
+++ b/apps/user_ldap/lib/Command/SetConfig.php
@@ -60,7 +60,7 @@ class SetConfig extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $helper = new Helper(\OC::$server->getConfig());
+ $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
$availableConfigs = $helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if (!in_array($configID, $availableConfigs)) {
diff --git a/apps/user_ldap/lib/Command/TestConfig.php b/apps/user_ldap/lib/Command/TestConfig.php
index b588a8380d0..e83befe6f30 100644
--- a/apps/user_ldap/lib/Command/TestConfig.php
+++ b/apps/user_ldap/lib/Command/TestConfig.php
@@ -48,7 +48,7 @@ class TestConfig extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $helper = new Helper(\OC::$server->getConfig());
+ $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
$availableConfigs = $helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if (!in_array($configID, $availableConfigs)) {
diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php
index 6af2fd700e4..9a99b94689f 100644
--- a/apps/user_ldap/lib/Connection.php
+++ b/apps/user_ldap/lib/Connection.php
@@ -120,7 +120,7 @@ class Connection extends LDAPUtility {
if ($memcache->isAvailable()) {
$this->cache = $memcache->createDistributed();
}
- $helper = new Helper(\OC::$server->getConfig());
+ $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
$this->doNotValidate = !in_array($this->configPrefix,
$helper->getServerConfigurationPrefixes());
}
diff --git a/apps/user_ldap/lib/Helper.php b/apps/user_ldap/lib/Helper.php
index 86712534f40..2cd8b528d0b 100644
--- a/apps/user_ldap/lib/Helper.php
+++ b/apps/user_ldap/lib/Helper.php
@@ -35,23 +35,25 @@
namespace OCA\User_LDAP;
use OC\Cache\CappedMemoryCache;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
+use OCP\IDBConnection;
class Helper {
/** @var IConfig */
private $config;
+ /** @var IDBConnection */
+ private $connection;
+
/** @var CappedMemoryCache */
protected $sanitizeDnCache;
- /**
- * Helper constructor.
- *
- * @param IConfig $config
- */
- public function __construct(IConfig $config) {
+ public function __construct(IConfig $config,
+ IDBConnection $connection) {
$this->config = $config;
+ $this->connection = $connection;
$this->sanitizeDnCache = new CappedMemoryCache(10000);
}
@@ -160,30 +162,22 @@ class Helper {
return false;
}
- $saveOtherConfigurations = '';
- if (empty($prefix)) {
- $saveOtherConfigurations = 'AND `configkey` NOT LIKE \'s%\'';
- }
+ $query = $this->connection->getQueryBuilder();
+ $query->delete('appconfig')
+ ->where($query->expr()->eq('appid', $query->createNamedParameter('user_ldap')))
+ ->andWhere($query->expr()->notIn('configkey', $query->createNamedParameter([
+ 'enabled',
+ 'installed_version',
+ 'types',
+ 'bgjUpdateGroupsLastRun',
+ ]), IQueryBuilder::PARAM_STR_ARRAY));
- $query = \OC_DB::prepare('
- DELETE
- FROM `*PREFIX*appconfig`
- WHERE `configkey` LIKE ?
- ' . $saveOtherConfigurations . '
- AND `appid` = \'user_ldap\'
- AND `configkey` NOT IN (\'enabled\', \'installed_version\', \'types\', \'bgjUpdateGroupsLastRun\')
- ');
- $delRows = $query->execute([$prefix . '%']);
-
- if ($delRows === null) {
- return false;
- }
-
- if ($delRows === 0) {
- return false;
+ if (empty($prefix)) {
+ $query->andWhere($query->expr()->notLike('configkey', $query->createNamedParameter('s%')));
}
- return true;
+ $deletedRows = $query->execute();
+ return $deletedRows !== 0;
}
/**
diff --git a/apps/user_ldap/lib/Jobs/CleanUp.php b/apps/user_ldap/lib/Jobs/CleanUp.php
index 8470c4793bb..3c4f483d677 100644
--- a/apps/user_ldap/lib/Jobs/CleanUp.php
+++ b/apps/user_ldap/lib/Jobs/CleanUp.php
@@ -88,7 +88,7 @@ class CleanUp extends TimedJob {
if (isset($arguments['helper'])) {
$this->ldapHelper = $arguments['helper'];
} else {
- $this->ldapHelper = new Helper(\OC::$server->getConfig());
+ $this->ldapHelper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
}
if (isset($arguments['ocConfig'])) {
diff --git a/apps/user_ldap/lib/Jobs/Sync.php b/apps/user_ldap/lib/Jobs/Sync.php
index 483c21386eb..5c70c0c23b7 100644
--- a/apps/user_ldap/lib/Jobs/Sync.php
+++ b/apps/user_ldap/lib/Jobs/Sync.php
@@ -308,7 +308,7 @@ class Sync extends TimedJob {
if (isset($argument['helper'])) {
$this->ldapHelper = $argument['helper'];
} else {
- $this->ldapHelper = new Helper($this->config);
+ $this->ldapHelper = new Helper($this->config, \OC::$server->getDatabaseConnection());
}
if (isset($argument['ldapWrapper'])) {
diff --git a/apps/user_ldap/lib/Proxy.php b/apps/user_ldap/lib/Proxy.php
index 46cb2e6b9a0..e723c4e3abf 100644
--- a/apps/user_ldap/lib/Proxy.php
+++ b/apps/user_ldap/lib/Proxy.php
@@ -87,7 +87,7 @@ abstract class Proxy {
new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(),
$coreUserManager, $coreNotificationManager, $shareManager);
$connector = new Connection($this->ldap, $configPrefix);
- $access = new Access($connector, $this->ldap, $userManager, new Helper($ocConfig), $ocConfig, $coreUserManager);
+ $access = new Access($connector, $this->ldap, $userManager, new Helper($ocConfig, \OC::$server->getDatabaseConnection()), $ocConfig, $coreUserManager);
$access->setUserMapper($userMap);
$access->setGroupMapper($groupMap);
self::$accesses[$configPrefix] = $access;
diff --git a/apps/user_ldap/lib/Settings/Admin.php b/apps/user_ldap/lib/Settings/Admin.php
index bea4813a23f..bf10a661edb 100644
--- a/apps/user_ldap/lib/Settings/Admin.php
+++ b/apps/user_ldap/lib/Settings/Admin.php
@@ -48,7 +48,7 @@ class Admin implements ISettings {
* @return TemplateResponse
*/
public function getForm() {
- $helper = new Helper(\OC::$server->getConfig());
+ $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
$prefixes = $helper->getServerConfigurationPrefixes();
if (count($prefixes) === 0) {
$newPrefix = $helper->getNextServerConfigurationPrefix();
diff --git a/apps/user_ldap/lib/Wizard.php b/apps/user_ldap/lib/Wizard.php
index 0d614f5b1fb..eb0b775345b 100644
--- a/apps/user_ldap/lib/Wizard.php
+++ b/apps/user_ldap/lib/Wizard.php
@@ -739,7 +739,7 @@ class Wizard extends LDAPUtility {
//this did not help :(
//Let's see whether we can parse the Host URL and convert the domain to
//a base DN
- $helper = new Helper(\OC::$server->getConfig());
+ $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
$domain = $helper->getDomainFromURL($this->configuration->ldapHost);
if (!$domain) {
return false;
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php
index 4f89fc51568..b9055d32824 100644
--- a/apps/user_ldap/tests/AccessTest.php
+++ b/apps/user_ldap/tests/AccessTest.php
@@ -118,7 +118,7 @@ class AccessTest extends TestCase {
$this->createMock(INotificationManager::class),
$this->shareManager])
->getMock();
- $helper = new Helper(\OC::$server->getConfig());
+ $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
return [$lw, $connector, $um, $helper];
}
diff --git a/apps/user_ldap/tests/HelperTest.php b/apps/user_ldap/tests/HelperTest.php
index 1822c27a1cd..866416ac186 100644
--- a/apps/user_ldap/tests/HelperTest.php
+++ b/apps/user_ldap/tests/HelperTest.php
@@ -40,7 +40,7 @@ class HelperTest extends \Test\TestCase {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
- $this->helper = new Helper($this->config);
+ $this->helper = new Helper($this->config, \OC::$server->getDatabaseConnection());
}
public function testGetServerConfigurationPrefixes() {
diff --git a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
index 095c61544b0..d0f2e8d4a95 100644
--- a/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
+++ b/apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
@@ -137,7 +137,7 @@ abstract class AbstractIntegrationTest {
* initializes the test Helper
*/
protected function initHelper() {
- $this->helper = new Helper(\OC::$server->getConfig());
+ $this->helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
}
/**
diff --git a/apps/user_ldap/tests/LDAPProviderTest.php b/apps/user_ldap/tests/LDAPProviderTest.php
index 3e9d0515892..eec5f732738 100644
--- a/apps/user_ldap/tests/LDAPProviderTest.php
+++ b/apps/user_ldap/tests/LDAPProviderTest.php
@@ -224,7 +224,7 @@ class LDAPProviderTest extends \Test\TestCase {
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
- $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
+ $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
$ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals(
@@ -240,7 +240,7 @@ class LDAPProviderTest extends \Test\TestCase {
$server = $this->getServerMock($userBackend, $this->getDefaultGroupBackendMock());
- $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
+ $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
$ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals(