diff --git a/packages/security/Http/Authenticator/JwtAuthenticator.php b/packages/security/Http/Authenticator/JwtAuthenticator.php index 06470748d..e0f0b3452 100644 --- a/packages/security/Http/Authenticator/JwtAuthenticator.php +++ b/packages/security/Http/Authenticator/JwtAuthenticator.php @@ -130,7 +130,11 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token, public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response { - throw new HttpException(Response::HTTP_FORBIDDEN, $this->translate($exception->getMessageKey(), $exception->getMessageData())); + throw new HttpException( + Response::HTTP_FORBIDDEN, + $this->translate($exception->getMessageKey(), $exception->getMessageData()), + previous: $exception + ); } private function translate(string $message, array $data = []): string diff --git a/packages/security/Tests/Http/Authenticator/JwtAuthenticatorTest.php b/packages/security/Tests/Http/Authenticator/JwtAuthenticatorTest.php index 028c05edb..debc158f8 100644 --- a/packages/security/Tests/Http/Authenticator/JwtAuthenticatorTest.php +++ b/packages/security/Tests/Http/Authenticator/JwtAuthenticatorTest.php @@ -367,13 +367,15 @@ public function testOnAuthenticationFailure(): void $this->expectException(HttpException::class); $this->expectExceptionMessage($translatedMessage); + $previous = new CustomUserMessageAuthenticationException( + $message, + $messageData + ); + try { $this->object->onAuthenticationFailure( new Request(), - new CustomUserMessageAuthenticationException( - $message, - $messageData - ) + $previous ); } catch (HttpException $error) { static::assertSame( @@ -381,6 +383,11 @@ public function testOnAuthenticationFailure(): void $error->getStatusCode() ); + static::assertSame( + $previous, + $error->getPrevious() + ); + throw $error; } } @@ -424,7 +431,7 @@ public function testOnAuthenticationFailureNoTranslator(): void } /** - * This is form the parent abstract class but we test it as part of a contract test. + * This is form the parent abstract class but, we test it as part of a contract test. * * @see AbstractAuthenticator */