Skip to content

Commit c07d414

Browse files
committed
Properly cleanup entries of WebAuthn on user deletion
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
1 parent ff8cfbb commit c07d414

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

core/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use OC\Authentication\Listeners\UserDeletedFilesCleanupListener;
4040
use OC\Authentication\Listeners\UserDeletedStoreCleanupListener;
4141
use OC\Authentication\Listeners\UserDeletedTokenCleanupListener;
42+
use OC\Authentication\Listeners\UserDeletedWebAuthnCleanupListener;
4243
use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
4344
use OC\Core\Notification\CoreNotifier;
4445
use OC\DB\Connection;
@@ -273,5 +274,6 @@ function (GenericEvent $event) use ($container) {
273274
$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
274275
$eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
275276
$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
277+
$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class);
276278
}
277279
}

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@
692692
'OC\\Authentication\\Listeners\\UserDeletedFilesCleanupListener' => $baseDir . '/lib/private/Authentication/Listeners/UserDeletedFilesCleanupListener.php',
693693
'OC\\Authentication\\Listeners\\UserDeletedStoreCleanupListener' => $baseDir . '/lib/private/Authentication/Listeners/UserDeletedStoreCleanupListener.php',
694694
'OC\\Authentication\\Listeners\\UserDeletedTokenCleanupListener' => $baseDir . '/lib/private/Authentication/Listeners/UserDeletedTokenCleanupListener.php',
695+
'OC\\Authentication\\Listeners\\UserDeletedWebAuthnCleanupListener' => $baseDir . '/lib/private/Authentication/Listeners/UserDeletedWebAuthnCleanupListener.php',
695696
'OC\\Authentication\\Listeners\\UserLoggedInListener' => $baseDir . '/lib/private/Authentication/Listeners/UserLoggedInListener.php',
696697
'OC\\Authentication\\LoginCredentials\\Credentials' => $baseDir . '/lib/private/Authentication/LoginCredentials/Credentials.php',
697698
'OC\\Authentication\\LoginCredentials\\Store' => $baseDir . '/lib/private/Authentication/LoginCredentials/Store.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
721721
'OC\\Authentication\\Listeners\\UserDeletedFilesCleanupListener' => __DIR__ . '/../../..' . '/lib/private/Authentication/Listeners/UserDeletedFilesCleanupListener.php',
722722
'OC\\Authentication\\Listeners\\UserDeletedStoreCleanupListener' => __DIR__ . '/../../..' . '/lib/private/Authentication/Listeners/UserDeletedStoreCleanupListener.php',
723723
'OC\\Authentication\\Listeners\\UserDeletedTokenCleanupListener' => __DIR__ . '/../../..' . '/lib/private/Authentication/Listeners/UserDeletedTokenCleanupListener.php',
724+
'OC\\Authentication\\Listeners\\UserDeletedWebAuthnCleanupListener' => __DIR__ . '/../../..' . '/lib/private/Authentication/Listeners/UserDeletedWebAuthnCleanupListener.php',
724725
'OC\\Authentication\\Listeners\\UserLoggedInListener' => __DIR__ . '/../../..' . '/lib/private/Authentication/Listeners/UserLoggedInListener.php',
725726
'OC\\Authentication\\LoginCredentials\\Credentials' => __DIR__ . '/../../..' . '/lib/private/Authentication/LoginCredentials/Credentials.php',
726727
'OC\\Authentication\\LoginCredentials\\Store' => __DIR__ . '/../../..' . '/lib/private/Authentication/LoginCredentials/Store.php',
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2021 Morris Jobke <hey@morrisjobke.de>
7+
*
8+
* @author Morris Jobke <hey@morrisjobke.de>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OC\Authentication\Listeners;
28+
29+
use OC\Authentication\WebAuthn\Db\PublicKeyCredentialMapper;
30+
use OCP\EventDispatcher\Event;
31+
use OCP\EventDispatcher\IEventListener;
32+
use OCP\User\Events\UserDeletedEvent;
33+
34+
class UserDeletedWebAuthnCleanupListener implements IEventListener {
35+
36+
/** @var PublicKeyCredentialMapper */
37+
private $credentialMapper;
38+
39+
public function __construct(PublicKeyCredentialMapper $credentialMapper) {
40+
$this->credentialMapper = $credentialMapper;
41+
}
42+
43+
public function handle(Event $event): void {
44+
if (!($event instanceof UserDeletedEvent)) {
45+
return;
46+
}
47+
48+
$this->credentialMapper->deleteByUid($event->getUser()->getUID());
49+
}
50+
}
51+
52+

lib/private/Authentication/WebAuthn/Db/PublicKeyCredentialMapper.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,17 @@ public function findById(string $uid, int $id): PublicKeyCredentialEntity {
8484

8585
return $this->findEntity($qb);
8686
}
87+
88+
/**
89+
* @throws \OCP\DB\Exception
90+
*/
91+
public function deleteByUid(string $uid) {
92+
$qb = $this->db->getQueryBuilder();
93+
94+
$qb->delete($this->getTableName())
95+
->where(
96+
$qb->expr()->eq('uid', $qb->createNamedParameter($uid))
97+
);
98+
$qb->executeStatement();
99+
}
87100
}

0 commit comments

Comments
 (0)