/**
* Will be invoked when login fails for some reasons.
*
* @param \AppserverIo\Appserver\ServletEngine\Security\RealmInterface $realm The realm instance containing the exception stack
* @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The servlet request instance
* @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse The servlet response instance
*
* @return void
*/
protected function onFailure(RealmInterface $realm, HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
{
// load the session from the request
if ($session = $servletRequest->getSession()) {
// prepare the ArrayList for the login errors
$formErrors = new ArrayList();
// transform the realm's exception stack into simple error messages
foreach ($realm->getExceptionStack() as $e) {
$formErrors->add($e->getMessage());
}
// add the error messages to the session
$session->putData(Constants::FORM_ERRORS, $formErrors);
}
// forward to the configured error page
$this->forwardToErrorPage($servletRequest, $servletResponse);
}