diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2022-09-06 23:34:54 +0300 |
---|---|---|
committer | backportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com> | 2022-10-21 19:58:12 +0300 |
commit | 0fd9d8b132a7f748920fb994de1f1b838a33c65a (patch) | |
tree | 9a8e657b5e91ea8623f8c6e4037d29a36891d458 /lib | |
parent | d2333d10810762cf0f83eddff1e7e2b48149c30a (diff) |
LDAP to no register new users when outside of fair use or over limits
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 2 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 2 | ||||
-rw-r--r-- | lib/private/Server.php | 1 | ||||
-rw-r--r-- | lib/private/Support/Subscription/Assertion.php | 55 | ||||
-rw-r--r-- | lib/private/User/Manager.php | 17 | ||||
-rw-r--r-- | lib/public/Support/Subscription/IAssertion.php | 44 |
6 files changed, 110 insertions, 11 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 0d9b99ab1c1..d396dbfcb33 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -567,6 +567,7 @@ return array( 'OCP\\Support\\CrashReport\\IRegistry' => $baseDir . '/lib/public/Support/CrashReport/IRegistry.php', 'OCP\\Support\\CrashReport\\IReporter' => $baseDir . '/lib/public/Support/CrashReport/IReporter.php', 'OCP\\Support\\Subscription\\Exception\\AlreadyRegisteredException' => $baseDir . '/lib/public/Support/Subscription/Exception/AlreadyRegisteredException.php', + 'OCP\\Support\\Subscription\\IAssertion' => $baseDir . '/lib/public/Support/Subscription/IAssertion.php', 'OCP\\Support\\Subscription\\IRegistry' => $baseDir . '/lib/public/Support/Subscription/IRegistry.php', 'OCP\\Support\\Subscription\\ISubscription' => $baseDir . '/lib/public/Support/Subscription/ISubscription.php', 'OCP\\Support\\Subscription\\ISupportedApps' => $baseDir . '/lib/public/Support/Subscription/ISupportedApps.php', @@ -1553,6 +1554,7 @@ return array( 'OC\\Streamer' => $baseDir . '/lib/private/Streamer.php', 'OC\\SubAdmin' => $baseDir . '/lib/private/SubAdmin.php', 'OC\\Support\\CrashReport\\Registry' => $baseDir . '/lib/private/Support/CrashReport/Registry.php', + 'OC\\Support\\Subscription\\Assertion' => $baseDir . '/lib/private/Support/Subscription/Assertion.php', 'OC\\Support\\Subscription\\Registry' => $baseDir . '/lib/private/Support/Subscription/Registry.php', 'OC\\SystemConfig' => $baseDir . '/lib/private/SystemConfig.php', 'OC\\SystemTag\\ManagerFactory' => $baseDir . '/lib/private/SystemTag/ManagerFactory.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index d69298c0263..20a7114b94a 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -600,6 +600,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Support\\CrashReport\\IRegistry' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/IRegistry.php', 'OCP\\Support\\CrashReport\\IReporter' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/IReporter.php', 'OCP\\Support\\Subscription\\Exception\\AlreadyRegisteredException' => __DIR__ . '/../../..' . '/lib/public/Support/Subscription/Exception/AlreadyRegisteredException.php', + 'OCP\\Support\\Subscription\\IAssertion' => __DIR__ . '/../../..' . '/lib/public/Support/Subscription/IAssertion.php', 'OCP\\Support\\Subscription\\IRegistry' => __DIR__ . '/../../..' . '/lib/public/Support/Subscription/IRegistry.php', 'OCP\\Support\\Subscription\\ISubscription' => __DIR__ . '/../../..' . '/lib/public/Support/Subscription/ISubscription.php', 'OCP\\Support\\Subscription\\ISupportedApps' => __DIR__ . '/../../..' . '/lib/public/Support/Subscription/ISupportedApps.php', @@ -1586,6 +1587,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Streamer' => __DIR__ . '/../../..' . '/lib/private/Streamer.php', 'OC\\SubAdmin' => __DIR__ . '/../../..' . '/lib/private/SubAdmin.php', 'OC\\Support\\CrashReport\\Registry' => __DIR__ . '/../../..' . '/lib/private/Support/CrashReport/Registry.php', + 'OC\\Support\\Subscription\\Assertion' => __DIR__ . '/../../..' . '/lib/private/Support/Subscription/Assertion.php', 'OC\\Support\\Subscription\\Registry' => __DIR__ . '/../../..' . '/lib/private/Support/Subscription/Registry.php', 'OC\\SystemConfig' => __DIR__ . '/../../..' . '/lib/private/SystemConfig.php', 'OC\\SystemTag\\ManagerFactory' => __DIR__ . '/../../..' . '/lib/private/SystemTag/ManagerFactory.php', diff --git a/lib/private/Server.php b/lib/private/Server.php index a94e0d568b0..4f2a93677c5 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -794,6 +794,7 @@ class Server extends ServerContainer implements IServerContainer { $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); + $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class); $this->registerService(\OC\Log::class, function (Server $c) { $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); diff --git a/lib/private/Support/Subscription/Assertion.php b/lib/private/Support/Subscription/Assertion.php new file mode 100644 index 00000000000..9acd3f878c3 --- /dev/null +++ b/lib/private/Support/Subscription/Assertion.php @@ -0,0 +1,55 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022 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 <https://www.gnu.org/licenses/>. + * + */ + +namespace OC\Support\Subscription; + +use OCP\HintException; +use OCP\L10N\IFactory; +use OCP\Notification\IManager; +use OCP\Support\Subscription\IAssertion; +use OCP\Support\Subscription\IRegistry; + +class Assertion implements IAssertion { + private IRegistry $registry; + private IFactory $l10nFactory; + private IManager $notificationManager; + + public function __construct(IRegistry $registry, IFactory $l10nFactory, IManager $notificationManager) { + $this->registry = $registry; + $this->l10nFactory = $l10nFactory; + $this->notificationManager = $notificationManager; + } + + /** + * @inheritDoc + */ + public function createUserIsLegit(): void { + if ($this->registry->delegateIsHardUserLimitReached($this->notificationManager)) { + $l = $this->l10nFactory->get('lib'); + throw new HintException($l->t('The user limit has been reached and the user was not created.')); + } + } +} diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index be5151313c4..dc31eece414 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -44,8 +44,7 @@ use OCP\IGroup; use OCP\IUser; use OCP\IUserBackend; use OCP\IUserManager; -use OCP\Notification\IManager; -use OCP\Support\Subscription\IRegistry; +use OCP\Support\Subscription\IAssertion; use OCP\User\Backend\IGetRealUIDBackend; use OCP\User\Backend\ISearchKnownUsersBackend; use OCP\User\Backend\ICheckPasswordBackend; @@ -386,19 +385,15 @@ class Manager extends PublicEmitter implements IUserManager { /** * @param string $uid * @param string $password - * @throws \InvalidArgumentException * @return false|IUser the created user or false + * @throws \InvalidArgumentException + * @throws HintException */ public function createUser($uid, $password) { // DI injection is not used here as IRegistry needs the user manager itself for user count and thus it would create a cyclic dependency - /** @var IRegistry $registry */ - $registry = \OC::$server->get(IRegistry::class); - /** @var IManager $notificationManager */ - $notificationManager = \OC::$server->get(IManager::class); - if ($registry->delegateIsHardUserLimitReached($notificationManager)) { - $l = \OC::$server->getL10N('lib'); - throw new HintException($l->t('The user limit has been reached and the user was not created.')); - } + /** @var IAssertion $assertion */ + $assertion = \OC::$server->get(IAssertion::class); + $assertion->createUserIsLegit(); $localBackends = []; foreach ($this->backends as $backend) { diff --git a/lib/public/Support/Subscription/IAssertion.php b/lib/public/Support/Subscription/IAssertion.php new file mode 100644 index 00000000000..1ef6a7b7187 --- /dev/null +++ b/lib/public/Support/Subscription/IAssertion.php @@ -0,0 +1,44 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2022 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 <https://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Support\Subscription; + +use OCP\HintException; + +/** + * @since 26.0.0 + */ +interface IAssertion { + /** + * This method throws a localized exception when user limits are exceeded, + * if applicable. Notifications are also created in that case. It is a + * shorthand for a check against IRegistry::delegateIsHardUserLimitReached(). + * + * @throws HintException + * @since 26.0.0 + */ + public function createUserIsLegit(): void; +} |