diff options
Diffstat (limited to 'lib')
8 files changed, 279 insertions, 47 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 439d4c819d1..80c03a6e63a 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -509,6 +509,9 @@ return array( 'OC\\Archive\\Archive' => $baseDir . '/lib/private/Archive/Archive.php', 'OC\\Archive\\TAR' => $baseDir . '/lib/private/Archive/TAR.php', 'OC\\Archive\\ZIP' => $baseDir . '/lib/private/Archive/ZIP.php', + 'OC\\Authentication\\Events\\ARemoteWipeEvent' => $baseDir . '/lib/private/Authentication/Events/ARemoteWipeEvent.php', + 'OC\\Authentication\\Events\\RemoteWipeFinished' => $baseDir . '/lib/private/Authentication/Events/RemoteWipeFinished.php', + 'OC\\Authentication\\Events\\RemoteWipeStarted' => $baseDir . '/lib/private/Authentication/Events/RemoteWipeStarted.php', 'OC\\Authentication\\Exceptions\\ExpiredTokenException' => $baseDir . '/lib/private/Authentication/Exceptions/ExpiredTokenException.php', 'OC\\Authentication\\Exceptions\\InvalidProviderException' => $baseDir . '/lib/private/Authentication/Exceptions/InvalidProviderException.php', 'OC\\Authentication\\Exceptions\\InvalidTokenException' => $baseDir . '/lib/private/Authentication/Exceptions/InvalidTokenException.php', @@ -518,6 +521,8 @@ return array( 'OC\\Authentication\\Exceptions\\TwoFactorAuthRequiredException' => $baseDir . '/lib/private/Authentication/Exceptions/TwoFactorAuthRequiredException.php', 'OC\\Authentication\\Exceptions\\UserAlreadyLoggedInException' => $baseDir . '/lib/private/Authentication/Exceptions/UserAlreadyLoggedInException.php', 'OC\\Authentication\\Exceptions\\WipeTokenException' => $baseDir . '/lib/private/Authentication/Exceptions/WipeTokenException.php', + 'OC\\Authentication\\Listeners\\RemoteWipeActivityListener' => $baseDir . '/lib/private/Authentication/Listeners/RemoteWipeActivityListener.php', + 'OC\\Authentication\\Listeners\\RemoteWipeNotificationsListener' => $baseDir . '/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php', 'OC\\Authentication\\LoginCredentials\\Credentials' => $baseDir . '/lib/private/Authentication/LoginCredentials/Credentials.php', 'OC\\Authentication\\LoginCredentials\\Store' => $baseDir . '/lib/private/Authentication/LoginCredentials/Store.php', 'OC\\Authentication\\Login\\ALoginCommand' => $baseDir . '/lib/private/Authentication/Login/ALoginCommand.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 7cfca806c06..0eaa457464c 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -543,6 +543,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Archive\\Archive' => __DIR__ . '/../../..' . '/lib/private/Archive/Archive.php', 'OC\\Archive\\TAR' => __DIR__ . '/../../..' . '/lib/private/Archive/TAR.php', 'OC\\Archive\\ZIP' => __DIR__ . '/../../..' . '/lib/private/Archive/ZIP.php', + 'OC\\Authentication\\Events\\ARemoteWipeEvent' => __DIR__ . '/../../..' . '/lib/private/Authentication/Events/ARemoteWipeEvent.php', + 'OC\\Authentication\\Events\\RemoteWipeFinished' => __DIR__ . '/../../..' . '/lib/private/Authentication/Events/RemoteWipeFinished.php', + 'OC\\Authentication\\Events\\RemoteWipeStarted' => __DIR__ . '/../../..' . '/lib/private/Authentication/Events/RemoteWipeStarted.php', 'OC\\Authentication\\Exceptions\\ExpiredTokenException' => __DIR__ . '/../../..' . '/lib/private/Authentication/Exceptions/ExpiredTokenException.php', 'OC\\Authentication\\Exceptions\\InvalidProviderException' => __DIR__ . '/../../..' . '/lib/private/Authentication/Exceptions/InvalidProviderException.php', 'OC\\Authentication\\Exceptions\\InvalidTokenException' => __DIR__ . '/../../..' . '/lib/private/Authentication/Exceptions/InvalidTokenException.php', @@ -552,6 +555,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Authentication\\Exceptions\\TwoFactorAuthRequiredException' => __DIR__ . '/../../..' . '/lib/private/Authentication/Exceptions/TwoFactorAuthRequiredException.php', 'OC\\Authentication\\Exceptions\\UserAlreadyLoggedInException' => __DIR__ . '/../../..' . '/lib/private/Authentication/Exceptions/UserAlreadyLoggedInException.php', 'OC\\Authentication\\Exceptions\\WipeTokenException' => __DIR__ . '/../../..' . '/lib/private/Authentication/Exceptions/WipeTokenException.php', + 'OC\\Authentication\\Listeners\\RemoteWipeActivityListener' => __DIR__ . '/../../..' . '/lib/private/Authentication/Listeners/RemoteWipeActivityListener.php', + 'OC\\Authentication\\Listeners\\RemoteWipeNotificationsListener' => __DIR__ . '/../../..' . '/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php', 'OC\\Authentication\\LoginCredentials\\Credentials' => __DIR__ . '/../../..' . '/lib/private/Authentication/LoginCredentials/Credentials.php', 'OC\\Authentication\\LoginCredentials\\Store' => __DIR__ . '/../../..' . '/lib/private/Authentication/LoginCredentials/Store.php', 'OC\\Authentication\\Login\\ALoginCommand' => __DIR__ . '/../../..' . '/lib/private/Authentication/Login/ALoginCommand.php', diff --git a/lib/private/Authentication/Events/ARemoteWipeEvent.php b/lib/private/Authentication/Events/ARemoteWipeEvent.php new file mode 100644 index 00000000000..f6c08882143 --- /dev/null +++ b/lib/private/Authentication/Events/ARemoteWipeEvent.php @@ -0,0 +1,46 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @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/>. + */ + +namespace OC\Authentication\Events; + +use OC\Authentication\Token\IToken; +use OCP\EventDispatcher\Event; +use Symfony\Component\EventDispatcher\GenericEvent; + +abstract class ARemoteWipeEvent extends Event { + + /** @var IToken */ + private $token; + + public function __construct(IToken $token) { + parent::__construct(); + $this->token = $token; + } + + public function getToken(): IToken { + return $this->token; + } + +} diff --git a/lib/private/Authentication/Events/RemoteWipeFinished.php b/lib/private/Authentication/Events/RemoteWipeFinished.php new file mode 100644 index 00000000000..79f6dcbffbe --- /dev/null +++ b/lib/private/Authentication/Events/RemoteWipeFinished.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @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/>. + */ + +namespace OC\Authentication\Events; + +class RemoteWipeFinished extends ARemoteWipeEvent { + +} diff --git a/lib/private/Authentication/Events/RemoteWipeStarted.php b/lib/private/Authentication/Events/RemoteWipeStarted.php new file mode 100644 index 00000000000..f3c0b628795 --- /dev/null +++ b/lib/private/Authentication/Events/RemoteWipeStarted.php @@ -0,0 +1,30 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @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/>. + */ + +namespace OC\Authentication\Events; + +class RemoteWipeStarted extends ARemoteWipeEvent { + +} diff --git a/lib/private/Authentication/Listeners/RemoteWipeActivityListener.php b/lib/private/Authentication/Listeners/RemoteWipeActivityListener.php new file mode 100644 index 00000000000..c8cd92d2102 --- /dev/null +++ b/lib/private/Authentication/Listeners/RemoteWipeActivityListener.php @@ -0,0 +1,80 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @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/>. + */ + +namespace OC\Authentication\Listeners; + +use BadMethodCallException; +use OC\Authentication\Events\ARemoteWipeEvent; +use OC\Authentication\Events\RemoteWipeFinished; +use OC\Authentication\Events\RemoteWipeStarted; +use OC\Authentication\Token\IToken; +use OCP\Activity\IManager as IActvityManager; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\ILogger; + +class RemoteWipeActivityListener implements IEventListener { + + /** @var IActvityManager */ + private $activityManager; + + /** @var ILogger */ + private $logger; + + public function __construct(IActvityManager $activityManager, + ILogger $logger) { + $this->activityManager = $activityManager; + $this->logger = $logger; + } + + public function handle(Event $event): void { + if ($event instanceof RemoteWipeStarted) { + $this->publishActivity('remote_wipe_start', $event->getToken()); + } else if ($event instanceof RemoteWipeFinished) { + $this->publishActivity('remote_wipe_finish', $event->getToken()); + } + } + + private function publishActivity(string $event, IToken $token): void { + $activity = $this->activityManager->generateEvent(); + $activity->setApp('core') + ->setType('security') + ->setAuthor($token->getUID()) + ->setAffectedUser($token->getUID()) + ->setSubject($event, [ + 'name' => $token->getName(), + ]); + try { + $this->activityManager->publish($activity); + } catch (BadMethodCallException $e) { + $this->logger->logException($e, [ + 'app' => 'core', + 'level' => ILogger::WARN, + 'message' => 'could not publish activity', + ]); + } + } + +} diff --git a/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php b/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php new file mode 100644 index 00000000000..ffddddff1d8 --- /dev/null +++ b/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php @@ -0,0 +1,71 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @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/>. + */ + +namespace OC\Authentication\Listeners; + +use OC\Authentication\Events\ARemoteWipeEvent; +use OC\Authentication\Events\RemoteWipeFinished; +use OC\Authentication\Events\RemoteWipeStarted; +use OC\Authentication\Token\IToken; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Notification\IManager as INotificationManager; + +class RemoteWipeNotificationsListener implements IEventListener { + + /** @var INotificationManager */ + private $notificationManager; + + /** @var ITimeFactory */ + private $timeFactory; + + public function __construct(INotificationManager $notificationManager, + ITimeFactory $timeFactory) { + $this->notificationManager = $notificationManager; + $this->timeFactory = $timeFactory; + } + + public function handle(Event $event): void { + if ($event instanceof RemoteWipeStarted) { + $this->sendNotification('remote_wipe_start', $event->getToken()); + } else if ($event instanceof RemoteWipeFinished) { + $this->sendNotification('remote_wipe_finish', $event->getToken()); + } + } + + private function sendNotification(string $event, IToken $token): void { + $notification = $this->notificationManager->createNotification(); + $notification->setApp('auth') + ->setUser($token->getUID()) + ->setDateTime($this->timeFactory->getDateTime()) + ->setObject('token', $token->getId()) + ->setSubject($event, [ + 'name' => $token->getName(), + ]); + $this->notificationManager->notify($notification); + } + +} diff --git a/lib/private/Authentication/Token/RemoteWipe.php b/lib/private/Authentication/Token/RemoteWipe.php index 6091d30fc25..5534ff1cba1 100644 --- a/lib/private/Authentication/Token/RemoteWipe.php +++ b/lib/private/Authentication/Token/RemoteWipe.php @@ -26,39 +26,34 @@ declare(strict_types=1); namespace OC\Authentication\Token; use BadMethodCallException; +use OC\Authentication\Events\RemoteWipeFinished; +use OC\Authentication\Events\RemoteWipeStarted; use OC\Authentication\Exceptions\InvalidTokenException; use OC\Authentication\Exceptions\WipeTokenException; +use OCP\Activity\IEvent; use OCP\Activity\IManager as IActivityManager; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\EventDispatcher\IEventDispatcher; use OCP\ILogger; use OCP\Notification\IManager as INotificationManager; +use Symfony\Component\EventDispatcher\EventDispatcher; class RemoteWipe { /** @var IProvider */ private $tokenProvider; - /** @var IActivityManager */ - private $activityManager; - - /** @var INotificationManager */ - private $notificationManager; - - /** @var ITimeFactory */ - private $timeFactory; + /** @var IEventDispatcher */ + private $eventDispatcher; /** @var ILogger */ private $logger; public function __construct(IProvider $tokenProvider, - IActivityManager $activityManager, - INotificationManager $notificationManager, - ITimeFactory $timeFactory, + IEventDispatcher $eventDispatcher, ILogger $logger) { $this->tokenProvider = $tokenProvider; - $this->activityManager = $activityManager; - $this->notificationManager = $notificationManager; - $this->timeFactory = $timeFactory; + $this->eventDispatcher = $eventDispatcher; $this->logger = $logger; } @@ -83,8 +78,8 @@ class RemoteWipe { $dbToken = $e->getToken(); $this->logger->info("user " . $dbToken->getUID() . " started a remote wipe"); - $this->sendNotification('remote_wipe_start', $e->getToken()); - $this->publishActivity('remote_wipe_start', $e->getToken()); + + $this->eventDispatcher->dispatch(RemoteWipeStarted::class, new RemoteWipeStarted($dbToken)); return true; } @@ -111,39 +106,9 @@ class RemoteWipe { $this->tokenProvider->invalidateToken($token); $this->logger->info("user " . $dbToken->getUID() . " finished a remote wipe"); - $this->sendNotification('remote_wipe_finish', $e->getToken()); - $this->publishActivity('remote_wipe_finish', $e->getToken()); + $this->eventDispatcher->dispatch(RemoteWipeFinished::class, new RemoteWipeFinished($dbToken)); return true; } - private function publishActivity(string $event, IToken $token): void { - $activity = $this->activityManager->generateEvent(); - $activity->setApp('core') - ->setType('security') - ->setAuthor($token->getUID()) - ->setAffectedUser($token->getUID()) - ->setSubject($event, [ - 'name' => $token->getName(), - ]); - try { - $this->activityManager->publish($activity); - } catch (BadMethodCallException $e) { - $this->logger->warning('could not publish activity', ['app' => 'core']); - $this->logger->logException($e, ['app' => 'core']); - } - } - - private function sendNotification(string $event, IToken $token): void { - $notification = $this->notificationManager->createNotification(); - $notification->setApp('auth') - ->setUser($token->getUID()) - ->setDateTime($this->timeFactory->getDateTime()) - ->setObject('token', $token->getId()) - ->setSubject($event, [ - 'name' => $token->getName(), - ]); - $this->notificationManager->notify($notification); - } - } |