From 7bd273f7502c04ec517da531debab04fb204e0a9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 10 Mar 2022 15:25:22 +0100 Subject: Trigger an event to log an activity when an administrator generates an app password Signed-off-by: Joas Schilling --- core/Command/User/AddAppPassword.php | 17 +++++++++++------ core/register_command.php | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/Command/User/AddAppPassword.php b/core/Command/User/AddAppPassword.php index a29692df045..34c8dc67ccc 100644 --- a/core/Command/User/AddAppPassword.php +++ b/core/Command/User/AddAppPassword.php @@ -23,10 +23,11 @@ */ namespace OC\Core\Command\User; +use OC\Authentication\Events\AppPasswordCreatedEvent; use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IToken; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IUserManager; -use OCP\Security\ICrypto; use OCP\Security\ISecureRandom; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\QuestionHelper; @@ -44,17 +45,17 @@ class AddAppPassword extends Command { protected $tokenProvider; /** @var ISecureRandom */ private $random; - /** @var ICrypto */ - private $crypto; + /** @var IEventDispatcher */ + private $eventDispatcher; public function __construct(IUserManager $userManager, IProvider $tokenProvider, ISecureRandom $random, - ICrypto $crypto) { + IEventDispatcher $eventDispatcher) { $this->tokenProvider = $tokenProvider; $this->userManager = $userManager; $this->random = $random; - $this->crypto = $crypto; + $this->eventDispatcher = $eventDispatcher; parent::__construct(); } @@ -112,7 +113,7 @@ class AddAppPassword extends Command { $token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS); - $this->tokenProvider->generateToken( + $generatedToken = $this->tokenProvider->generateToken( $token, $user->getUID(), $user->getUID(), @@ -122,6 +123,10 @@ class AddAppPassword extends Command { IToken::DO_NOT_REMEMBER ); + $this->eventDispatcher->dispatchTyped( + new AppPasswordCreatedEvent($generatedToken) + ); + $output->writeln('app password:'); $output->writeln($token); diff --git a/core/register_command.php b/core/register_command.php index 3cff363e46f..7385de64b5d 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -187,7 +187,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) { $application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig(), \OC::$server->getDatabaseConnection())); $application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); $application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); - $application->add(new OC\Core\Command\User\AddAppPassword(\OC::$server->get(\OCP\IUserManager::class), \OC::$server->get(\OC\Authentication\Token\IProvider::class), \OC::$server->get(\OCP\Security\ISecureRandom::class), \OC::$server->get(\OCP\Security\ICrypto::class))); + $application->add(new OC\Core\Command\User\AddAppPassword(\OC::$server->get(\OCP\IUserManager::class), \OC::$server->get(\OC\Authentication\Token\IProvider::class), \OC::$server->get(\OCP\Security\ISecureRandom::class), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class))); $application->add(new OC\Core\Command\Group\Add(\OC::$server->getGroupManager())); $application->add(new OC\Core\Command\Group\Delete(\OC::$server->getGroupManager())); -- cgit v1.2.3