AppserverIo\Appserver\ServletEngine\Authenticator\FormAuthenticator::onFailure PHP Method

onFailure() protected method

Will be invoked when login fails for some reasons.
protected onFailure ( AppserverIo\Appserver\ServletEngine\Security\RealmInterface $realm, AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest, AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface $servletResponse ) : void
$realm AppserverIo\Appserver\ServletEngine\Security\RealmInterface The realm instance containing the exception stack
$servletRequest AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface The servlet request instance
$servletResponse AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface 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);
    }