1515use OCP \DB \Exception ;
1616use OCP \DB \QueryBuilder \IQueryBuilder ;
1717use OCP \IDBConnection ;
18- use OCP \IUser ;
1918
2019/**
2120 * @template-extends QBMapper<PublicKeyCredentialEntity>
@@ -104,17 +103,21 @@ public function findById(int $id, string $userId): ?PublicKeyCredentialEntity {
104103 }
105104 }
106105
107- /**
108- * @param IUser $user
109- * @param int $id
110- */
111- public function findPublicKeyCredential ($ publicKeyCredentialId ): ?PublicKeyCredentialEntity {
112- /* @var $qb IQueryBuilder */
106+ public function findPublicKeyCredential (string $ publicKeyCredentialId , string $ userId ): ?PublicKeyCredentialEntity {
113107 $ qb = $ this ->db ->getQueryBuilder ();
114108
115109 $ qb ->select ('id ' , 'name ' , 'public_key_credential_id ' , 'type ' , 'transports ' , 'attestation_type ' , 'trust_path ' , 'aaguid ' , 'credential_public_key ' , 'user_handle ' , 'counter ' , 'active ' , 'created_at ' )
116110 ->from ('twofactor_webauthn_regs ' )
117- ->where ($ qb ->expr ()->eq ('public_key_credential_id ' , $ qb ->createNamedParameter ($ publicKeyCredentialId )));
111+ ->where ($ qb ->expr ()->eq (
112+ 'public_key_credential_id ' ,
113+ $ qb ->createNamedParameter ($ publicKeyCredentialId , IQueryBuilder::PARAM_STR ),
114+ IQueryBuilder::PARAM_STR ,
115+ ))
116+ ->andWhere ($ qb ->expr ()->eq (
117+ 'user_handle ' ,
118+ $ qb ->createNamedParameter ($ userId , IQueryBuilder::PARAM_STR ),
119+ IQueryBuilder::PARAM_STR ,
120+ ));
118121 try {
119122 return $ this ->findEntity ($ qb );
120123 } catch (\Exception $ exception ) {
@@ -136,7 +139,7 @@ public function findPublicKeyCredentials(string $uid): array {
136139 }
137140
138141 public function insertOrUpdate (Entity $ entity ): Entity {
139- $ publicKeyCredentialEntity = $ this ->findPublicKeyCredential ($ entity ->getPublicKeyCredentialId ());
142+ $ publicKeyCredentialEntity = $ this ->findPublicKeyCredential ($ entity ->getPublicKeyCredentialId (), $ entity -> getUserHandle () );
140143 if ($ publicKeyCredentialEntity !== null ) {
141144 $ entity ->setId ($ publicKeyCredentialEntity ->getId ());
142145 return parent ::update ($ entity );
0 commit comments