/** * Handles an authentication failure and returns the Response for the * GuardAuthenticator. * * @param AuthenticationException $authenticationException * @param Request $request * @param GuardAuthenticatorInterface $guardAuthenticator * * @return null|Response */ public function handleAuthenticationFailure(AuthenticationException $authenticationException, Request $request, GuardAuthenticatorInterface $guardAuthenticator) { $this->tokenStorage->setToken(null); $response = $guardAuthenticator->onAuthenticationFailure($request, $authenticationException); if ($response instanceof Response || null === $response) { // returning null is ok, it means they want the request to continue return $response; } throw new \UnexpectedValueException(sprintf('The %s::onAuthenticationFailure method must return null or a Response object. You returned %s.', get_class($guardAuthenticator), is_object($response) ? get_class($response) : gettype($response))); }