2019-05-28 18:56:01 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-05-28 18:56:01 +03:00
|
|
|
*
|
|
|
|
* @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
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2019-05-28 18:56:01 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Authentication\Listeners;
|
|
|
|
|
|
|
|
use BadMethodCallException;
|
|
|
|
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;
|
2020-10-12 18:14:25 +03:00
|
|
|
use Psr\Log\LoggerInterface;
|
2019-05-28 18:56:01 +03:00
|
|
|
|
2020-10-15 17:43:21 +03:00
|
|
|
/**
|
|
|
|
* @template-implements IEventListener<\OC\Authentication\Events\ARemoteWipeEvent>
|
|
|
|
*/
|
2019-05-28 18:56:01 +03:00
|
|
|
class RemoteWipeActivityListener implements IEventListener {
|
|
|
|
|
|
|
|
/** @var IActvityManager */
|
|
|
|
private $activityManager;
|
|
|
|
|
2020-10-12 18:14:25 +03:00
|
|
|
/** @var LoggerInterface */
|
2019-05-28 18:56:01 +03:00
|
|
|
private $logger;
|
|
|
|
|
|
|
|
public function __construct(IActvityManager $activityManager,
|
2020-10-12 18:14:25 +03:00
|
|
|
LoggerInterface $logger) {
|
2019-05-28 18:56:01 +03:00
|
|
|
$this->activityManager = $activityManager;
|
|
|
|
$this->logger = $logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle(Event $event): void {
|
|
|
|
if ($event instanceof RemoteWipeStarted) {
|
|
|
|
$this->publishActivity('remote_wipe_start', $event->getToken());
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($event instanceof RemoteWipeFinished) {
|
2019-05-28 18:56:01 +03:00
|
|
|
$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) {
|
2020-10-12 18:14:25 +03:00
|
|
|
$this->logger->warning('could not publish activity', [
|
2019-05-28 18:56:01 +03:00
|
|
|
'app' => 'core',
|
2020-10-12 18:14:25 +03:00
|
|
|
'exception' => $e,
|
2019-05-28 18:56:01 +03:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|