public function authenticateByUsernameAndCallbackHandler(string $username, CallbackHandlerInterface $callbackHandler)
{
try {
// initialize the subject and the configuration
$subject = new Subject();
$configuration = $this->getConfiguration();
// initialize the LoginContext and try to login the user
$loginContext = new LoginContext($subject, $callbackHandler, $configuration);
$loginContext->login();
// create and return a new Principal of the authenticated user
return $this->createPrincipal($username, $subject, $loginContext);
} catch (\Exception $e) {
// add the exception to the stack
$this->getExceptionStack()->add($e);
// load the system logger and debug log the exception
/** @var \Psr\Log\LoggerInterface $systemLogger */
if ($systemLogger = $this->getAuthenticationManager()->getApplication()->getNamingDirectory()->search(NamingDirectoryKeys::SYSTEM_LOGGER)) {
$systemLogger->error($e->__toString());
}
}
}