summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2016-12-13 10:30:08 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2016-12-19 11:59:47 +0100
commit7ae9442f3d4cdb2a98ae680979d6fcb33350cc02 (patch)
treec534d9020a1b62dcc4999d4315a24ac4b9c2087b /lib
parent9b71ee27ff95336c36d608217d9621110e6674c1 (diff)
downloadnextcloud-server-7ae9442f3d4cdb2a98ae680979d6fcb33350cc02.tar.gz
nextcloud-server-7ae9442f3d4cdb2a98ae680979d6fcb33350cc02.zip
Publish, parse and filter 2FA activities
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Authentication/TwoFactorAuth/Manager.php32
-rw-r--r--lib/private/Server.php2
2 files changed, 32 insertions, 2 deletions
diff --git a/lib/private/Authentication/TwoFactorAuth/Manager.php b/lib/private/Authentication/TwoFactorAuth/Manager.php
index 48792aa685b..297e69fac99 100644
--- a/lib/private/Authentication/TwoFactorAuth/Manager.php
+++ b/lib/private/Authentication/TwoFactorAuth/Manager.php
@@ -1,4 +1,5 @@
<?php
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -26,6 +27,7 @@ use Exception;
use OC;
use OC\App\AppManager;
use OC_App;
+use OCP\Activity\IManager;
use OCP\AppFramework\QueryException;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\IConfig;
@@ -48,15 +50,19 @@ class Manager {
/** @var IConfig */
private $config;
+ /** @var IManager */
+ private $activityManager;
+
/**
* @param AppManager $appManager
* @param ISession $session
* @param IConfig $config
*/
- public function __construct(AppManager $appManager, ISession $session, IConfig $config) {
+ public function __construct(AppManager $appManager, ISession $session, IConfig $config, IManager $activityManager) {
$this->appManager = $appManager;
$this->session = $session;
$this->config = $config;
+ $this->activityManager = $activityManager;
}
/**
@@ -184,11 +190,35 @@ class Manager {
}
$this->session->remove(self::SESSION_UID_KEY);
$this->session->remove(self::REMEMBER_LOGIN);
+
+ $this->publishEvent($user, 'twofactor_success', [
+ 'provider' => $provider->getDisplayName(),
+ ]);
+ } else {
+ $this->publishEvent($user, 'twofactor_failed', [
+ 'provider' => $provider->getDisplayName(),
+ ]);
}
return $passed;
}
/**
+ * Push a 2fa event the user's activity stream
+ *
+ * @param IUser $user
+ * @param string $event
+ */
+ private function publishEvent(IUser $user, $event, array $params) {
+ $activity = $this->activityManager->generateEvent();
+ $activity->setApp('twofactor_generic')
+ ->setType('twofactor_generic')
+ ->setAuthor($user->getUID())
+ ->setAffectedUser($user->getUID());
+ $activity->setSubject($event, $params);
+ $this->activityManager->publish($activity);
+ }
+
+ /**
* Check if the currently logged in user needs to pass 2FA
*
* @param IUser $user the currently logged in user
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 969e5a25b9b..d51ae7d8655 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -312,7 +312,7 @@ class Server extends ServerContainer implements IServerContainer {
});
$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
- return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig());
+ return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager());
});
$this->registerService('NavigationManager', function ($c) {