diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-12-22 14:47:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-22 14:47:15 +0100 |
commit | bb8b647bd6bcd8a51d6b0e020d5a1f7d00498d3c (patch) | |
tree | 1b2e5e0f65ca18e9b91f27e6de7ac0d2f9242bb3 /lib/private | |
parent | 6789685c4e041af2a3faa181de3875f2c3e36505 (diff) | |
parent | 88b7d033dfca053e5a726f04c96c312092671245 (diff) | |
download | nextcloud-server-bb8b647bd6bcd8a51d6b0e020d5a1f7d00498d3c.tar.gz nextcloud-server-bb8b647bd6bcd8a51d6b0e020d5a1f7d00498d3c.zip |
Merge pull request #2633 from nextcloud/2fa-activities
two-factor activities
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Authentication/TwoFactorAuth/Manager.php | 45 | ||||
-rw-r--r-- | lib/private/Server.php | 2 |
2 files changed, 45 insertions, 2 deletions
diff --git a/lib/private/Authentication/TwoFactorAuth/Manager.php b/lib/private/Authentication/TwoFactorAuth/Manager.php index 48792aa685b..1d0deada696 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,9 +27,11 @@ 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; +use OCP\ILogger; use OCP\ISession; use OCP\IUser; @@ -48,15 +51,26 @@ class Manager { /** @var IConfig */ private $config; + /** @var IManager */ + private $activityManager; + + /** @var ILogger */ + private $logger; + /** * @param AppManager $appManager * @param ISession $session * @param IConfig $config + * @param IManager $activityManager + * @param ILogger $logger */ - public function __construct(AppManager $appManager, ISession $session, IConfig $config) { + public function __construct(AppManager $appManager, ISession $session, IConfig $config, IManager $activityManager, + ILogger $logger) { $this->appManager = $appManager; $this->session = $session; $this->config = $config; + $this->activityManager = $activityManager; + $this->logger = $logger; } /** @@ -184,11 +198,40 @@ 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') + ->setAuthor($user->getUID()) + ->setAffectedUser($user->getUID()) + ->setSubject($event, $params); + try { + $this->activityManager->publish($activity); + } catch (Exception $e) { + $this->logger->warning('could not publish backup code creation activity', ['app' => 'twofactor_backupcodes']); + $this->logger->logException($e, ['app' => 'twofactor_backupcodes']); + } + } + + /** * 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..6f4d4f066e7 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(), $c->getLogger()); }); $this->registerService('NavigationManager', function ($c) { |