DI IConfig into ldap helper

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2016-10-10 10:18:18 +02:00
parent 1ba2b7e5d4
commit bdf4bf4669
No known key found for this signature in database
GPG Key ID: 1E152838F164D13B
26 changed files with 43 additions and 27 deletions

View File

@ -32,7 +32,7 @@ OCP\JSON::checkAppEnabled('user_ldap');
OCP\JSON::callCheck();
$prefix = (string)$_POST['ldap_serverconfig_chooser'];
$helper = new \OCA\User_LDAP\Helper();
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
if($helper->deleteServerConfiguration($prefix)) {
OCP\JSON::success();
} else {

View File

@ -27,7 +27,7 @@ OCP\JSON::checkAdminUser();
OCP\JSON::checkAppEnabled('user_ldap');
OCP\JSON::callCheck();
$helper = new \OCA\User_LDAP\Helper();
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
$serverConnections = $helper->getServerConfigurationPrefixes();
sort($serverConnections);
$lk = array_pop($serverConnections);

View File

@ -60,7 +60,9 @@ $userManager = new \OCA\User_LDAP\User\Manager(
\OC::$server->getDatabaseConnection(),
\OC::$server->getUserManager());
$access = new \OCA\User_LDAP\Access($con, $ldapWrapper, $userManager, new \OCA\User_LDAP\Helper());
$access = new \OCA\User_LDAP\Access($con, $ldapWrapper, $userManager, new \OCA\User_LDAP\Helper(
\OC::$server->getConfig()
));
$wizard = new \OCA\User_LDAP\Wizard($configuration, $ldapWrapper, $access);

View File

@ -27,7 +27,7 @@
*
*/
$helper = new \OCA\User_LDAP\Helper();
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
$ldapWrapper = new OCA\User_LDAP\LDAP();
$ocConfig = \OC::$server->getConfig();

View File

@ -26,5 +26,5 @@ if($state === 'doSet') {
OCP\Config::setSystemValue('ldapIgnoreNamingRules', false);
}
$helper = new \OCA\User_LDAP\Helper();
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
$helper->setLDAPProvider();

View File

@ -30,7 +30,7 @@ use OCA\User_LDAP\User\DeletedUsersIndex;
$dbConnection = \OC::$server->getDatabaseConnection();
$userMapping = new UserMapping($dbConnection);
$helper = new Helper();
$helper = new Helper(\OC::$server->getConfig());
$ocConfig = \OC::$server->getConfig();
$uBackend = new User_Proxy(
$helper->getServerConfigurationPrefixes(true),

View File

@ -20,5 +20,5 @@
*
*/
$helper = new \OCA\User_LDAP\Helper();
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
$helper->setLDAPProvider();

View File

@ -102,7 +102,7 @@ class Search extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output) {
$helper = new Helper();
$helper = new Helper($this->ocConfig);
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
$ldapWrapper = new LDAP();

View File

@ -57,7 +57,7 @@ class SetConfig extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output) {
$helper = new Helper();
$helper = new Helper(\OC::$server->getConfig());
$availableConfigs = $helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if(!in_array($configID, $availableConfigs)) {

View File

@ -47,7 +47,7 @@ class TestConfig extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output) {
$helper = new Helper();
$helper = new Helper(\OC::$server->getConfig());
$availableConfigs = $helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if(!in_array($configID, $availableConfigs)) {

View File

@ -87,7 +87,7 @@ class Connection extends LDAPUtility {
if($memcache->isAvailable()) {
$this->cache = $memcache->create();
}
$helper = new Helper();
$helper = new Helper(\OC::$server->getConfig());
$this->doNotValidate = !in_array($this->configPrefix,
$helper->getServerConfigurationPrefixes());
$this->hasPagedResultSupport =

View File

@ -30,8 +30,22 @@
namespace OCA\User_LDAP;
use OCP\IConfig;
class Helper {
/** @var IConfig */
private $config;
/**
* Helper constructor.
*
* @param IConfig $config
*/
public function __construct(IConfig $config) {
$this->config = $config;
}
/**
* returns prefixes for each saved LDAP/AD server configuration.
* @param bool $activeConfigurations optional, whether only active configuration shall be
@ -251,7 +265,7 @@ class Helper {
}
//ain't it ironic?
$helper = new Helper();
$helper = new Helper(\OC::$server->getConfig());
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
$ldapWrapper = new LDAP();

View File

@ -83,7 +83,7 @@ class CleanUp extends TimedJob {
if(isset($arguments['helper'])) {
$this->ldapHelper = $arguments['helper'];
} else {
$this->ldapHelper = new Helper();
$this->ldapHelper = new Helper(\OC::$server->getConfig());
}
if(isset($arguments['ocConfig'])) {

View File

@ -172,7 +172,7 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
if(!is_null(self::$groupBE)) {
return self::$groupBE;
}
$helper = new Helper();
$helper = new Helper(\OC::$server->getConfig());
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
$ldapWrapper = new LDAP();
if(count($configPrefixes) === 1) {

View File

@ -52,7 +52,7 @@ class LDAPProviderFactory implements ILDAPProviderFactory {
public function getLDAPProvider() {
$dbConnection = $this->serverContainer->getDatabaseConnection();
$userMapping = new UserMapping($dbConnection);
return new LDAPProvider($this->serverContainer, new Helper(),
return new LDAPProvider($this->serverContainer, new Helper($this->serverContainer->getConfig()),
new DeletedUsersIndex($this->serverContainer->getConfig(),
$dbConnection, $userMapping));
}

View File

@ -77,7 +77,7 @@ abstract class Proxy {
$userManager =
new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db, $coreUserManager);
$connector = new Connection($this->ldap, $configPrefix);
$access = new Access($connector, $this->ldap, $userManager, new Helper());
$access = new Access($connector, $this->ldap, $userManager, new Helper(\OC::$server->getConfig()));
$access->setUserMapper($userMap);
$access->setGroupMapper($groupMap);
self::$accesses[$configPrefix] = $access;

View File

@ -45,7 +45,7 @@ class Admin implements ISettings {
* @return TemplateResponse
*/
public function getForm() {
$helper = new Helper();
$helper = new Helper(\OC::$server->getConfig());
$prefixes = $helper->getServerConfigurationPrefixes();
$hosts = $helper->getServerConfigurationHosts();

View File

@ -724,7 +724,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();
$helper = new Helper(\OC::$server->getConfig());
$domain = $helper->getDomainFromURL($this->configuration->ldapHost);
if(!$domain) {
return false;

View File

@ -67,7 +67,7 @@ class AccessTest extends \Test\TestCase {
$this->createMock(Image::class),
$this->createMock(IDBConnection::class),
$this->createMock(IUserManager::class)));
$helper = new \OCA\User_LDAP\Helper();
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
return array($lw, $connector, $um, $helper);
}

View File

@ -54,7 +54,7 @@ class Group_LDAPTest extends \Test\TestCase {
$um = $this->getMockBuilder('\OCA\User_LDAP\User\Manager')
->disableOriginalConstructor()
->getMock();
$helper = new \OCA\User_LDAP\Helper();
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
$access = $this->getMock('\OCA\User_LDAP\Access',
$accMethods,
array($connector, $lw, $um, $helper));

View File

@ -113,7 +113,7 @@ abstract class AbstractIntegrationTest {
* initializes the test Helper
*/
protected function initHelper() {
$this->helper = new Helper();
$this->helper = new Helper(\OC::$server->getConfig());
}
/**

View File

@ -121,7 +121,7 @@ class LDAPProviderTest extends \Test\TestCase {
$server = $this->getServerMock($backend);
$helper = new \OCA\User_LDAP\Helper();
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
$ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals(
@ -137,7 +137,7 @@ class LDAPProviderTest extends \Test\TestCase {
$server = $this->getServerMock($backend);
$helper = new \OCA\User_LDAP\Helper();
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
$ldapProvider = $this->getLDAPProvider($server);
$this->assertEquals(

View File

@ -55,7 +55,7 @@ class AdminTest extends TestCase {
*/
public function testGetForm() {
$helper = new Helper();
$helper = new Helper(\OC::$server->getConfig());
$prefixes = $helper->getServerConfigurationPrefixes();
$hosts = $helper->getServerConfigurationHosts();

View File

@ -81,7 +81,7 @@ class UserTest extends \Test\TestCase {
$umMethods, array($cfMock, $fsMock, $logMock, $avaMgr, $im, $dbc, $userMgr));
$connector = $this->getMock('\OCA\User_LDAP\Connection',
$conMethods, array($lw, null, null));
$helper = new \OCA\User_LDAP\Helper();
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
$access = $this->getMock('\OCA\User_LDAP\Access',
$accMethods, array($connector, $lw, $um, $helper));

View File

@ -97,7 +97,7 @@ class User_LDAPTest extends TestCase {
->method('getDeletedUser')
->will($this->returnValue($offlineUser));
$helper = new Helper();
$helper = new Helper(\OC::$server->getConfig());
$access = $this->getMockBuilder(Access::class)
->setMethodsExcept(['getConnection'])

View File

@ -70,7 +70,7 @@ class WizardTest extends \Test\TestCase {
$um = $this->getMockBuilder('\OCA\User_LDAP\User\Manager')
->disableOriginalConstructor()
->getMock();
$helper = new \OCA\User_LDAP\Helper();
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
$access = $this->getMock('\OCA\User_LDAP\Access',
$accMethods, array($connector, $lw, $um, $helper));