]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix!: Remove legacy event dispatching Symfony's GenericEvent from 2FA Manager
authorJoas Schilling <coding@schilljs.com>
Tue, 25 Jul 2023 09:54:36 +0000 (11:54 +0200)
committerJoas Schilling <coding@schilljs.com>
Thu, 27 Jul 2023 07:57:52 +0000 (09:57 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/dav/lib/Connector/Sabre/Auth.php
lib/private/Authentication/TwoFactorAuth/Manager.php
lib/public/Authentication/TwoFactorAuth/IProvider.php
tests/lib/Authentication/TwoFactorAuth/ManagerTest.php

index 69e3946bb1152a320a5fe8abefe2a1bfa5a29dac..75e3f61fded65e0a9f5a4c1c81420fc29c238242 100644 (file)
@@ -37,7 +37,6 @@ use Exception;
 use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
 use OC\Authentication\TwoFactorAuth\Manager;
 use OC\Security\Bruteforce\Throttler;
-use OC\User\LoginException;
 use OC\User\Session;
 use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
 use OCA\DAV\Connector\Sabre\Exception\TooManyRequests;
index 17937de4e44eb252746fd34ee2b127aa79e957a7..8ae08ca65ae2503609bacc8dbdc70b1d0e85289d 100644 (file)
@@ -46,8 +46,6 @@ use OCP\ISession;
 use OCP\IUser;
 use OCP\Session\Exceptions\SessionNotAvailableException;
 use Psr\Log\LoggerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
 use function array_diff;
 use function array_filter;
 
@@ -87,9 +85,6 @@ class Manager {
        /** @var IEventDispatcher */
        private $dispatcher;
 
-       /** @var EventDispatcherInterface */
-       private $legacyDispatcher;
-
        /** @psalm-var array<string, bool> */
        private $userIsTwoFactorAuthenticated = [];
 
@@ -102,8 +97,7 @@ class Manager {
                                                                LoggerInterface $logger,
                                                                TokenProvider $tokenProvider,
                                                                ITimeFactory $timeFactory,
-                                                               IEventDispatcher $eventDispatcher,
-                                                               EventDispatcherInterface $legacyDispatcher) {
+                                                               IEventDispatcher $eventDispatcher) {
                $this->providerLoader = $providerLoader;
                $this->providerRegistry = $providerRegistry;
                $this->mandatoryTwoFactor = $mandatoryTwoFactor;
@@ -114,7 +108,6 @@ class Manager {
                $this->tokenProvider = $tokenProvider;
                $this->timeFactory = $timeFactory;
                $this->dispatcher = $eventDispatcher;
-               $this->legacyDispatcher = $legacyDispatcher;
        }
 
        /**
@@ -284,9 +277,6 @@ class Manager {
                        $tokenId = $token->getId();
                        $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', (string)$tokenId);
 
-                       $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]);
-                       $this->legacyDispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent);
-
                        $this->dispatcher->dispatchTyped(new TwoFactorProviderForUserEnabled($user, $provider));
                        $this->dispatcher->dispatchTyped(new TwoFactorProviderChallengePassed($user, $provider));
 
@@ -294,9 +284,6 @@ class Manager {
                                'provider' => $provider->getDisplayName(),
                        ]);
                } else {
-                       $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]);
-                       $this->legacyDispatcher->dispatch(IProvider::EVENT_FAILED, $dispatchEvent);
-
                        $this->dispatcher->dispatchTyped(new TwoFactorProviderForUserDisabled($user, $provider));
                        $this->dispatcher->dispatchTyped(new TwoFactorProviderChallengeFailed($user, $provider));
 
index 09fa7a56f5ce90b3f5a87306d456ff80227f9833..7cb6c83bdf645a40c2bee3b2d4366fed7781660b 100644 (file)
@@ -32,17 +32,6 @@ use OCP\Template;
  * @since 9.1.0
  */
 interface IProvider {
-       /**
-        * @since 14.0.0
-        * @deprecated 22.0.0
-        */
-       public const EVENT_SUCCESS = self::class . '::success';
-
-       /**
-        * @deprecated 22.0.0
-        */
-       public const EVENT_FAILED = self::class . '::failed';
-
        /**
         * Get unique identifier of this 2FA provider
         *
index da11b11e53780b5b51dd869d31fb7025feac882d..7647e3bda7df190788041dd3342808d4b5a5d89b 100644 (file)
@@ -40,7 +40,6 @@ use OCP\IUser;
 use PHPUnit\Framework\MockObject\MockObject;
 use Psr\Log\LoggerInterface;
 use function reset;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Test\TestCase;
 
 class ManagerTest extends TestCase {
@@ -84,10 +83,7 @@ class ManagerTest extends TestCase {
        private $timeFactory;
 
        /** @var IEventDispatcher|MockObject */
-       private $newDispatcher;
-
-       /** @var EventDispatcherInterface|MockObject */
-       private $eventDispatcher;
+       private $dispatcher;
 
        protected function setUp(): void {
                parent::setUp();
@@ -102,8 +98,7 @@ class ManagerTest extends TestCase {
                $this->logger = $this->createMock(LoggerInterface::class);
                $this->tokenProvider = $this->createMock(TokenProvider::class);
                $this->timeFactory = $this->createMock(ITimeFactory::class);
-               $this->newDispatcher = $this->createMock(IEventDispatcher::class);
-               $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
+               $this->dispatcher = $this->createMock(IEventDispatcher::class);
 
                $this->manager = new Manager(
                        $this->providerLoader,
@@ -115,8 +110,7 @@ class ManagerTest extends TestCase {
                        $this->logger,
                        $this->tokenProvider,
                        $this->timeFactory,
-                       $this->newDispatcher,
-                       $this->eventDispatcher
+                       $this->dispatcher,
                );
 
                $this->fakeProvider = $this->createMock(IProvider::class);
@@ -530,8 +524,7 @@ class ManagerTest extends TestCase {
                                $this->logger,
                                $this->tokenProvider,
                                $this->timeFactory,
-                               $this->newDispatcher,
-                               $this->eventDispatcher
+                               $this->dispatcher,
                        ])
                        ->setMethods(['loadTwoFactorApp', 'isTwoFactorAuthenticated'])// Do not actually load the apps
                        ->getMock();