aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/admin_audit/lib/Actions/Security.php29
-rw-r--r--apps/admin_audit/lib/AppInfo/Application.php42
-rw-r--r--apps/admin_audit/tests/Actions/SecurityTest.php15
-rw-r--r--apps/dav/lib/HookManager.php7
-rw-r--r--apps/dav/tests/unit/DAV/HookManagerTest.php13
-rw-r--r--console.php2
-rw-r--r--lib/private/Console/Application.php12
7 files changed, 63 insertions, 57 deletions
diff --git a/apps/admin_audit/lib/Actions/Security.php b/apps/admin_audit/lib/Actions/Security.php
index e4831ac6fc1..17cf0c3c2b9 100644
--- a/apps/admin_audit/lib/Actions/Security.php
+++ b/apps/admin_audit/lib/Actions/Security.php
@@ -26,6 +26,7 @@ declare(strict_types=1);
*/
namespace OCA\AdminAudit\Actions;
+use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\IUser;
/**
@@ -35,14 +36,14 @@ use OCP\IUser;
*/
class Security extends Action {
/**
- * Log twofactor auth enabled
- *
- * @param IUser $user
- * @param array $params
+ * Logs failed twofactor challenge
*/
- public function twofactorFailed(IUser $user, array $params): void {
- $params['uid'] = $user->getUID();
- $params['displayName'] = $user->getDisplayName();
+ public function twofactorFailed(IUser $user, IProvider $provider): void {
+ $params = [
+ 'displayName' => $user->getDisplayName(),
+ 'uid' => $user->getUID(),
+ 'provider' => $provider->getDisplayName(),
+ ];
$this->log(
'Failed two factor attempt by user %s (%s) with provider %s',
@@ -56,14 +57,14 @@ class Security extends Action {
}
/**
- * Logs unsharing of data
- *
- * @param IUser $user
- * @param array $params
+ * Logs successful twofactor challenge
*/
- public function twofactorSuccess(IUser $user, array $params): void {
- $params['uid'] = $user->getUID();
- $params['displayName'] = $user->getDisplayName();
+ public function twofactorSuccess(IUser $user, IProvider $provider): void {
+ $params = [
+ 'displayName' => $user->getDisplayName(),
+ 'uid' => $user->getUID(),
+ 'provider' => $provider->getDisplayName(),
+ ];
$this->log(
'Successful two factor attempt by user %s (%s) with provider %s',
diff --git a/apps/admin_audit/lib/AppInfo/Application.php b/apps/admin_audit/lib/AppInfo/Application.php
index 1160d151710..7a4d2d6e3d1 100644
--- a/apps/admin_audit/lib/AppInfo/Application.php
+++ b/apps/admin_audit/lib/AppInfo/Application.php
@@ -57,7 +57,10 @@ use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Authentication\TwoFactorAuth\IProvider;
+use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengeFailed;
+use OCP\Authentication\TwoFactorAuth\TwoFactorProviderChallengePassed;
use OCP\Console\ConsoleEvent;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IPreview;
@@ -65,6 +68,7 @@ use OCP\IServerContainer;
use OCP\IUserSession;
use OCP\Log\Audit\CriticalActionPerformedEvent;
use OCP\Log\ILogFactory;
+use OCP\Preview\BeforePreviewFetchedEvent;
use OCP\Share;
use OCP\Util;
use Psr\Container\ContainerInterface;
@@ -109,8 +113,9 @@ class Application extends App implements IBootstrap {
$this->groupHooks($logger, $serverContainer->get(IGroupManager::class));
$this->authHooks($logger);
- /** @var EventDispatcherInterface $eventDispatcher */
- $eventDispatcher = $serverContainer->get(EventDispatcherInterface::class);
+
+ /** @var IEventDispatcher $eventDispatcher */
+ $eventDispatcher = $serverContainer->get(IEventDispatcher::class);
$this->consoleHooks($logger, $eventDispatcher);
$this->appHooks($logger, $eventDispatcher);
@@ -169,7 +174,7 @@ class Application extends App implements IBootstrap {
}
private function appHooks(IAuditLogger $logger,
- EventDispatcherInterface $eventDispatcher): void {
+ IEventDispatcher $eventDispatcher): void {
$eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function (ManagerEvent $event) use ($logger) {
$appActions = new AppManagement($logger);
$appActions->enableApp($event->getAppID());
@@ -185,27 +190,26 @@ class Application extends App implements IBootstrap {
}
private function consoleHooks(IAuditLogger $logger,
- EventDispatcherInterface $eventDispatcher): void {
- $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function (ConsoleEvent $event) use ($logger) {
+ IEventDispatcher $eventDispatcher): void {
+ $eventDispatcher->addListener(ConsoleEvent::class, function (ConsoleEvent $event) use ($logger) {
$appActions = new Console($logger);
$appActions->runCommand($event->getArguments());
});
}
private function fileHooks(IAuditLogger $logger,
- EventDispatcherInterface $eventDispatcher): void {
+ IEventDispatcher $eventDispatcher): void {
$fileActions = new Files($logger);
$eventDispatcher->addListener(
- IPreview::EVENT,
- function (GenericEvent $event) use ($fileActions) {
- /** @var File $file */
- $file = $event->getSubject();
+ BeforePreviewFetchedEvent::class,
+ function (BeforePreviewFetchedEvent $event) use ($fileActions) {
+ $file = $event->getNode();
$fileActions->preview([
'path' => mb_substr($file->getInternalPath(), 5),
- 'width' => $event->getArguments()['width'],
- 'height' => $event->getArguments()['height'],
- 'crop' => $event->getArguments()['crop'],
- 'mode' => $event->getArguments()['mode']
+ 'width' => $event->getWidth(),
+ 'height' => $event->getHeight(),
+ 'crop' => $event->isCrop(),
+ 'mode' => $event->getMode()
]);
}
);
@@ -267,14 +271,14 @@ class Application extends App implements IBootstrap {
}
private function securityHooks(IAuditLogger $logger,
- EventDispatcherInterface $eventDispatcher): void {
- $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function (GenericEvent $event) use ($logger) {
+ IEventDispatcher $eventDispatcher): void {
+ $eventDispatcher->addListener(TwoFactorProviderChallengePassed::class, function (TwoFactorProviderChallengePassed $event) use ($logger) {
$security = new Security($logger);
- $security->twofactorSuccess($event->getSubject(), $event->getArguments());
+ $security->twofactorSuccess($event->getUser(), $event->getProvider());
});
- $eventDispatcher->addListener(IProvider::EVENT_FAILED, function (GenericEvent $event) use ($logger) {
+ $eventDispatcher->addListener(TwoFactorProviderChallengeFailed::class, function (TwoFactorProviderChallengeFailed $event) use ($logger) {
$security = new Security($logger);
- $security->twofactorFailed($event->getSubject(), $event->getArguments());
+ $security->twofactorFailed($event->getUser(), $event->getProvider());
});
}
}
diff --git a/apps/admin_audit/tests/Actions/SecurityTest.php b/apps/admin_audit/tests/Actions/SecurityTest.php
index d45cbb75a64..bba819ad04d 100644
--- a/apps/admin_audit/tests/Actions/SecurityTest.php
+++ b/apps/admin_audit/tests/Actions/SecurityTest.php
@@ -27,8 +27,9 @@ declare(strict_types=1);
namespace OCA\AdminAudit\Tests\Actions;
use OCA\AdminAudit\Actions\Security;
-use OCP\IUser;
use OCA\AdminAudit\AuditLogger;
+use OCP\Authentication\TwoFactorAuth\IProvider;
+use OCP\IUser;
use Test\TestCase;
class SecurityTest extends TestCase {
@@ -60,7 +61,11 @@ class SecurityTest extends TestCase {
['app' => 'admin_audit']
);
- $this->security->twofactorFailed($this->user, ['provider' => 'myprovider']);
+ $provider = $this->createMock(IProvider::class);
+ $provider->method('getDisplayName')
+ ->willReturn('myprovider');
+
+ $this->security->twofactorFailed($this->user, $provider);
}
public function testTwofactorSuccess() {
@@ -71,6 +76,10 @@ class SecurityTest extends TestCase {
['app' => 'admin_audit']
);
- $this->security->twofactorSuccess($this->user, ['provider' => 'myprovider']);
+ $provider = $this->createMock(IProvider::class);
+ $provider->method('getDisplayName')
+ ->willReturn('myprovider');
+
+ $this->security->twofactorSuccess($this->user, $provider);
}
}
diff --git a/apps/dav/lib/HookManager.php b/apps/dav/lib/HookManager.php
index b69d9b0cd79..ae92a9c9335 100644
--- a/apps/dav/lib/HookManager.php
+++ b/apps/dav/lib/HookManager.php
@@ -67,21 +67,16 @@ class HookManager {
/** @var Defaults */
private $themingDefaults;
- /** @var EventDispatcherInterface */
- private $eventDispatcher;
-
public function __construct(IUserManager $userManager,
SyncService $syncService,
CalDavBackend $calDav,
CardDavBackend $cardDav,
- Defaults $themingDefaults,
- EventDispatcherInterface $eventDispatcher) {
+ Defaults $themingDefaults) {
$this->userManager = $userManager;
$this->syncService = $syncService;
$this->calDav = $calDav;
$this->cardDav = $cardDav;
$this->themingDefaults = $themingDefaults;
- $this->eventDispatcher = $eventDispatcher;
}
public function setup() {
diff --git a/apps/dav/tests/unit/DAV/HookManagerTest.php b/apps/dav/tests/unit/DAV/HookManagerTest.php
index eeda27d8aa3..97abe3881c0 100644
--- a/apps/dav/tests/unit/DAV/HookManagerTest.php
+++ b/apps/dav/tests/unit/DAV/HookManagerTest.php
@@ -39,19 +39,14 @@ use OCP\IL10N;
use OCP\IUser;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
class HookManagerTest extends TestCase {
/** @var IL10N */
private $l10n;
- /** @var EventDispatcherInterface | MockObject */
- private $eventDispatcher;
-
protected function setUp(): void {
parent::setUp();
- $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->l10n = $this->createMock(IL10N::class);
$this->l10n
->expects($this->any())
@@ -106,7 +101,7 @@ class HookManagerTest extends TestCase {
'principals/users/newUser',
'contacts', ['{DAV:}displayname' => 'Contacts']);
- $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults, $this->eventDispatcher);
+ $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults);
$hm->firstLogin($user);
}
@@ -145,7 +140,7 @@ class HookManagerTest extends TestCase {
$card->expects($this->once())->method('getAddressBooksForUserCount')->willReturn(1);
$card->expects($this->never())->method('createAddressBook');
- $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults, $this->eventDispatcher);
+ $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults);
$hm->firstLogin($user);
}
@@ -193,7 +188,7 @@ class HookManagerTest extends TestCase {
'principals/users/newUser',
'contacts', ['{DAV:}displayname' => 'Contacts']);
- $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults, $this->eventDispatcher);
+ $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults);
$hm->firstLogin($user);
}
@@ -243,7 +238,7 @@ class HookManagerTest extends TestCase {
]);
$card->expects($this->once())->method('deleteAddressBook');
- $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults, $this->eventDispatcher);
+ $hm = new HookManager($userManager, $syncService, $cal, $card, $defaults);
$hm->preDeleteUser(['uid' => 'newUser']);
$hm->postDeleteUser(['uid' => 'newUser']);
}
diff --git a/console.php b/console.php
index f9a4689bd58..d30db9adb6e 100644
--- a/console.php
+++ b/console.php
@@ -91,7 +91,7 @@ try {
$application = new Application(
\OC::$server->getConfig(),
- \OC::$server->getEventDispatcher(),
+ \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
\OC::$server->getRequest(),
\OC::$server->get(\Psr\Log\LoggerInterface::class),
\OC::$server->query(\OC\MemoryInfo::class)
diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php
index 94956364390..11515f26866 100644
--- a/lib/private/Console/Application.php
+++ b/lib/private/Console/Application.php
@@ -36,6 +36,7 @@ use OC_App;
use OCP\AppFramework\QueryException;
use OCP\App\IAppManager;
use OCP\Console\ConsoleEvent;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IRequest;
use Psr\Log\LoggerInterface;
@@ -44,13 +45,12 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class Application {
/** @var IConfig */
private $config;
private SymfonyApplication $application;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $dispatcher;
/** @var IRequest */
private $request;
@@ -60,7 +60,7 @@ class Application {
private $memoryInfo;
public function __construct(IConfig $config,
- EventDispatcherInterface $dispatcher,
+ IEventDispatcher $dispatcher,
IRequest $request,
LoggerInterface $logger,
MemoryInfo $memoryInfo) {
@@ -204,10 +204,12 @@ class Application {
* @throws \Exception
*/
public function run(InputInterface $input = null, OutputInterface $output = null) {
- $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent(
+ $event = new ConsoleEvent(
ConsoleEvent::EVENT_RUN,
$this->request->server['argv']
- ));
+ );
+ $this->dispatcher->dispatchTyped($event);
+ $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, $event);
return $this->application->run($input, $output);
}