You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RemoteWipeActivityListener.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\Authentication\Listeners;
  26. use BadMethodCallException;
  27. use OC\Authentication\Events\RemoteWipeFinished;
  28. use OC\Authentication\Events\RemoteWipeStarted;
  29. use OC\Authentication\Token\IToken;
  30. use OCP\Activity\IManager as IActvityManager;
  31. use OCP\EventDispatcher\Event;
  32. use OCP\EventDispatcher\IEventListener;
  33. use Psr\Log\LoggerInterface;
  34. /**
  35. * @template-implements IEventListener<\OC\Authentication\Events\ARemoteWipeEvent>
  36. */
  37. class RemoteWipeActivityListener implements IEventListener {
  38. /** @var IActvityManager */
  39. private $activityManager;
  40. /** @var LoggerInterface */
  41. private $logger;
  42. public function __construct(IActvityManager $activityManager,
  43. LoggerInterface $logger) {
  44. $this->activityManager = $activityManager;
  45. $this->logger = $logger;
  46. }
  47. public function handle(Event $event): void {
  48. if ($event instanceof RemoteWipeStarted) {
  49. $this->publishActivity('remote_wipe_start', $event->getToken());
  50. } elseif ($event instanceof RemoteWipeFinished) {
  51. $this->publishActivity('remote_wipe_finish', $event->getToken());
  52. }
  53. }
  54. private function publishActivity(string $event, IToken $token): void {
  55. $activity = $this->activityManager->generateEvent();
  56. $activity->setApp('core')
  57. ->setType('security')
  58. ->setAuthor($token->getUID())
  59. ->setAffectedUser($token->getUID())
  60. ->setSubject($event, [
  61. 'name' => $token->getName(),
  62. ]);
  63. try {
  64. $this->activityManager->publish($activity);
  65. } catch (BadMethodCallException $e) {
  66. $this->logger->warning('could not publish activity', [
  67. 'app' => 'core',
  68. 'exception' => $e,
  69. ]);
  70. }
  71. }
  72. }