aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command/TwoFactorAuth
diff options
context:
space:
mode:
Diffstat (limited to 'core/Command/TwoFactorAuth')
-rw-r--r--core/Command/TwoFactorAuth/Base.php32
-rw-r--r--core/Command/TwoFactorAuth/Cleanup.php37
-rw-r--r--core/Command/TwoFactorAuth/Disable.php41
-rw-r--r--core/Command/TwoFactorAuth/Enable.php41
-rw-r--r--core/Command/TwoFactorAuth/Enforce.php32
-rw-r--r--core/Command/TwoFactorAuth/State.php51
6 files changed, 71 insertions, 163 deletions
diff --git a/core/Command/TwoFactorAuth/Base.php b/core/Command/TwoFactorAuth/Base.php
index 27bd381d951..034ea36afca 100644
--- a/core/Command/TwoFactorAuth/Base.php
+++ b/core/Command/TwoFactorAuth/Base.php
@@ -1,27 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Core\Command\TwoFactorAuth;
@@ -30,7 +11,12 @@ use OCP\IUserManager;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
class Base extends \OC\Core\Command\Base {
- protected IUserManager $userManager;
+ public function __construct(
+ ?string $name,
+ protected IUserManager $userManager,
+ ) {
+ parent::__construct($name);
+ }
/**
* Return possible values for the named option
diff --git a/core/Command/TwoFactorAuth/Cleanup.php b/core/Command/TwoFactorAuth/Cleanup.php
index 7d3fc3c33f7..f8f116af3fd 100644
--- a/core/Command/TwoFactorAuth/Cleanup.php
+++ b/core/Command/TwoFactorAuth/Cleanup.php
@@ -3,41 +3,26 @@
declare(strict_types=1);
/**
- * @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.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: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Core\Command\TwoFactorAuth;
use OCP\Authentication\TwoFactorAuth\IRegistry;
+use OCP\IUserManager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Cleanup extends Base {
- private IRegistry $registry;
-
- public function __construct(IRegistry $registry) {
- parent::__construct();
-
- $this->registry = $registry;
+ public function __construct(
+ private IRegistry $registry,
+ IUserManager $userManager,
+ ) {
+ parent::__construct(
+ null,
+ $userManager,
+ );
}
protected function configure() {
diff --git a/core/Command/TwoFactorAuth/Disable.php b/core/Command/TwoFactorAuth/Disable.php
index 54e4b138a0a..c60c1245735 100644
--- a/core/Command/TwoFactorAuth/Disable.php
+++ b/core/Command/TwoFactorAuth/Disable.php
@@ -1,24 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.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 OC\Core\Command\TwoFactorAuth;
@@ -29,12 +14,14 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Disable extends Base {
- private ProviderManager $manager;
-
- public function __construct(ProviderManager $manager, IUserManager $userManager) {
- parent::__construct('twofactorauth:disable');
- $this->manager = $manager;
- $this->userManager = $userManager;
+ public function __construct(
+ private ProviderManager $manager,
+ IUserManager $userManager,
+ ) {
+ parent::__construct(
+ 'twofactorauth:disable',
+ $userManager,
+ );
}
protected function configure() {
@@ -51,14 +38,14 @@ class Disable extends Base {
$providerId = $input->getArgument('provider_id');
$user = $this->userManager->get($uid);
if (is_null($user)) {
- $output->writeln("<error>Invalid UID</error>");
+ $output->writeln('<error>Invalid UID</error>');
return 1;
}
if ($this->manager->tryDisableProviderFor($providerId, $user)) {
$output->writeln("Two-factor provider <options=bold>$providerId</> disabled for user <options=bold>$uid</>.");
return 0;
} else {
- $output->writeln("<error>The provider does not support this operation.</error>");
+ $output->writeln('<error>The provider does not support this operation.</error>');
return 2;
}
}
diff --git a/core/Command/TwoFactorAuth/Enable.php b/core/Command/TwoFactorAuth/Enable.php
index 67c1778399d..215cb31397e 100644
--- a/core/Command/TwoFactorAuth/Enable.php
+++ b/core/Command/TwoFactorAuth/Enable.php
@@ -1,24 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.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 OC\Core\Command\TwoFactorAuth;
@@ -29,12 +14,14 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Enable extends Base {
- private ProviderManager $manager;
-
- public function __construct(ProviderManager $manager, IUserManager $userManager) {
- parent::__construct('twofactorauth:enable');
- $this->manager = $manager;
- $this->userManager = $userManager;
+ public function __construct(
+ private ProviderManager $manager,
+ IUserManager $userManager,
+ ) {
+ parent::__construct(
+ 'twofactorauth:enable',
+ $userManager,
+ );
}
protected function configure() {
@@ -51,14 +38,14 @@ class Enable extends Base {
$providerId = $input->getArgument('provider_id');
$user = $this->userManager->get($uid);
if (is_null($user)) {
- $output->writeln("<error>Invalid UID</error>");
+ $output->writeln('<error>Invalid UID</error>');
return 1;
}
if ($this->manager->tryEnableProviderFor($providerId, $user)) {
$output->writeln("Two-factor provider <options=bold>$providerId</> enabled for user <options=bold>$uid</>.");
return 0;
} else {
- $output->writeln("<error>The provider does not support this operation.</error>");
+ $output->writeln('<error>The provider does not support this operation.</error>');
return 2;
}
}
diff --git a/core/Command/TwoFactorAuth/Enforce.php b/core/Command/TwoFactorAuth/Enforce.php
index d8fa41e2e95..3315f045bc8 100644
--- a/core/Command/TwoFactorAuth/Enforce.php
+++ b/core/Command/TwoFactorAuth/Enforce.php
@@ -3,44 +3,24 @@
declare(strict_types=1);
/**
- * @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.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: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Core\Command\TwoFactorAuth;
-use function implode;
use OC\Authentication\TwoFactorAuth\EnforcementState;
use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use function implode;
class Enforce extends Command {
- private MandatoryTwoFactor $mandatoryTwoFactor;
-
- public function __construct(MandatoryTwoFactor $mandatoryTwoFactor) {
+ public function __construct(
+ private MandatoryTwoFactor $mandatoryTwoFactor,
+ ) {
parent::__construct();
-
- $this->mandatoryTwoFactor = $mandatoryTwoFactor;
}
protected function configure() {
diff --git a/core/Command/TwoFactorAuth/State.php b/core/Command/TwoFactorAuth/State.php
index 4694c76b408..ab2e8f2aecf 100644
--- a/core/Command/TwoFactorAuth/State.php
+++ b/core/Command/TwoFactorAuth/State.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.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: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Core\Command\TwoFactorAuth;
@@ -33,13 +15,14 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class State extends Base {
- private IRegistry $registry;
-
- public function __construct(IRegistry $registry, IUserManager $userManager) {
- parent::__construct('twofactorauth:state');
-
- $this->registry = $registry;
- $this->userManager = $userManager;
+ public function __construct(
+ private IRegistry $registry,
+ IUserManager $userManager,
+ ) {
+ parent::__construct(
+ 'twofactorauth:state',
+ $userManager,
+ );
}
protected function configure() {
@@ -54,7 +37,7 @@ class State extends Base {
$uid = $input->getArgument('uid');
$user = $this->userManager->get($uid);
if (is_null($user)) {
- $output->writeln("<error>Invalid UID</error>");
+ $output->writeln('<error>Invalid UID</error>');
return 1;
}
@@ -68,9 +51,9 @@ class State extends Base {
$output->writeln("Two-factor authentication is not enabled for user $uid");
}
- $output->writeln("");
- $this->printProviders("Enabled providers", $enabled, $output);
- $this->printProviders("Disabled providers", $disabled, $output);
+ $output->writeln('');
+ $this->printProviders('Enabled providers', $enabled, $output);
+ $this->printProviders('Disabled providers', $disabled, $output);
return 0;
}
@@ -91,15 +74,15 @@ class State extends Base {
}
private function printProviders(string $title, array $providers,
- OutputInterface $output) {
+ OutputInterface $output) {
if (empty($providers)) {
// Ignore and don't print anything
return;
}
- $output->writeln($title . ":");
+ $output->writeln($title . ':');
foreach ($providers as $provider) {
- $output->writeln("- " . $provider);
+ $output->writeln('- ' . $provider);
}
}
}