1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @copyright Copyright (c) 2020, Roeland Jago Douma <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @author Christoph Wurst <[email protected]> |
9
|
|
|
* @author Roeland Jago Douma <[email protected]> |
10
|
|
|
* |
11
|
|
|
* @license GNU AGPL version 3 or any later version |
12
|
|
|
* |
13
|
|
|
* This program is free software: you can redistribute it and/or modify |
14
|
|
|
* it under the terms of the GNU Affero General Public License as |
15
|
|
|
* published by the Free Software Foundation, either version 3 of the |
16
|
|
|
* License, or (at your option) any later version. |
17
|
|
|
* |
18
|
|
|
* This program is distributed in the hope that it will be useful, |
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21
|
|
|
* GNU Affero General Public License for more details. |
22
|
|
|
* |
23
|
|
|
* You should have received a copy of the GNU Affero General Public License |
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
|
|
namespace OC\Authentication\WebAuthn\Db; |
28
|
|
|
|
29
|
|
|
use OCP\AppFramework\Db\DoesNotExistException; |
30
|
|
|
use OCP\AppFramework\Db\QBMapper; |
31
|
|
|
use OCP\IDBConnection; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @template-extends QBMapper<PublicKeyCredentialEntity> |
35
|
|
|
*/ |
36
|
|
|
class PublicKeyCredentialMapper extends QBMapper { |
37
|
|
|
public function __construct(IDBConnection $db) { |
38
|
|
|
parent::__construct($db, 'webauthn', PublicKeyCredentialEntity::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function findOneByCredentialId(string $publicKeyCredentialId): PublicKeyCredentialEntity { |
42
|
|
|
$qb = $this->db->getQueryBuilder(); |
43
|
|
|
|
44
|
|
|
$qb->select('*') |
45
|
|
|
->from($this->getTableName()) |
46
|
|
|
->where( |
47
|
|
|
$qb->expr()->eq('public_key_credential_id', $qb->createNamedParameter(base64_encode($publicKeyCredentialId))) |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
return $this->findEntity($qb); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return PublicKeyCredentialEntity[] |
55
|
|
|
*/ |
56
|
|
|
public function findAllForUid(string $uid): array { |
57
|
|
|
$qb = $this->db->getQueryBuilder(); |
58
|
|
|
|
59
|
|
|
$qb->select('*') |
60
|
|
|
->from($this->getTableName()) |
61
|
|
|
->where( |
62
|
|
|
$qb->expr()->eq('uid', $qb->createNamedParameter($uid)) |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
return $this->findEntities($qb); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $uid |
70
|
|
|
* @param int $id |
71
|
|
|
* |
72
|
|
|
* @return PublicKeyCredentialEntity |
73
|
|
|
* @throws DoesNotExistException |
74
|
|
|
*/ |
75
|
|
|
public function findById(string $uid, int $id): PublicKeyCredentialEntity { |
76
|
|
|
$qb = $this->db->getQueryBuilder(); |
77
|
|
|
|
78
|
|
|
$qb->select('*') |
79
|
|
|
->from($this->getTableName()) |
80
|
|
|
->where($qb->expr()->andX( |
81
|
|
|
$qb->expr()->eq('id', $qb->createNamedParameter($id)), |
82
|
|
|
$qb->expr()->eq('uid', $qb->createNamedParameter($uid)) |
83
|
|
|
)); |
84
|
|
|
|
85
|
|
|
return $this->findEntity($qb); |
|
|
|
|
86
|
|
|
} |
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
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|