Skip to content

Commit add22f2

Browse files
committed
LDAP simplify User_Proxy and Group_Proxy signatures
- make User_Proxy and Group_Proxy easy to instantiate - simplify dependent code - move commands to info.xml - make UpdateGroups job class non-static Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent 872f032 commit add22f2

18 files changed

Lines changed: 127 additions & 303 deletions

apps/user_ldap/appinfo/info.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ A user logs into Nextcloud with their LDAP or AD credentials, and is granted acc
4040
</post-migration>
4141
</repair-steps>
4242

43+
<commands>
44+
<command>OCA\User_LDAP\Command\CheckUser</command>
45+
<command>OCA\User_LDAP\Command\CreateEmptyConfig</command>
46+
<command>OCA\User_LDAP\Command\DeleteConfig</command>
47+
<command>OCA\User_LDAP\Command\Search</command>
48+
<command>OCA\User_LDAP\Command\SetConfig</command>
49+
<command>OCA\User_LDAP\Command\ShowConfig</command>
50+
<command>OCA\User_LDAP\Command\ShowRemnants</command>
51+
<command>OCA\User_LDAP\Command\TestConfig</command>
52+
</commands>
53+
4354
<settings>
4455
<admin>OCA\User_LDAP\Settings\Admin</admin>
4556
<admin-section>OCA\User_LDAP\Settings\Section</admin-section>

apps/user_ldap/appinfo/register_command.php

Lines changed: 0 additions & 61 deletions
This file was deleted.

apps/user_ldap/lib/AppInfo/Application.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@
4646
use OCP\AppFramework\Bootstrap\IRegistrationContext;
4747
use OCP\AppFramework\IAppContainer;
4848
use OCP\EventDispatcher\IEventDispatcher;
49-
use OCP\IConfig;
5049
use OCP\IGroupManager;
5150
use OCP\IL10N;
5251
use OCP\IServerContainer;
53-
use OCP\IUserSession;
5452
use OCP\Notification\IManager as INotificationManager;
5553
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
5654

@@ -86,28 +84,23 @@ public function register(IRegistrationContext $context): void {
8684
}
8785

8886
public function boot(IBootContext $context): void {
89-
$context->injectFn(function (IConfig $config,
90-
INotificationManager $notificationManager,
91-
IUserSession $userSession,
92-
IAppContainer $appContainer,
93-
EventDispatcherInterface $legacyDispatcher,
94-
IEventDispatcher $dispatcher,
95-
IGroupManager $groupManager) {
96-
$helper = new Helper($config);
87+
$context->injectFn(function (
88+
INotificationManager $notificationManager,
89+
IAppContainer $appContainer,
90+
EventDispatcherInterface $legacyDispatcher,
91+
IEventDispatcher $dispatcher,
92+
IGroupManager $groupManager,
93+
User_Proxy $userBackend,
94+
Group_Proxy $groupBackend,
95+
Helper $helper
96+
) {
9797
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
9898
if (count($configPrefixes) > 0) {
99-
$ldapWrapper = new LDAP();
100-
10199
$notificationManager->registerNotifierService(Notifier::class);
102100

103101
$userPluginManager = $appContainer->get(UserPluginManager::class);
104102
$groupPluginManager = $appContainer->get(GroupPluginManager::class);
105103

106-
$userBackend = new User_Proxy(
107-
$configPrefixes, $ldapWrapper, $config, $notificationManager, $userSession, $userPluginManager
108-
);
109-
$groupBackend = new Group_Proxy($configPrefixes, $ldapWrapper, $groupPluginManager);
110-
111104
\OC_User::useBackend($userBackend);
112105
$groupManager->addBackend($groupBackend);
113106

apps/user_ldap/lib/Command/Search.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@
2929
namespace OCA\User_LDAP\Command;
3030

3131
use OCA\User_LDAP\Group_Proxy;
32-
use OCA\User_LDAP\GroupPluginManager;
3332
use OCA\User_LDAP\Helper;
3433
use OCA\User_LDAP\LDAP;
3534
use OCA\User_LDAP\User_Proxy;
36-
use OCA\User_LDAP\UserPluginManager;
3735
use OCP\IConfig;
3836

3937
use Symfony\Component\Console\Command\Command;
@@ -45,13 +43,16 @@
4543
class Search extends Command {
4644
/** @var \OCP\IConfig */
4745
protected $ocConfig;
46+
/** @var User_Proxy */
47+
private $userProxy;
48+
/** @var Group_Proxy */
49+
private $groupProxy;
4850

49-
/**
50-
* @param \OCP\IConfig $ocConfig
51-
*/
52-
public function __construct(IConfig $ocConfig) {
53-
$this->ocConfig = $ocConfig;
51+
public function __construct(IConfig $ocConfig, User_Proxy $userProxy, Group_Proxy $groupProxy) {
5452
parent::__construct();
53+
$this->ocConfig = $ocConfig;
54+
$this->userProxy = $userProxy;
55+
$this->groupProxy = $groupProxy;
5556
}
5657

5758
protected function configure() {
@@ -117,7 +118,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
117118
$this->validateOffsetAndLimit($offset, $limit);
118119

119120
if ($input->getOption('group')) {
120-
$proxy = new Group_Proxy($configPrefixes, $ldapWrapper, \OC::$server->query(GroupPluginManager::class));
121+
$proxy = $this->groupProxy;
121122
$getMethod = 'getGroups';
122123
$printID = false;
123124
// convert the limit of groups to null. This will show all the groups available instead of
@@ -126,14 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
126127
$limit = null;
127128
}
128129
} else {
129-
$proxy = new User_Proxy(
130-
$configPrefixes,
131-
$ldapWrapper,
132-
$this->ocConfig,
133-
\OC::$server->getNotificationManager(),
134-
\OC::$server->getUserSession(),
135-
\OC::$server->query(UserPluginManager::class)
136-
);
130+
$proxy = $this->userProxy;
137131
$getMethod = 'getDisplayNames';
138132
$printID = true;
139133
}

apps/user_ldap/lib/Group_Proxy.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,9 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGet
3434
private $backends = [];
3535
private $refBackend = null;
3636

37-
/**
38-
* Constructor
39-
*
40-
* @param string[] $serverConfigPrefixes array containing the config Prefixes
41-
*/
42-
public function __construct($serverConfigPrefixes, ILDAPWrapper $ldap, GroupPluginManager $groupPluginManager) {
37+
public function __construct(Helper $helper, ILDAPWrapper $ldap, GroupPluginManager $groupPluginManager) {
4338
parent::__construct($ldap);
39+
$serverConfigPrefixes = $helper->getServerConfigurationPrefixes(true);
4440
foreach ($serverConfigPrefixes as $configPrefix) {
4541
$this->backends[$configPrefix] =
4642
new \OCA\User_LDAP\Group_LDAP($this->getAccess($configPrefix), $groupPluginManager);

apps/user_ldap/lib/Helper.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function __construct(IConfig $config) {
7676
* except the default (first) server shall be connected to.
7777
*
7878
*/
79-
public function getServerConfigurationPrefixes($activeConfigurations = false) {
79+
public function getServerConfigurationPrefixes($activeConfigurations = false): array {
8080
$referenceConfigkey = 'ldap_configuration_active';
8181

8282
$keys = $this->getServersConfig($referenceConfigkey);
@@ -192,7 +192,7 @@ public function deleteServerConfiguration($prefix) {
192192
* @return bool
193193
* @throws \Exception
194194
*/
195-
public function haveDisabledConfigurations() {
195+
public function haveDisabledConfigurations(): bool {
196196
$all = $this->getServerConfigurationPrefixes(false);
197197
$active = $this->getServerConfigurationPrefixes(true);
198198

@@ -312,20 +312,7 @@ public static function loginName2UserName($param) {
312312
throw new \Exception('key uid is expected to be set in $param');
313313
}
314314

315-
//ain't it ironic?
316-
$helper = new Helper(\OC::$server->getConfig());
317-
318-
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
319-
$ldapWrapper = new LDAP();
320-
$ocConfig = \OC::$server->getConfig();
321-
$notificationManager = \OC::$server->getNotificationManager();
322-
323-
$userSession = \OC::$server->getUserSession();
324-
$userPluginManager = \OC::$server->query(UserPluginManager::class);
325-
326-
$userBackend = new User_Proxy(
327-
$configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession, $userPluginManager
328-
);
315+
$userBackend = \OC::$server->get(User_Proxy::class);
329316
$uid = $userBackend->loginName2UserName($param['uid']);
330317
if ($uid !== false) {
331318
$param['uid'] = $uid;

apps/user_ldap/lib/Jobs/CleanUp.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
use OCA\User_LDAP\User\DeletedUsersIndex;
3636
use OCA\User_LDAP\User_LDAP;
3737
use OCA\User_LDAP\User_Proxy;
38-
use OCA\User_LDAP\UserPluginManager;
3938

4039
/**
4140
* Class CleanUp
@@ -69,10 +68,11 @@ class CleanUp extends TimedJob {
6968
/** @var DeletedUsersIndex */
7069
protected $dui;
7170

72-
public function __construct() {
71+
public function __construct(User_Proxy $userBackend) {
7372
$minutes = \OC::$server->getConfig()->getSystemValue(
7473
'ldapUserCleanupInterval', (string)$this->defaultIntervalMin);
7574
$this->setInterval((int)$minutes * 60);
75+
$this->userBackend = $userBackend;
7676
}
7777

7878
/**
@@ -99,15 +99,6 @@ public function setArguments($arguments) {
9999

100100
if (isset($arguments['userBackend'])) {
101101
$this->userBackend = $arguments['userBackend'];
102-
} else {
103-
$this->userBackend = new User_Proxy(
104-
$this->ldapHelper->getServerConfigurationPrefixes(true),
105-
new LDAP(),
106-
$this->ocConfig,
107-
\OC::$server->getNotificationManager(),
108-
\OC::$server->getUserSession(),
109-
\OC::$server->query(UserPluginManager::class)
110-
);
111102
}
112103

113104
if (isset($arguments['db'])) {

0 commit comments

Comments
 (0)