summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php6
-rw-r--r--lib/composer/composer/autoload_static.php6
-rw-r--r--lib/private/Authentication/Events/ARemoteWipeEvent.php46
-rw-r--r--lib/private/Authentication/Events/RemoteWipeFinished.php30
-rw-r--r--lib/private/Authentication/Events/RemoteWipeStarted.php30
-rw-r--r--lib/private/Authentication/Listeners/RemoteWipeActivityListener.php80
-rw-r--r--lib/private/Authentication/Listeners/RemoteWipeEmailListener.php171
-rw-r--r--lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php71
-rw-r--r--lib/private/Authentication/Token/RemoteWipe.php59
-rw-r--r--lib/private/Comments/Manager.php22
10 files changed, 468 insertions, 53 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 439d4c819d1..f608ce0b77c 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,9 @@ 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\\RemoteWipeEmailListener' => $baseDir . '/lib/private/Authentication/Listeners/RemoteWipeEmailListener.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..fc4fc585e60 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,9 @@ 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\\RemoteWipeEmailListener' => __DIR__ . '/../../..' . '/lib/private/Authentication/Listeners/RemoteWipeEmailListener.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/RemoteWipeEmailListener.php b/lib/private/Authentication/Listeners/RemoteWipeEmailListener.php
new file mode 100644
index 00000000000..be431747389
--- /dev/null
+++ b/lib/private/Authentication/Listeners/RemoteWipeEmailListener.php
@@ -0,0 +1,171 @@
+<?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 Exception;
+use OC\Authentication\Events\RemoteWipeFinished;
+use OC\Authentication\Events\RemoteWipeStarted;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\IL10N;
+use OCP\ILogger;
+use OCP\IUser;
+use OCP\IUserManager;
+use OCP\L10N\IFactory as IL10nFactory;
+use OCP\Mail\IMailer;
+use OCP\Mail\IMessage;
+use function substr;
+
+class RemoteWipeEmailListener implements IEventListener {
+
+ /** @var IMailer */
+ private $mailer;
+
+ /** @var IUserManager */
+ private $userManager;
+
+ /** @var IL10N */
+ private $l10n;
+
+ /** @var ILogger */
+ private $logger;
+
+ public function __construct(IMailer $mailer,
+ IUserManager $userManager,
+ IL10nFactory $l10nFactory,
+ ILogger $logger) {
+ $this->mailer = $mailer;
+ $this->userManager = $userManager;
+ $this->l10n = $l10nFactory->get('core');
+ $this->logger = $logger;
+ }
+
+ /**
+ * @param Event $event
+ */
+ public function handle(Event $event): void {
+ if ($event instanceof RemoteWipeStarted) {
+ $uid = $event->getToken()->getUID();
+ $user = $this->userManager->get($uid);
+ if ($user === null) {
+ $this->logger->warning("not sending a wipe started email because user <$uid> does not exist (anymore)");
+ return;
+ }
+ if ($user->getEMailAddress() === null) {
+ $this->logger->info("not sending a wipe started email because user <$uid> has no email set");
+ return;
+ }
+
+ try {
+ $this->mailer->send(
+ $this->getWipingStartedMessage($event, $user)
+ );
+ } catch (Exception $e) {
+ $this->logger->logException($e, [
+ 'message' => "Could not send remote wipe started email to <$uid>",
+ 'level' => ILogger::ERROR,
+ ]);
+ }
+ } else if ($event instanceof RemoteWipeFinished) {
+ $uid = $event->getToken()->getUID();
+ $user = $this->userManager->get($uid);
+ if ($user === null) {
+ $this->logger->warning("not sending a wipe finished email because user <$uid> does not exist (anymore)");
+ return;
+ }
+ if ($user->getEMailAddress() === null) {
+ $this->logger->info("not sending a wipe finished email because user <$uid> has no email set");
+ return;
+ }
+
+ try {
+ $this->mailer->send(
+ $this->getWipingFinishedMessage($event, $user)
+ );
+ } catch (Exception $e) {
+ $this->logger->logException($e, [
+ 'message' => "Could not send remote wipe finished email to <$uid>",
+ 'level' => ILogger::ERROR,
+ ]);
+ }
+ }
+ }
+
+ private function getWipingStartedMessage(RemoteWipeStarted $event, IUser $user): IMessage {
+ $message = $this->mailer->createMessage();
+ $emailTemplate = $this->mailer->createEMailTemplate('auth.RemoteWipeStarted');
+ $plainHeading = $this->l10n->t('Wiping of device %s has started', [$event->getToken()->getName()]);
+ $htmlHeading = $this->l10n->t('Wiping of device »%s« has started', [$event->getToken()->getName()]);
+ $emailTemplate->setSubject(
+ $this->l10n->t(
+ '»%s« started remote wipe',
+ [
+ substr($event->getToken()->getName(), 0, 15)
+ ]
+ )
+ );
+ $emailTemplate->addHeader();
+ $emailTemplate->addHeading(
+ $htmlHeading,
+ $plainHeading
+ );
+ $emailTemplate->addBodyText(
+ $this->l10n->t('Device or application »%s« has started the remote wipe process. You will receive another email once the process has finished', [$event->getToken()->getName()])
+ );
+ $emailTemplate->addFooter();
+ $message->setTo([$user->getEMailAddress()]);
+ $message->useTemplate($emailTemplate);
+
+ return $message;
+ }
+
+ private function getWipingFinishedMessage(RemoteWipeFinished $event, IUser $user): IMessage {
+ $message = $this->mailer->createMessage();
+ $emailTemplate = $this->mailer->createEMailTemplate('auth.RemoteWipeFinished');
+ $plainHeading = $this->l10n->t('Wiping of device %s has finished', [$event->getToken()->getName()]);
+ $htmlHeading = $this->l10n->t('Wiping of device »%s« has finished', [$event->getToken()->getName()]);
+ $emailTemplate->setSubject(
+ $this->l10n->t(
+ '»%s« finished remote wipe',
+ [
+ substr($event->getToken()->getName(), 0, 15)
+ ]
+ )
+ );
+ $emailTemplate->addHeader();
+ $emailTemplate->addHeading(
+ $htmlHeading,
+ $plainHeading
+ );
+ $emailTemplate->addBodyText(
+ $this->l10n->t('Device or application »%s« has finished the remote wipe process.', [$event->getToken()->getName()])
+ );
+ $emailTemplate->addFooter();
+ $message->setTo([$user->getEMailAddress()]);
+ $message->useTemplate($emailTemplate);
+
+ return $message;
+ }
+
+}
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);
- }
-
}
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php
index 8df4a84a477..309b682767b 100644
--- a/lib/private/Comments/Manager.php
+++ b/lib/private/Comments/Manager.php
@@ -98,6 +98,15 @@ class Manager implements ICommentsManager {
return $data;
}
+
+ /**
+ * @param array $data
+ * @return IComment
+ */
+ public function getCommentFromData(array $data): IComment {
+ return new Comment($this->normalizeDatabaseData($data));
+ }
+
/**
* prepares a comment for an insert or update operation after making sure
* all necessary fields have a value assigned.
@@ -253,7 +262,8 @@ class Manager implements ICommentsManager {
throw new NotFoundException();
}
- $comment = new Comment($this->normalizeDatabaseData($data));
+
+ $comment = $this->getCommentFromData($data);
$this->cache($comment);
return $comment;
}
@@ -308,7 +318,7 @@ class Manager implements ICommentsManager {
$resultStatement = $query->execute();
while ($data = $resultStatement->fetch()) {
- $comment = new Comment($this->normalizeDatabaseData($data));
+ $comment = $this->getCommentFromData($data);
$this->cache($comment);
$tree['replies'][] = [
'comment' => $comment,
@@ -367,7 +377,7 @@ class Manager implements ICommentsManager {
$resultStatement = $query->execute();
while ($data = $resultStatement->fetch()) {
- $comment = new Comment($this->normalizeDatabaseData($data));
+ $comment = $this->getCommentFromData($data);
$this->cache($comment);
$comments[] = $comment;
}
@@ -455,7 +465,7 @@ class Manager implements ICommentsManager {
$resultStatement = $query->execute();
while ($data = $resultStatement->fetch()) {
- $comment = new Comment($this->normalizeDatabaseData($data));
+ $comment = $this->getCommentFromData($data);
$this->cache($comment);
$comments[] = $comment;
}
@@ -485,7 +495,7 @@ class Manager implements ICommentsManager {
$result->closeCursor();
if ($row) {
- $comment = new Comment($this->normalizeDatabaseData($row));
+ $comment = $this->getCommentFromData($row);
$this->cache($comment);
return $comment;
}
@@ -532,7 +542,7 @@ class Manager implements ICommentsManager {
$comments = [];
$result = $query->execute();
while ($data = $result->fetch()) {
- $comment = new Comment($this->normalizeDatabaseData($data));
+ $comment = $this->getCommentFromData($data);
$this->cache($comment);
$comments[] = $comment;
}