aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib/Command
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/lib/Command')
-rw-r--r--apps/user_ldap/lib/Command/CheckGroup.php47
-rw-r--r--apps/user_ldap/lib/Command/CheckUser.php69
-rw-r--r--apps/user_ldap/lib/Command/CreateEmptyConfig.php40
-rw-r--r--apps/user_ldap/lib/Command/DeleteConfig.php49
-rw-r--r--apps/user_ldap/lib/Command/PromoteGroup.php23
-rw-r--r--apps/user_ldap/lib/Command/ResetGroup.php42
-rw-r--r--apps/user_ldap/lib/Command/ResetUser.php46
-rw-r--r--apps/user_ldap/lib/Command/Search.php57
-rw-r--r--apps/user_ldap/lib/Command/SetConfig.php42
-rw-r--r--apps/user_ldap/lib/Command/ShowConfig.php74
-rw-r--r--apps/user_ldap/lib/Command/ShowRemnants.php50
-rw-r--r--apps/user_ldap/lib/Command/TestConfig.php74
-rw-r--r--apps/user_ldap/lib/Command/TestUserSettings.php248
-rw-r--r--apps/user_ldap/lib/Command/UpdateUUID.php107
14 files changed, 450 insertions, 518 deletions
diff --git a/apps/user_ldap/lib/Command/CheckGroup.php b/apps/user_ldap/lib/Command/CheckGroup.php
index 68f96512a9b..9c7ccb9d3b3 100644
--- a/apps/user_ldap/lib/Command/CheckGroup.php
+++ b/apps/user_ldap/lib/Command/CheckGroup.php
@@ -3,29 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Côme Chilliet <come.chilliet@nextcloud.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\User_LDAP\Command;
@@ -106,37 +85,39 @@ class CheckGroup extends Command {
$this->service->handleCreatedGroups([$gid]);
}
}
- return 0;
- } elseif ($wasMapped) {
+ return self::SUCCESS;
+ }
+
+ if ($wasMapped) {
$output->writeln('The group does not exist on LDAP anymore.');
if ($input->getOption('update')) {
$this->backend->getLDAPAccess($gid)->connection->clearCache();
$this->service->handleRemovedGroups([$gid]);
}
- return 0;
- } else {
- throw new \Exception('The given group is not a recognized LDAP group.');
+ return self::SUCCESS;
}
+
+ throw new \Exception('The given group is not a recognized LDAP group.');
} catch (\Exception $e) {
- $output->writeln('<error>' . $e->getMessage(). '</error>');
- return 1;
+ $output->writeln('<error>' . $e->getMessage() . '</error>');
+ return self::FAILURE;
}
}
public function onGroupCreatedEvent(GroupCreatedEvent $event, OutputInterface $output): void {
- $output->writeln('<info>The group '.$event->getGroup()->getGID().' was added to Nextcloud with '.$event->getGroup()->count().' users</info>');
+ $output->writeln('<info>The group ' . $event->getGroup()->getGID() . ' was added to Nextcloud with ' . $event->getGroup()->count() . ' users</info>');
}
public function onUserAddedEvent(UserAddedEvent $event, OutputInterface $output): void {
$user = $event->getUser();
$group = $event->getGroup();
- $output->writeln('<info>The user '.$user->getUID().' was added to group '.$group->getGID().'</info>');
+ $output->writeln('<info>The user ' . $user->getUID() . ' was added to group ' . $group->getGID() . '</info>');
}
public function onUserRemovedEvent(UserRemovedEvent $event, OutputInterface $output): void {
$user = $event->getUser();
$group = $event->getGroup();
- $output->writeln('<info>The user '.$user->getUID().' was removed from group '.$group->getGID().'</info>');
+ $output->writeln('<info>The user ' . $user->getUID() . ' was removed from group ' . $group->getGID() . '</info>');
}
/**
diff --git a/apps/user_ldap/lib/Command/CheckUser.php b/apps/user_ldap/lib/Command/CheckUser.php
index 1174408cb49..8bb26ce3d0e 100644
--- a/apps/user_ldap/lib/Command/CheckUser.php
+++ b/apps/user_ldap/lib/Command/CheckUser.php
@@ -1,28 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Côme Chilliet <come.chilliet@nextcloud.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP\Command;
@@ -37,23 +18,12 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class CheckUser extends Command {
- /** @var User_Proxy */
- protected $backend;
-
- /** @var Helper */
- protected $helper;
-
- /** @var DeletedUsersIndex */
- protected $dui;
-
- /** @var UserMapping */
- protected $mapping;
-
- public function __construct(User_Proxy $uBackend, Helper $helper, DeletedUsersIndex $dui, UserMapping $mapping) {
- $this->backend = $uBackend;
- $this->helper = $helper;
- $this->dui = $dui;
- $this->mapping = $mapping;
+ public function __construct(
+ protected User_Proxy $backend,
+ protected Helper $helper,
+ protected DeletedUsersIndex $dui,
+ protected UserMapping $mapping,
+ ) {
parent::__construct();
}
@@ -98,19 +68,21 @@ class CheckUser extends Command {
if ($input->getOption('update')) {
$this->updateUser($uid, $output);
}
- return 0;
- } elseif ($wasMapped) {
+ return self::SUCCESS;
+ }
+
+ if ($wasMapped) {
$this->dui->markUser($uid);
$output->writeln('The user does not exists on LDAP anymore.');
$output->writeln('Clean up the user\'s remnants by: ./occ user:delete "'
. $uid . '"');
- return 0;
- } else {
- throw new \Exception('The given user is not a recognized LDAP user.');
+ return self::SUCCESS;
}
+
+ throw new \Exception('The given user is not a recognized LDAP user.');
} catch (\Exception $e) {
- $output->writeln('<error>' . $e->getMessage(). '</error>');
- return 1;
+ $output->writeln('<error>' . $e->getMessage() . '</error>');
+ return self::FAILURE;
}
}
@@ -144,7 +116,8 @@ class CheckUser extends Command {
$attrs = $access->userManager->getAttributes();
$user = $access->userManager->get($uid);
$avatarAttributes = $access->getConnection()->resolveRule('avatar');
- $result = $access->search('objectclass=*', $user->getDN(), $attrs, 1, 0);
+ $baseDn = $this->helper->DNasBaseParameter($user->getDN());
+ $result = $access->search('objectclass=*', $baseDn, $attrs, 1, 0);
foreach ($result[0] as $attribute => $valueSet) {
$output->writeln(' ' . $attribute . ': ');
foreach ($valueSet as $value) {
diff --git a/apps/user_ldap/lib/Command/CreateEmptyConfig.php b/apps/user_ldap/lib/Command/CreateEmptyConfig.php
index f7f04e28e60..7c381cf431f 100644
--- a/apps/user_ldap/lib/Command/CreateEmptyConfig.php
+++ b/apps/user_ldap/lib/Command/CreateEmptyConfig.php
@@ -1,26 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Martin Konrad <konrad@frib.msu.edu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP\Command;
@@ -32,18 +15,13 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class CreateEmptyConfig extends Command {
- /** @var \OCA\User_LDAP\Helper */
- protected $helper;
-
- /**
- * @param Helper $helper
- */
- public function __construct(Helper $helper) {
- $this->helper = $helper;
+ public function __construct(
+ protected Helper $helper,
+ ) {
parent::__construct();
}
- protected function configure() {
+ protected function configure(): void {
$this
->setName('ldap:create-empty-config')
->setDescription('creates an empty LDAP configuration')
@@ -67,6 +45,6 @@ class CreateEmptyConfig extends Command {
$prose = 'Created new configuration with configID ';
}
$output->writeln($prose . "{$configPrefix}");
- return 0;
+ return self::SUCCESS;
}
}
diff --git a/apps/user_ldap/lib/Command/DeleteConfig.php b/apps/user_ldap/lib/Command/DeleteConfig.php
index 8da77c29671..7604e229bed 100644
--- a/apps/user_ldap/lib/Command/DeleteConfig.php
+++ b/apps/user_ldap/lib/Command/DeleteConfig.php
@@ -1,26 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Martin Konrad <info@martin-konrad.net>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP\Command;
@@ -31,18 +14,13 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class DeleteConfig extends Command {
- /** @var \OCA\User_LDAP\Helper */
- protected $helper;
-
- /**
- * @param Helper $helper
- */
- public function __construct(Helper $helper) {
- $this->helper = $helper;
+ public function __construct(
+ protected Helper $helper,
+ ) {
parent::__construct();
}
- protected function configure() {
+ protected function configure(): void {
$this
->setName('ldap:delete-config')
->setDescription('deletes an existing LDAP configuration')
@@ -54,18 +32,17 @@ class DeleteConfig extends Command {
;
}
-
protected function execute(InputInterface $input, OutputInterface $output): int {
$configPrefix = $input->getArgument('configID');
$success = $this->helper->deleteServerConfiguration($configPrefix);
- if ($success) {
- $output->writeln("Deleted configuration with configID '{$configPrefix}'");
- return 0;
- } else {
+ if (!$success) {
$output->writeln("Cannot delete configuration with configID '{$configPrefix}'");
- return 1;
+ return self::FAILURE;
}
+
+ $output->writeln("Deleted configuration with configID '{$configPrefix}'");
+ return self::SUCCESS;
}
}
diff --git a/apps/user_ldap/lib/Command/PromoteGroup.php b/apps/user_ldap/lib/Command/PromoteGroup.php
index 7ec18064332..b203a910b14 100644
--- a/apps/user_ldap/lib/Command/PromoteGroup.php
+++ b/apps/user_ldap/lib/Command/PromoteGroup.php
@@ -2,25 +2,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2023 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\User_LDAP\Command;
@@ -39,7 +22,7 @@ class PromoteGroup extends Command {
public function __construct(
private IGroupManager $groupManager,
- private Group_Proxy $backend
+ private Group_Proxy $backend,
) {
parent::__construct();
}
diff --git a/apps/user_ldap/lib/Command/ResetGroup.php b/apps/user_ldap/lib/Command/ResetGroup.php
index f3c3019f919..5833ca980f2 100644
--- a/apps/user_ldap/lib/Command/ResetGroup.php
+++ b/apps/user_ldap/lib/Command/ResetGroup.php
@@ -1,25 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2021 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Côme Chilliet <come.chilliet@nextcloud.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\User_LDAP\Command;
@@ -36,18 +19,11 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
class ResetGroup extends Command {
- private IGroupManager $groupManager;
- private GroupPluginManager $pluginManager;
- private Group_Proxy $backend;
-
public function __construct(
- IGroupManager $groupManager,
- GroupPluginManager $pluginManager,
- Group_Proxy $backend
+ private IGroupManager $groupManager,
+ private GroupPluginManager $pluginManager,
+ private Group_Proxy $backend,
) {
- $this->groupManager = $groupManager;
- $this->pluginManager = $pluginManager;
- $this->backend = $backend;
parent::__construct();
}
@@ -96,16 +72,16 @@ class ResetGroup extends Command {
echo "calling delete $gid\n";
if ($group->delete()) {
$this->pluginManager->setSuppressDeletion($pluginManagerSuppressed);
- return 0;
+ return self::SUCCESS;
}
} catch (\Throwable $e) {
if (isset($pluginManagerSuppressed)) {
$this->pluginManager->setSuppressDeletion($pluginManagerSuppressed);
}
$output->writeln('<error>' . $e->getMessage() . '</error>');
- return 1;
+ return self::FAILURE;
}
$output->writeln('<error>Error while resetting group</error>');
- return 2;
+ return self::INVALID;
}
}
diff --git a/apps/user_ldap/lib/Command/ResetUser.php b/apps/user_ldap/lib/Command/ResetUser.php
index 854481fc0d1..1409806e4ac 100644
--- a/apps/user_ldap/lib/Command/ResetUser.php
+++ b/apps/user_ldap/lib/Command/ResetUser.php
@@ -1,24 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2021 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\User_LDAP\Command;
@@ -36,25 +20,15 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
class ResetUser extends Command {
- /** @var DeletedUsersIndex */
- protected $dui;
- /** @var IUserManager */
- private $userManager;
- /** @var UserPluginManager */
- private $pluginManager;
-
public function __construct(
- DeletedUsersIndex $dui,
- IUserManager $userManager,
- UserPluginManager $pluginManager
+ protected DeletedUsersIndex $dui,
+ private IUserManager $userManager,
+ private UserPluginManager $pluginManager,
) {
- $this->dui = $dui;
- $this->userManager = $userManager;
- $this->pluginManager = $pluginManager;
parent::__construct();
}
- protected function configure() {
+ protected function configure(): void {
$this
->setName('ldap:reset-user')
->setDescription('deletes an LDAP user independent of the user state')
@@ -96,16 +70,16 @@ class ResetUser extends Command {
$pluginManagerSuppressed = $this->pluginManager->setSuppressDeletion(true);
if ($user->delete()) {
$this->pluginManager->setSuppressDeletion($pluginManagerSuppressed);
- return 0;
+ return self::SUCCESS;
}
} catch (\Throwable $e) {
if (isset($pluginManagerSuppressed)) {
$this->pluginManager->setSuppressDeletion($pluginManagerSuppressed);
}
$output->writeln('<error>' . $e->getMessage() . '</error>');
- return 1;
+ return self::FAILURE;
}
$output->writeln('<error>Error while resetting user</error>');
- return 2;
+ return self::INVALID;
}
}
diff --git a/apps/user_ldap/lib/Command/Search.php b/apps/user_ldap/lib/Command/Search.php
index 748bf873e64..85906b20e9a 100644
--- a/apps/user_ldap/lib/Command/Search.php
+++ b/apps/user_ldap/lib/Command/Search.php
@@ -1,28 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP\Command;
@@ -31,6 +12,7 @@ use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\User_Proxy;
use OCP\IConfig;
+use OCP\Server;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
@@ -39,21 +21,15 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Search extends Command {
- /** @var \OCP\IConfig */
- protected $ocConfig;
- /** @var User_Proxy */
- private $userProxy;
- /** @var Group_Proxy */
- private $groupProxy;
-
- public function __construct(IConfig $ocConfig, User_Proxy $userProxy, Group_Proxy $groupProxy) {
+ public function __construct(
+ protected IConfig $ocConfig,
+ private User_Proxy $userProxy,
+ private Group_Proxy $groupProxy,
+ ) {
parent::__construct();
- $this->ocConfig = $ocConfig;
- $this->userProxy = $userProxy;
- $this->groupProxy = $groupProxy;
}
- protected function configure() {
+ protected function configure(): void {
$this
->setName('ldap:search')
->setDescription('executes a user or group search')
@@ -87,11 +63,10 @@ class Search extends Command {
/**
* Tests whether the offset and limit options are valid
- * @param int $offset
- * @param int $limit
+ *
* @throws \InvalidArgumentException
*/
- protected function validateOffsetAndLimit($offset, $limit) {
+ protected function validateOffsetAndLimit(int $offset, int $limit): void {
if ($limit < 0) {
throw new \InvalidArgumentException('limit must be 0 or greater');
}
@@ -107,7 +82,7 @@ class Search extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $helper = new Helper($this->ocConfig, \OC::$server->getDatabaseConnection());
+ $helper = Server::get(Helper::class);
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
$ldapWrapper = new LDAP();
@@ -132,9 +107,9 @@ class Search extends Command {
$result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset);
foreach ($result as $id => $name) {
- $line = $name . ($printID ? ' ('.$id.')' : '');
+ $line = $name . ($printID ? ' (' . $id . ')' : '');
$output->writeln($line);
}
- return 0;
+ return self::SUCCESS;
}
}
diff --git a/apps/user_ldap/lib/Command/SetConfig.php b/apps/user_ldap/lib/Command/SetConfig.php
index 8cf100ecd0a..7e9efcf34d0 100644
--- a/apps/user_ldap/lib/Command/SetConfig.php
+++ b/apps/user_ldap/lib/Command/SetConfig.php
@@ -1,27 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP\Command;
@@ -29,13 +11,14 @@ use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\ConnectionFactory;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
+use OCP\Server;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SetConfig extends Command {
- protected function configure() {
+ protected function configure(): void {
$this
->setName('ldap:set-config')
->setDescription('modifies an LDAP configuration')
@@ -58,12 +41,12 @@ class SetConfig extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $helper = new Helper(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection());
+ $helper = Server::get(Helper::class);
$availableConfigs = $helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if (!in_array($configID, $availableConfigs)) {
- $output->writeln("Invalid configID");
- return 1;
+ $output->writeln('Invalid configID');
+ return self::FAILURE;
}
$this->setValue(
@@ -71,16 +54,13 @@ class SetConfig extends Command {
$input->getArgument('configKey'),
$input->getArgument('configValue')
);
- return 0;
+ return self::SUCCESS;
}
/**
* save the configuration value as provided
- * @param string $configID
- * @param string $configKey
- * @param string $configValue
*/
- protected function setValue($configID, $key, $value) {
+ protected function setValue(string $configID, string $key, string $value): void {
$configHolder = new Configuration($configID);
$configHolder->$key = $value;
$configHolder->saveConfiguration();
diff --git a/apps/user_ldap/lib/Command/ShowConfig.php b/apps/user_ldap/lib/Command/ShowConfig.php
index 6ff30739217..fa021192ac4 100644
--- a/apps/user_ldap/lib/Command/ShowConfig.php
+++ b/apps/user_ldap/lib/Command/ShowConfig.php
@@ -1,28 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Johannes Leuker <j.leuker@hosting.de>
- * @author Laurens Post <Crote@users.noreply.github.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP\Command;
@@ -36,18 +17,13 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class ShowConfig extends Base {
- /** @var \OCA\User_LDAP\Helper */
- protected $helper;
-
- /**
- * @param Helper $helper
- */
- public function __construct(Helper $helper) {
- $this->helper = $helper;
+ public function __construct(
+ protected Helper $helper,
+ ) {
parent::__construct();
}
- protected function configure() {
+ protected function configure(): void {
$this
->setName('ldap:show-config')
->setDescription('shows the LDAP configuration')
@@ -78,24 +54,27 @@ class ShowConfig extends Base {
if (!is_null($configID)) {
$configIDs[] = $configID;
if (!in_array($configIDs[0], $availableConfigs)) {
- $output->writeln("Invalid configID");
- return 1;
+ $output->writeln('Invalid configID');
+ return self::FAILURE;
}
} else {
$configIDs = $availableConfigs;
}
$this->renderConfigs($configIDs, $input, $output);
- return 0;
+ return self::SUCCESS;
}
/**
* prints the LDAP configuration(s)
- * @param string[] configID(s)
- * @param InputInterface $input
- * @param OutputInterface $output
+ *
+ * @param string[] $configIDs
*/
- protected function renderConfigs($configIDs, $input, $output) {
+ protected function renderConfigs(
+ array $configIDs,
+ InputInterface $input,
+ OutputInterface $output,
+ ): void {
$renderTable = $input->getOption('output') === 'table' or $input->getOption('output') === null;
$showPassword = $input->getOption('show-password');
@@ -121,16 +100,17 @@ class ShowConfig extends Base {
$table->setHeaders(['Configuration', $id]);
$table->setRows($rows);
$table->render();
- } else {
- foreach ($configuration as $key => $value) {
- if ($key === 'ldapAgentPassword' && !$showPassword) {
- $rows[$key] = '***';
- } else {
- $rows[$key] = $value;
- }
+ continue;
+ }
+
+ foreach ($configuration as $key => $value) {
+ if ($key === 'ldapAgentPassword' && !$showPassword) {
+ $rows[$key] = '***';
+ } else {
+ $rows[$key] = $value;
}
- $configs[$id] = $rows;
}
+ $configs[$id] = $rows;
}
if (!$renderTable) {
$this->writeArrayInOutputFormat($input, $output, $configs);
diff --git a/apps/user_ldap/lib/Command/ShowRemnants.php b/apps/user_ldap/lib/Command/ShowRemnants.php
index 55d930dead4..d255aac1368 100644
--- a/apps/user_ldap/lib/Command/ShowRemnants.php
+++ b/apps/user_ldap/lib/Command/ShowRemnants.php
@@ -1,28 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author scolebrook <scolebrook@mac.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP\Command;
@@ -36,23 +17,14 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class ShowRemnants extends Command {
- /** @var \OCA\User_LDAP\User\DeletedUsersIndex */
- protected $dui;
-
- /** @var \OCP\IDateTimeFormatter */
- protected $dateFormatter;
-
- /**
- * @param DeletedUsersIndex $dui
- * @param IDateTimeFormatter $dateFormatter
- */
- public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) {
- $this->dui = $dui;
- $this->dateFormatter = $dateFormatter;
+ public function __construct(
+ protected DeletedUsersIndex $dui,
+ protected IDateTimeFormatter $dateFormatter,
+ ) {
parent::__construct();
}
- protected function configure() {
+ protected function configure(): void {
$this
->setName('ldap:show-remnants')
->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.')
@@ -60,7 +32,7 @@ class ShowRemnants extends Command {
->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format');
}
- protected function formatDate(int $timestamp, string $default, bool $showShortDate) {
+ protected function formatDate(int $timestamp, string $default, bool $showShortDate): string {
if (!($timestamp > 0)) {
return $default;
}
@@ -103,6 +75,6 @@ class ShowRemnants extends Command {
$table->setRows($rows);
$table->render();
}
- return 0;
+ return self::SUCCESS;
}
}
diff --git a/apps/user_ldap/lib/Command/TestConfig.php b/apps/user_ldap/lib/Command/TestConfig.php
index c081b0cb726..77eaac91d85 100644
--- a/apps/user_ldap/lib/Command/TestConfig.php
+++ b/apps/user_ldap/lib/Command/TestConfig.php
@@ -1,28 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Côme Chilliet <come.chilliet@nextcloud.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP\Command;
@@ -41,18 +22,11 @@ class TestConfig extends Command {
protected const BINDFAILURE = 2;
protected const SEARCHFAILURE = 3;
- protected AccessFactory $accessFactory;
- protected Helper $helper;
- protected ILDAPWrapper $ldap;
-
public function __construct(
- AccessFactory $accessFactory,
- Helper $helper,
- ILDAPWrapper $ldap
+ protected AccessFactory $accessFactory,
+ protected Helper $helper,
+ protected ILDAPWrapper $ldap,
) {
- $this->accessFactory = $accessFactory;
- $this->helper = $helper;
- $this->ldap = $ldap;
parent::__construct();
}
@@ -73,28 +47,24 @@ class TestConfig extends Command {
$configID = $input->getArgument('configID');
if (!in_array($configID, $availableConfigs)) {
$output->writeln('Invalid configID');
- return 1;
+ return self::FAILURE;
}
$result = $this->testConfig($configID);
- switch ($result) {
- case static::ESTABLISHED:
- $output->writeln('The configuration is valid and the connection could be established!');
- return 0;
- case static::CONF_INVALID:
- $output->writeln('The configuration is invalid. Please have a look at the logs for further details.');
- break;
- case static::BINDFAILURE:
- $output->writeln('The configuration is valid, but the bind failed. Please check the server settings and credentials.');
- break;
- case static::SEARCHFAILURE:
- $output->writeln('The configuration is valid and the bind passed, but a simple search on the base fails. Please check the server base setting.');
- break;
- default:
- $output->writeln('Your LDAP server was kidnapped by aliens.');
- break;
- }
- return 1;
+
+ $message = match ($result) {
+ static::ESTABLISHED => 'The configuration is valid and the connection could be established!',
+ static::CONF_INVALID => 'The configuration is invalid. Please have a look at the logs for further details.',
+ static::BINDFAILURE => 'The configuration is valid, but the bind failed. Please check the server settings and credentials.',
+ static::SEARCHFAILURE => 'The configuration is valid and the bind passed, but a simple search on the base fails. Please check the server base setting.',
+ default => 'Your LDAP server was kidnapped by aliens.',
+ };
+
+ $output->writeln($message);
+
+ return $result === static::ESTABLISHED
+ ? self::SUCCESS
+ : self::FAILURE;
}
/**
diff --git a/apps/user_ldap/lib/Command/TestUserSettings.php b/apps/user_ldap/lib/Command/TestUserSettings.php
new file mode 100644
index 00000000000..12690158f98
--- /dev/null
+++ b/apps/user_ldap/lib/Command/TestUserSettings.php
@@ -0,0 +1,248 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OCA\User_LDAP\Command;
+
+use OCA\User_LDAP\Group_Proxy;
+use OCA\User_LDAP\Helper;
+use OCA\User_LDAP\Mapping\GroupMapping;
+use OCA\User_LDAP\Mapping\UserMapping;
+use OCA\User_LDAP\User\DeletedUsersIndex;
+use OCA\User_LDAP\User_Proxy;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class TestUserSettings extends Command {
+ public function __construct(
+ protected User_Proxy $backend,
+ protected Group_Proxy $groupBackend,
+ protected Helper $helper,
+ protected DeletedUsersIndex $dui,
+ protected UserMapping $mapping,
+ protected GroupMapping $groupMapping,
+ ) {
+ parent::__construct();
+ }
+
+ protected function configure(): void {
+ $this
+ ->setName('ldap:test-user-settings')
+ ->setDescription('Runs tests and show information about user related LDAP settings')
+ ->addArgument(
+ 'user',
+ InputArgument::REQUIRED,
+ 'the user name as used in Nextcloud, or the LDAP DN'
+ )
+ ->addOption(
+ 'group',
+ 'g',
+ InputOption::VALUE_REQUIRED,
+ 'A group DN to check if the user is a member or not'
+ )
+ ->addOption(
+ 'clearcache',
+ null,
+ InputOption::VALUE_NONE,
+ 'Clear the cache of the LDAP connection before the beginning of tests'
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int {
+ try {
+ $uid = $input->getArgument('user');
+ $access = $this->backend->getLDAPAccess($uid);
+ $connection = $access->getConnection();
+ if ($input->getOption('clearcache')) {
+ $connection->clearCache();
+ }
+ $configPrefix = $connection->getConfigPrefix();
+ $knownDn = '';
+ if ($access->stringResemblesDN($uid)) {
+ $knownDn = $uid;
+ $username = $access->dn2username($uid);
+ if ($username !== false) {
+ $uid = $username;
+ }
+ }
+
+ $dn = $this->mapping->getDNByName($uid);
+ if ($dn !== false) {
+ $output->writeln("User <info>$dn</info> is mapped with account name <info>$uid</info>.");
+ $uuid = $this->mapping->getUUIDByDN($dn);
+ $output->writeln("Known UUID is <info>$uuid</info>.");
+ if ($knownDn === '') {
+ $knownDn = $dn;
+ }
+ } else {
+ $output->writeln("User <info>$uid</info> is not mapped.");
+ }
+
+ if ($knownDn === '') {
+ return self::SUCCESS;
+ }
+
+ if (!$access->isDNPartOfBase($knownDn, $access->getConnection()->ldapBaseUsers)) {
+ $output->writeln(
+ "User <info>$knownDn</info> is not in one of the configured user bases: <info>"
+ . implode(',', $access->getConnection()->ldapBaseUsers)
+ . '</info>.'
+ );
+ }
+
+ $output->writeln("Configuration prefix is <info>$configPrefix</info>");
+ $output->writeln('');
+
+ $attributeNames = [
+ 'ldapBase',
+ 'ldapBaseUsers',
+ 'ldapExpertUsernameAttr',
+ 'ldapUuidUserAttribute',
+ 'ldapExpertUUIDUserAttr',
+ 'ldapQuotaAttribute',
+ 'ldapEmailAttribute',
+ 'ldapUserDisplayName',
+ 'ldapUserDisplayName2',
+ 'ldapExtStorageHomeAttribute',
+ 'ldapAttributePhone',
+ 'ldapAttributeWebsite',
+ 'ldapAttributeAddress',
+ 'ldapAttributeTwitter',
+ 'ldapAttributeFediverse',
+ 'ldapAttributeOrganisation',
+ 'ldapAttributeRole',
+ 'ldapAttributeHeadline',
+ 'ldapAttributeBiography',
+ 'ldapAttributeBirthDate',
+ 'ldapAttributePronouns',
+ 'ldapGidNumber',
+ 'hasGidNumber',
+ ];
+ $output->writeln('Attributes set in configuration:');
+ foreach ($attributeNames as $attributeName) {
+ if (($connection->$attributeName !== '') && ($connection->$attributeName !== [])) {
+ if (\is_string($connection->$attributeName)) {
+ $output->writeln("- $attributeName: <info>" . $connection->$attributeName . '</info>');
+ } else {
+ $output->writeln("- $attributeName: <info>" . \json_encode($connection->$attributeName) . '</info>');
+ }
+ }
+ }
+
+ $filter = $connection->ldapUserFilter;
+ $attrs = $access->userManager->getAttributes(true);
+ $attrs[] = strtolower($connection->ldapExpertUsernameAttr);
+ if ($connection->ldapUuidUserAttribute !== 'auto') {
+ $attrs[] = strtolower($connection->ldapUuidUserAttribute);
+ }
+ if ($connection->hasGidNumber) {
+ $attrs[] = strtolower($connection->ldapGidNumber);
+ }
+ $attrs[] = 'memberof';
+ $attrs = array_values(array_unique($attrs));
+ $attributes = $access->readAttributes($knownDn, $attrs, $filter);
+
+ if ($attributes === false) {
+ $output->writeln(
+ "LDAP read on <info>$knownDn</info> with filter <info>$filter</info> failed."
+ );
+ return self::FAILURE;
+ }
+
+ $output->writeln("Attributes fetched from LDAP using filter <info>$filter</info>:");
+ foreach ($attributes as $attribute => $value) {
+ $output->writeln(
+ "- $attribute: <info>" . json_encode($value) . '</info>'
+ );
+ }
+
+ $uuid = $access->getUUID($knownDn);
+ if ($connection->ldapUuidUserAttribute === 'auto') {
+ $output->writeln('<error>Failed to detect UUID attribute</error>');
+ } else {
+ $output->writeln('Detected UUID attribute: <info>' . $connection->ldapUuidUserAttribute . '</info>');
+ }
+ if ($uuid === false) {
+ $output->writeln("<error>Failed to find UUID for $knownDn</error>");
+ } else {
+ $output->writeln("UUID for <info>$knownDn</info>: <info>$uuid</info>");
+ }
+
+ $groupLdapInstance = $this->groupBackend->getBackend($configPrefix);
+
+ $output->writeln('');
+ $output->writeln('Group information:');
+
+ $attributeNames = [
+ 'ldapBaseGroups',
+ 'ldapDynamicGroupMemberURL',
+ 'ldapGroupFilter',
+ 'ldapGroupMemberAssocAttr',
+ ];
+ $output->writeln('Configuration:');
+ foreach ($attributeNames as $attributeName) {
+ if ($connection->$attributeName !== '') {
+ $output->writeln("- $attributeName: <info>" . $connection->$attributeName . '</info>');
+ }
+ }
+
+ $primaryGroup = $groupLdapInstance->getUserPrimaryGroup($knownDn);
+ $output->writeln('Primary group: <info>' . ($primaryGroup !== false? $primaryGroup:'') . '</info>');
+
+ $groupByGid = $groupLdapInstance->getUserGroupByGid($knownDn);
+ $output->writeln('Group from gidNumber: <info>' . ($groupByGid !== false? $groupByGid:'') . '</info>');
+
+ $groups = $groupLdapInstance->getUserGroups($uid);
+ $output->writeln('All known groups: <info>' . json_encode($groups) . '</info>');
+
+ $memberOfUsed = ((int)$access->connection->hasMemberOfFilterSupport === 1
+ && (int)$access->connection->useMemberOfToDetectMembership === 1);
+
+ $output->writeln('MemberOf usage: <info>' . ($memberOfUsed ? 'on' : 'off') . '</info> (' . $access->connection->hasMemberOfFilterSupport . ',' . $access->connection->useMemberOfToDetectMembership . ')');
+
+ $gid = (string)$input->getOption('group');
+ if ($gid === '') {
+ return self::SUCCESS;
+ }
+
+ $output->writeln('');
+ $output->writeln("Group $gid:");
+ $knownGroupDn = '';
+ if ($access->stringResemblesDN($gid)) {
+ $knownGroupDn = $gid;
+ $groupname = $access->dn2groupname($gid);
+ if ($groupname !== false) {
+ $gid = $groupname;
+ }
+ }
+
+ $groupDn = $this->groupMapping->getDNByName($gid);
+ if ($groupDn !== false) {
+ $output->writeln("Group <info>$groupDn</info> is mapped with name <info>$gid</info>.");
+ $groupUuid = $this->groupMapping->getUUIDByDN($groupDn);
+ $output->writeln("Known UUID is <info>$groupUuid</info>.");
+ if ($knownGroupDn === '') {
+ $knownGroupDn = $groupDn;
+ }
+ } else {
+ $output->writeln("Group <info>$gid</info> is not mapped.");
+ }
+
+ $members = $groupLdapInstance->usersInGroup($gid);
+ $output->writeln('Members: <info>' . json_encode($members) . '</info>');
+
+ return self::SUCCESS;
+
+ } catch (\Exception $e) {
+ $output->writeln('<error>' . $e->getMessage() . '</error>');
+ return self::FAILURE;
+ }
+ }
+}
diff --git a/apps/user_ldap/lib/Command/UpdateUUID.php b/apps/user_ldap/lib/Command/UpdateUUID.php
index 57863a11ec8..93dcc37bada 100644
--- a/apps/user_ldap/lib/Command/UpdateUUID.php
+++ b/apps/user_ldap/lib/Command/UpdateUUID.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2021 Arthur Schiwon <blizzz@arthur-schiwon.de>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Côme Chilliet <come.chilliet@nextcloud.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\User_LDAP\Command;
@@ -49,45 +31,29 @@ class UuidUpdateReport {
public const UNWRITABLE = 4;
public const UNMAPPED = 5;
- public $id = '';
- public $dn = '';
- public $isUser = true;
- public $state = self::UNCHANGED;
- public $oldUuid = '';
- public $newUuid = '';
-
- public function __construct(string $id, string $dn, bool $isUser, int $state, string $oldUuid = '', string $newUuid = '') {
- $this->id = $id;
- $this->dn = $dn;
- $this->isUser = $isUser;
- $this->state = $state;
- $this->oldUuid = $oldUuid;
- $this->newUuid = $newUuid;
+ public function __construct(
+ public string $id,
+ public string $dn,
+ public bool $isUser,
+ public int $state,
+ public string $oldUuid = '',
+ public string $newUuid = '',
+ ) {
}
}
class UpdateUUID extends Command {
- /** @var UserMapping */
- private $userMapping;
- /** @var GroupMapping */
- private $groupMapping;
- /** @var User_Proxy */
- private $userProxy;
- /** @var Group_Proxy */
- private $groupProxy;
/** @var array<UuidUpdateReport[]> */
- protected $reports = [];
- /** @var LoggerInterface */
- private $logger;
- /** @var bool */
- private $dryRun = false;
+ protected array $reports = [];
+ private bool $dryRun = false;
- public function __construct(UserMapping $userMapping, GroupMapping $groupMapping, User_Proxy $userProxy, Group_Proxy $groupProxy, LoggerInterface $logger) {
- $this->userMapping = $userMapping;
- $this->groupMapping = $groupMapping;
- $this->userProxy = $userProxy;
- $this->groupProxy = $groupProxy;
- $this->logger = $logger;
+ public function __construct(
+ private UserMapping $userMapping,
+ private GroupMapping $groupMapping,
+ private User_Proxy $userProxy,
+ private Group_Proxy $groupProxy,
+ private LoggerInterface $logger,
+ ) {
$this->reports = [
UuidUpdateReport::UPDATED => [],
UuidUpdateReport::UNKNOWN => [],
@@ -140,7 +106,7 @@ class UpdateUUID extends Command {
$entriesToUpdate = $this->estimateNumberOfUpdates($input);
$progress = new ProgressBar($output);
$progress->start($entriesToUpdate);
- foreach($this->handleUpdates($input) as $_) {
+ foreach ($this->handleUpdates($input) as $_) {
$progress->advance();
}
$progress->finish();
@@ -149,8 +115,8 @@ class UpdateUUID extends Command {
return count($this->reports[UuidUpdateReport::UNMAPPED]) === 0
&& count($this->reports[UuidUpdateReport::UNREADABLE]) === 0
&& count($this->reports[UuidUpdateReport::UNWRITABLE]) === 0
- ? 0
- : 1;
+ ? self::SUCCESS
+ : self::FAILURE;
}
protected function printReport(OutputInterface $output): void {
@@ -219,37 +185,37 @@ class UpdateUUID extends Command {
protected function handleUpdates(InputInterface $input): \Generator {
if ($input->getOption('all')) {
- foreach($this->handleMappingBasedUpdates(false) as $_) {
+ foreach ($this->handleMappingBasedUpdates(false) as $_) {
yield;
}
} elseif ($input->getOption('userId')
|| $input->getOption('groupId')
|| $input->getOption('dn')
) {
- foreach($this->handleUpdatesByUserId($input->getOption('userId')) as $_) {
+ foreach ($this->handleUpdatesByUserId($input->getOption('userId')) as $_) {
yield;
}
- foreach($this->handleUpdatesByGroupId($input->getOption('groupId')) as $_) {
+ foreach ($this->handleUpdatesByGroupId($input->getOption('groupId')) as $_) {
yield;
}
- foreach($this->handleUpdatesByDN($input->getOption('dn')) as $_) {
+ foreach ($this->handleUpdatesByDN($input->getOption('dn')) as $_) {
yield;
}
} else {
- foreach($this->handleMappingBasedUpdates(true) as $_) {
+ foreach ($this->handleMappingBasedUpdates(true) as $_) {
yield;
}
}
}
protected function handleUpdatesByUserId(array $userIds): \Generator {
- foreach($this->handleUpdatesByEntryId($userIds, $this->userMapping) as $_) {
+ foreach ($this->handleUpdatesByEntryId($userIds, $this->userMapping) as $_) {
yield;
}
}
protected function handleUpdatesByGroupId(array $groupIds): \Generator {
- foreach($this->handleUpdatesByEntryId($groupIds, $this->groupMapping) as $_) {
+ foreach ($this->handleUpdatesByEntryId($groupIds, $this->groupMapping) as $_) {
yield;
}
}
@@ -272,10 +238,10 @@ class UpdateUUID extends Command {
$this->reports[UuidUpdateReport::UNMAPPED][] = new UuidUpdateReport('', $dn, true, UuidUpdateReport::UNMAPPED);
yield;
}
- foreach($this->handleUpdatesByList($this->userMapping, $userList) as $_) {
+ foreach ($this->handleUpdatesByList($this->userMapping, $userList) as $_) {
yield;
}
- foreach($this->handleUpdatesByList($this->groupMapping, $groupList) as $_) {
+ foreach ($this->handleUpdatesByList($this->groupMapping, $groupList) as $_) {
yield;
}
}
@@ -284,7 +250,7 @@ class UpdateUUID extends Command {
$isUser = $mapping instanceof UserMapping;
$list = [];
while ($id = array_pop($ids)) {
- if(!$dn = $mapping->getDNByName($id)) {
+ if (!$dn = $mapping->getDNByName($id)) {
$this->reports[UuidUpdateReport::UNMAPPED][] = new UuidUpdateReport($id, '', $isUser, UuidUpdateReport::UNMAPPED);
yield;
continue;
@@ -293,21 +259,21 @@ class UpdateUUID extends Command {
$uuid = $mapping->getUUIDByDN($dn);
$list[] = ['name' => $id, 'uuid' => $uuid];
}
- foreach($this->handleUpdatesByList($mapping, $list) as $_) {
+ foreach ($this->handleUpdatesByList($mapping, $list) as $_) {
yield;
}
}
protected function handleMappingBasedUpdates(bool $invalidatedOnly): \Generator {
$limit = 1000;
- /** @var AbstractMapping $mapping*/
- foreach([$this->userMapping, $this->groupMapping] as $mapping) {
+ /** @var AbstractMapping $mapping */
+ foreach ([$this->userMapping, $this->groupMapping] as $mapping) {
$offset = 0;
do {
$list = $mapping->getList($offset, $limit, $invalidatedOnly);
$offset += $limit;
- foreach($this->handleUpdatesByList($mapping, $list) as $tick) {
+ foreach ($this->handleUpdatesByList($mapping, $list) as $tick) {
yield; // null, for it only advances progress counter
}
} while (count($list) === $limit);
@@ -369,5 +335,4 @@ class UpdateUUID extends Command {
return $this->userMapping->countInvalidated() + $this->groupMapping->countInvalidated();
}
}
-
}