diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-06-09 14:33:06 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-06-16 14:38:33 +0200 |
commit | 68794ebc9292cdedaa6a52d190e41e58f6edb1ba (patch) | |
tree | 7431b26f51f615f407b000fab7ac9f68be89600e /lib/private/Authentication | |
parent | 5e52c110bb149f35ec46472a4834a5f9a25c4892 (diff) | |
download | nextcloud-server-68794ebc9292cdedaa6a52d190e41e58f6edb1ba.tar.gz nextcloud-server-68794ebc9292cdedaa6a52d190e41e58f6edb1ba.zip |
Emit an event for every disabled 2FA provider during cleanup
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/Authentication')
-rw-r--r-- | lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php | 35 | ||||
-rw-r--r-- | lib/private/Authentication/TwoFactorAuth/Registry.php | 9 |
2 files changed, 34 insertions, 10 deletions
diff --git a/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php b/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php index 02e6863d1c4..bd8ff0353ee 100644 --- a/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php +++ b/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php @@ -29,6 +29,7 @@ namespace OC\Authentication\TwoFactorAuth\Db; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; +use function array_map; /** * Data access object to query and assign (provider_id, uid, enabled) tuples of @@ -91,13 +92,35 @@ class ProviderUserAssignmentDao { } } - public function deleteByUser(string $uid) { - $qb = $this->conn->getQueryBuilder(); - - $deleteQuery = $qb->delete(self::TABLE_NAME) - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))); - + /** + * Delete all provider states of a user and return the provider IDs + * + * @param string $uid + * + * @return int[] + */ + public function deleteByUser(string $uid): array { + $qb1 = $this->conn->getQueryBuilder(); + $selectQuery = $qb1->select('*') + ->from(self::TABLE_NAME) + ->where($qb1->expr()->eq('uid', $qb1->createNamedParameter($uid))); + $selectResult = $selectQuery->execute(); + $rows = $selectResult->fetchAll(); + $selectResult->closeCursor(); + + $qb2 = $this->conn->getQueryBuilder(); + $deleteQuery = $qb2 + ->delete(self::TABLE_NAME) + ->where($qb2->expr()->eq('uid', $qb2->createNamedParameter($uid))); $deleteQuery->execute(); + + return array_map(function (array $row) { + return [ + 'provider_id' => $row['provider_id'], + 'uid' => $row['uid'], + 'enabled' => 1 === (int) $row['enabled'], + ]; + }, $rows); } public function deleteAll(string $providerId) { diff --git a/lib/private/Authentication/TwoFactorAuth/Registry.php b/lib/private/Authentication/TwoFactorAuth/Registry.php index 97df2bd5311..2af8566d3e5 100644 --- a/lib/private/Authentication/TwoFactorAuth/Registry.php +++ b/lib/private/Authentication/TwoFactorAuth/Registry.php @@ -31,6 +31,7 @@ use OC\Authentication\TwoFactorAuth\Db\ProviderUserAssignmentDao; use OCP\Authentication\TwoFactorAuth\IProvider; use OCP\Authentication\TwoFactorAuth\IRegistry; use OCP\Authentication\TwoFactorAuth\RegistryEvent; +use OCP\Authentication\TwoFactorAuth\TwoFactorProviderDisabled; use OCP\EventDispatcher\IEventDispatcher; use OCP\IUser; @@ -66,11 +67,11 @@ class Registry implements IRegistry { $this->dispatcher->dispatch(self::EVENT_PROVIDER_DISABLED, $event); } - /** - * @todo evaluate if we should emit RegistryEvents for each of the deleted rows -> needs documentation - */ public function deleteUserData(IUser $user): void { - $this->assignmentDao->deleteByUser($user->getUID()); + foreach ($this->assignmentDao->deleteByUser($user->getUID()) as $provider) { + $event = new TwoFactorProviderDisabled($provider['provider_id']); + $this->dispatcher->dispatchTyped($event); + } } public function cleanUp(string $providerId) { |