From 0928b5f621c42b2675fd877417e02dfc18b4e82b Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Tue, 16 May 2017 09:37:21 +0200 Subject: [PATCH] Change 2FA activities to more generic security activities Signed-off-by: Christoph Wurst --- apps/twofactor_backupcodes/appinfo/info.xml | 7 ------- lib/private/Authentication/TwoFactorAuth/Manager.php | 11 ++++++----- .../Activity/SecurityFilter.php | 10 +++++----- .../Activity/SecurityProvider.php | 6 +++--- .../Activity/SecuritySetting.php | 8 ++++---- settings/Application.php | 6 ++++++ 6 files changed, 24 insertions(+), 24 deletions(-) rename apps/twofactor_backupcodes/lib/Activity/GenericFilter.php => settings/Activity/SecurityFilter.php (87%) rename apps/twofactor_backupcodes/lib/Activity/GenericProvider.php => settings/Activity/SecurityProvider.php (94%) rename apps/twofactor_backupcodes/lib/Activity/GenericSetting.php => settings/Activity/SecuritySetting.php (88%) diff --git a/apps/twofactor_backupcodes/appinfo/info.xml b/apps/twofactor_backupcodes/appinfo/info.xml index e5e96eddcf9..77ecbd8e1a2 100644 --- a/apps/twofactor_backupcodes/appinfo/info.xml +++ b/apps/twofactor_backupcodes/appinfo/info.xml @@ -18,14 +18,7 @@ - - OCA\TwoFactorBackupCodes\Activity\GenericFilter - - - OCA\TwoFactorBackupCodes\Activity\GenericSetting - - OCA\TwoFactorBackupCodes\Activity\GenericProvider OCA\TwoFactorBackupCodes\Activity\Provider diff --git a/lib/private/Authentication/TwoFactorAuth/Manager.php b/lib/private/Authentication/TwoFactorAuth/Manager.php index 1d0deada696..06aa0224ae0 100644 --- a/lib/private/Authentication/TwoFactorAuth/Manager.php +++ b/lib/private/Authentication/TwoFactorAuth/Manager.php @@ -23,6 +23,7 @@ namespace OC\Authentication\TwoFactorAuth; +use BadMethodCallException; use Exception; use OC; use OC\App\AppManager; @@ -218,16 +219,16 @@ class Manager { */ private function publishEvent(IUser $user, $event, array $params) { $activity = $this->activityManager->generateEvent(); - $activity->setApp('twofactor_generic') - ->setType('twofactor') + $activity->setApp('core') + ->setType('security') ->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']); + } catch (BadMethodCallException $e) { + $this->logger->warning('could not publish backup code creation activity', ['app' => 'core']); + $this->logger->logException($e, ['app' => 'core']); } } diff --git a/apps/twofactor_backupcodes/lib/Activity/GenericFilter.php b/settings/Activity/SecurityFilter.php similarity index 87% rename from apps/twofactor_backupcodes/lib/Activity/GenericFilter.php rename to settings/Activity/SecurityFilter.php index 27c0274b600..6bf36a9e488 100644 --- a/apps/twofactor_backupcodes/lib/Activity/GenericFilter.php +++ b/settings/Activity/SecurityFilter.php @@ -20,13 +20,13 @@ * */ -namespace OCA\TwoFactorBackupCodes\Activity; +namespace OC\Settings\Activity; use OCP\Activity\IFilter; use OCP\IL10N; use OCP\IURLGenerator; -class GenericFilter implements IFilter { +class SecurityFilter implements IFilter { /** @var IURLGenerator */ private $urlGenerator; @@ -44,7 +44,7 @@ class GenericFilter implements IFilter { } public function filterTypes(array $types) { - return array_intersect(['twofactor'], $types); + return array_intersect(['security'], $types); } public function getIcon() { @@ -52,11 +52,11 @@ class GenericFilter implements IFilter { } public function getIdentifier() { - return 'twofactor'; + return 'security'; } public function getName() { - return $this->l10n->t('Two-factor authentication'); + return $this->l10n->t('Security'); } public function getPriority() { diff --git a/apps/twofactor_backupcodes/lib/Activity/GenericProvider.php b/settings/Activity/SecurityProvider.php similarity index 94% rename from apps/twofactor_backupcodes/lib/Activity/GenericProvider.php rename to settings/Activity/SecurityProvider.php index ffdd47708d5..74747f684da 100644 --- a/apps/twofactor_backupcodes/lib/Activity/GenericProvider.php +++ b/settings/Activity/SecurityProvider.php @@ -20,7 +20,7 @@ * */ -namespace OCA\TwoFactorBackupCodes\Activity; +namespace OC\Settings\Activity; use InvalidArgumentException; use OCP\Activity\IEvent; @@ -29,7 +29,7 @@ use OCP\ILogger; use OCP\IURLGenerator; use OCP\L10N\IFactory as L10nFactory; -class GenericProvider implements IProvider { +class SecurityProvider implements IProvider { /** @var L10nFactory */ private $l10n; @@ -47,7 +47,7 @@ class GenericProvider implements IProvider { } public function parse($language, IEvent $event, IEvent $previousEvent = null) { - if ($event->getType() !== 'twofactor') { + if ($event->getType() !== 'security') { throw new InvalidArgumentException(); } diff --git a/apps/twofactor_backupcodes/lib/Activity/GenericSetting.php b/settings/Activity/SecuritySetting.php similarity index 88% rename from apps/twofactor_backupcodes/lib/Activity/GenericSetting.php rename to settings/Activity/SecuritySetting.php index abd1c60f1d5..fe1b0dd8f57 100644 --- a/apps/twofactor_backupcodes/lib/Activity/GenericSetting.php +++ b/settings/Activity/SecuritySetting.php @@ -20,12 +20,12 @@ * */ -namespace OCA\TwoFactorBackupCodes\Activity; +namespace OC\Settings\Activity; use OCP\Activity\ISetting; use OCP\IL10N; -class GenericSetting implements ISetting { +class SecuritySetting implements ISetting { /** @var IL10N */ private $l10n; @@ -43,11 +43,11 @@ class GenericSetting implements ISetting { } public function getIdentifier() { - return 'twofactor'; + return 'security'; } public function getName() { - return $this->l10n->t('Two-factor authentication'); + return $this->l10n->t('Security'); } public function getPriority() { diff --git a/settings/Application.php b/settings/Application.php index 0ca2d28dfe6..f79453e3d01 100644 --- a/settings/Application.php +++ b/settings/Application.php @@ -34,6 +34,9 @@ use OC\AppFramework\Utility\TimeFactory; use OC\Authentication\Token\IProvider; use OC\Server; use OC\Settings\Activity\Provider; +use OC\Settings\Activity\SecurityFilter; +use OC\Settings\Activity\SecurityProvider; +use OC\Settings\Activity\SecuritySetting; use OC\Settings\Activity\Setting; use OC\Settings\Mailer\NewUserMailHelper; use OC\Settings\Middleware\SubadminMiddleware; @@ -114,6 +117,9 @@ class Application extends App { $activityManager = $this->getContainer()->getServer()->getActivityManager(); $activityManager->registerSetting(Setting::class); // FIXME move to info.xml $activityManager->registerProvider(Provider::class); // FIXME move to info.xml + $activityManager->registerFilter(SecurityFilter::class); // FIXME move to info.xml + $activityManager->registerSetting(SecuritySetting::class); // FIXME move to info.xml + $activityManager->registerProvider(SecurityProvider::class); // FIXME move to info.xml Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); -- 2.39.5