public function login(string $username, string $password, HttpServletRequestInterface $servletRequest)
{
// load the realm to authenticate this request for
/** @var AppserverIo\Appserver\ServletEngine\Security\RealmInterface $realm */
$realm = $this->getAuthenticationManager()->getRealm($this->getRealmName());
// authenticate the request and initialize the user principal
$userPrincipal = $realm->authenticate($username, $password);
// query whether or not we can authenticate the user
if ($userPrincipal == null) {
throw new ServletException(sprintf('Can\'t authenticate user %s', $username));
}
// return's the user principal
return $userPrincipal;
}