Skip to content

Commit 364c772

Browse files
author
Vincent Chalnot
committed
Fixing authentication exception when trying to decrypt user cypher key with bad credentials
1 parent 2ca50e9 commit 364c772

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Authentication/AuthenticationProvider.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
namespace Sidus\EncryptionBundle\Authentication;
1212

1313
use Sidus\EncryptionBundle\Entity\UserEncryptionProviderInterface;
14+
use Sidus\EncryptionBundle\Exception\EncryptionException;
1415
use Sidus\EncryptionBundle\Registry\EncryptionManagerRegistry;
1516
use Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider;
1617
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
18+
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1719

1820
/**
1921
* The Authentication provider will be used at connection time to decrypt the cipher key in the user and store it in
@@ -48,7 +50,12 @@ protected function retrieveUser($username, UsernamePasswordToken $token)
4850
$user = parent::retrieveUser($username, $token);
4951
if ($user instanceof UserEncryptionProviderInterface && null !== $token->getCredentials()) {
5052
$encryptionManager = $this->encryptionManagerRegistry->getEncryptionManagerForUser($user);
51-
$encryptionManager->decryptCipherKey($user, $token->getCredentials());
53+
try {
54+
$encryptionManager->decryptCipherKey($user, $token->getCredentials());
55+
} catch (EncryptionException $e) {
56+
throw new BadCredentialsException('Bad credentials.', 0, $e);
57+
$e->setUsername($username);
58+
}
5259
}
5360

5461
return $user;

0 commit comments

Comments
 (0)