aboutsummaryrefslogtreecommitdiffstats
path: root/settings
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-02-19 15:08:43 +0100
committerGitHub <noreply@github.com>2019-02-19 15:08:43 +0100
commite7f0e8ba03363f37631ded3099d4e2bf0df5d5f6 (patch)
treea0cf0ccc828d472696304f44e8c4356ead2cec79 /settings
parenta70099ef10b9f7452443d79519da0aafe2f19d6f (diff)
parentc583c5e7e2608c3a5a1f5d15f750b7f3f57c6c93 (diff)
downloadnextcloud-server-e7f0e8ba03363f37631ded3099d4e2bf0df5d5f6.tar.gz
nextcloud-server-e7f0e8ba03363f37631ded3099d4e2bf0df5d5f6.zip
Merge pull request #14263 from nextcloud/publish-activity-app-token
Publish activity if app password created by ocs api or client login flow
Diffstat (limited to 'settings')
-rw-r--r--settings/Application.php31
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() {