diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2019-02-18 17:38:38 +0100 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2019-02-18 17:47:43 +0100 |
commit | c583c5e7e2608c3a5a1f5d15f750b7f3f57c6c93 (patch) | |
tree | 45f28d5df2dbf56d11aa75f96a3b82c2a7fe40e4 /settings | |
parent | 149a98edf69558ade2176467fd1d78919ee0b8c7 (diff) | |
download | nextcloud-server-c583c5e7e2608c3a5a1f5d15f750b7f3f57c6c93.tar.gz nextcloud-server-c583c5e7e2608c3a5a1f5d15f750b7f3f57c6c93.zip |
Emit event if app password created
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'settings')
-rw-r--r-- | settings/Application.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/settings/Application.php b/settings/Application.php index 4a144082427..111cb6a6e0b 100644 --- a/settings/Application.php +++ b/settings/Application.php @@ -28,8 +28,10 @@ namespace OC\Settings; +use BadMethodCallException; use OC\AppFramework\Utility\TimeFactory; use OC\Authentication\Token\IProvider; +use OC\Authentication\Token\IToken; use OC\Server; use OC\Settings\Activity\Provider; use OC\Settings\Activity\SecurityFilter; @@ -38,11 +40,15 @@ use OC\Settings\Activity\SecuritySetting; use OC\Settings\Activity\Setting; use OC\Settings\Mailer\NewUserMailHelper; use OC\Settings\Middleware\SubadminMiddleware; +use OCP\Activity\IManager as IActivityManager; use OCP\AppFramework\App; use OCP\Defaults; use OCP\IContainer; +use OCP\ILogger; use OCP\Settings\IManager; use OCP\Util; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; /** * @package OC\Settings @@ -109,6 +115,31 @@ class Application extends App { Util::getDefaultEmailAddress('no-reply') ); }); + + /** @var EventDispatcherInterface $eventDispatcher */ + $eventDispatcher = $container->getServer()->getEventDispatcher(); + $eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { + if (($token = $event->getSubject()) instanceof IToken) { + /** @var IActivityManager $activityManager */ + $activityManager = $container->query(IActivityManager::class); + /** @var ILogger $logger */ + $logger = $container->query(ILogger::class); + + $activity = $activityManager->generateEvent(); + $activity->setApp('settings') + ->setType('security') + ->setAffectedUser($token->getUID()) + ->setAuthor($token->getUID()) + ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()]) + ->setObject('app_token', $token->getId()); + + try { + $activityManager->publish($activity); + } catch (BadMethodCallException $e) { + $logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]); + } + } + }); } public function register() { |