/** * Create's a new instance of the login module with the passed class name. * * @param \AppserverIo\Lang\String $className The login module class name * * @return \AppserverIo\Psr\Security\Auth\Spi\LoginModuleInterface The login module instance */ public function createLoginModuleInstance(string $className) { return parent::createLoginModuleInstance($className); }
/** * Finally tries to authenticate the user with the passed name. * * @param \AppserverIo\Lang\String $username The name of the user to authenticate * @param \AppserverIo\Psr\Security\Auth\Callback\CallbackHandlerInterface $callbackHandler The callback handler used to load the credentials * * @return \AppserverIo\Security\PrincipalInterface|null The authenticated user principal */ 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()); } } }