2022-10-29 00:19:34 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2022-11-04 22:45:47 +01:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
2022-10-29 00:19:34 +02:00
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
2022-11-04 22:45:47 +01:00
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
2022-10-29 00:19:34 +02:00
|
|
|
*/
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-10-29 00:19:34 +02:00
|
|
|
namespace D3\Webauthn\Application\Controller\Admin;
|
|
|
|
|
2022-11-23 00:18:09 +01:00
|
|
|
use D3\TestingTools\Production\IsMockable;
|
|
|
|
use D3\Webauthn\Application\Controller\Traits\helpersTrait;
|
2022-11-03 13:18:02 +01:00
|
|
|
use D3\Webauthn\Application\Model\Exceptions\WebauthnGetException;
|
2022-10-29 00:19:34 +02:00
|
|
|
use D3\Webauthn\Application\Model\Webauthn;
|
|
|
|
use D3\Webauthn\Application\Model\WebauthnConf;
|
2022-11-03 13:18:02 +01:00
|
|
|
use D3\Webauthn\Application\Model\Exceptions\WebauthnException;
|
2022-11-24 01:02:20 +01:00
|
|
|
use D3\Webauthn\Modules\Application\Controller\Admin\d3_LoginController_Webauthn;
|
2022-10-29 00:19:34 +02:00
|
|
|
use D3\Webauthn\Modules\Application\Model\d3_User_Webauthn;
|
2022-10-31 23:17:04 +01:00
|
|
|
use Doctrine\DBAL\Driver\Exception as DoctrineDriverException;
|
|
|
|
use Doctrine\DBAL\Exception as DoctrineException;
|
2022-10-29 00:19:34 +02:00
|
|
|
use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
|
|
|
|
use OxidEsales\Eshop\Application\Controller\Admin\LoginController;
|
|
|
|
use OxidEsales\Eshop\Application\Controller\FrontendController;
|
2022-11-24 01:02:20 +01:00
|
|
|
use OxidEsales\Eshop\Core\Exception\ConnectionException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\CookieException;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\UserException;
|
2022-10-29 00:19:34 +02:00
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
2022-11-24 01:02:20 +01:00
|
|
|
use OxidEsales\Eshop\Core\SystemEventHandler;
|
2022-10-29 00:19:34 +02:00
|
|
|
use OxidEsales\Eshop\Core\Utils;
|
2022-10-31 23:17:04 +01:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2022-10-29 00:19:34 +02:00
|
|
|
|
|
|
|
class d3webauthnadminlogin extends AdminController
|
|
|
|
{
|
2022-11-23 00:18:09 +01:00
|
|
|
use helpersTrait;
|
|
|
|
use IsMockable;
|
|
|
|
|
2022-10-29 00:19:34 +02:00
|
|
|
protected $_sThisTemplate = 'd3webauthnadminlogin.tpl';
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2022-10-30 00:27:11 +02:00
|
|
|
protected function _authorize(): bool
|
2022-10-29 00:19:34 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-11-04 22:02:44 +01:00
|
|
|
* @return string
|
2022-10-31 23:17:04 +01:00
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws DoctrineDriverException
|
|
|
|
* @throws DoctrineException
|
|
|
|
* @throws NotFoundExceptionInterface
|
2022-10-29 00:19:34 +02:00
|
|
|
*/
|
2022-11-04 22:02:44 +01:00
|
|
|
public function render(): string
|
2022-10-29 00:19:34 +02:00
|
|
|
{
|
2022-11-23 08:46:25 +01:00
|
|
|
if ($this->d3GetSession()->hasVariable(WebauthnConf::WEBAUTHN_ADMIN_SESSION_AUTH) ||
|
|
|
|
!$this->d3GetSession()->hasVariable(WebauthnConf::WEBAUTHN_ADMIN_SESSION_CURRENTUSER)
|
2022-10-29 00:19:34 +02:00
|
|
|
) {
|
|
|
|
$this->getUtils()->redirect('index.php?cl=admin_start');
|
|
|
|
}
|
|
|
|
|
2022-11-24 20:37:02 +01:00
|
|
|
/** @var d3_LoginController_Webauthn $loginController */
|
|
|
|
$loginController = oxNew(LoginController::class);
|
|
|
|
$loginController->d3WebauthnAfterLoginChangeLanguage();
|
|
|
|
|
2022-10-29 00:19:34 +02:00
|
|
|
$this->generateCredentialRequest();
|
|
|
|
|
2022-11-23 00:18:09 +01:00
|
|
|
$this->addTplParam('navFormParams', $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_NAVFORMPARAMS));
|
2022-11-24 09:10:45 +01:00
|
|
|
$this->addTplParam('currentProfile', $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_ADMIN_PROFILE));
|
|
|
|
$this->d3GetSession()->deleteVariable(WebauthnConf::WEBAUTHN_ADMIN_PROFILE);
|
|
|
|
$this->addTplParam('currentChLanguage', $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_ADMIN_CHLANGUAGE));
|
|
|
|
$this->d3GetSession()->deleteVariable(WebauthnConf::WEBAUTHN_ADMIN_CHLANGUAGE);
|
2022-11-23 00:18:09 +01:00
|
|
|
|
|
|
|
return $this->d3CallMockableParent('render');
|
2022-10-29 00:19:34 +02:00
|
|
|
}
|
|
|
|
|
2022-10-31 23:17:04 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
* @throws DoctrineDriverException
|
|
|
|
* @throws DoctrineException
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
*/
|
2022-11-04 22:02:44 +01:00
|
|
|
public function generateCredentialRequest(): void
|
2022-10-29 00:19:34 +02:00
|
|
|
{
|
2022-11-23 08:46:25 +01:00
|
|
|
$userId = $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_ADMIN_SESSION_CURRENTUSER);
|
2022-10-31 00:11:06 +01:00
|
|
|
try {
|
|
|
|
/** @var Webauthn $webauthn */
|
2022-11-23 00:18:09 +01:00
|
|
|
$webauthn = $this->d3GetWebauthnObject();
|
2022-10-31 00:11:06 +01:00
|
|
|
$publicKeyCredentialRequestOptions = $webauthn->getRequestOptions($userId);
|
2022-11-23 08:46:25 +01:00
|
|
|
$this->d3GetSession()->setVariable(WebauthnConf::WEBAUTHN_ADMIN_LOGIN_OBJECT, $publicKeyCredentialRequestOptions);
|
2022-10-31 00:11:06 +01:00
|
|
|
$this->addTplParam('webauthn_publickey_login', $publicKeyCredentialRequestOptions);
|
|
|
|
$this->addTplParam('isAdmin', isAdmin());
|
|
|
|
} catch (WebauthnException $e) {
|
2022-11-23 00:18:09 +01:00
|
|
|
$this->d3GetSession()->setVariable(WebauthnConf::GLOBAL_SWITCH, true);
|
2022-11-03 13:18:02 +01:00
|
|
|
Registry::getUtilsView()->addErrorToDisplay($e);
|
2022-11-23 00:18:09 +01:00
|
|
|
$this->d3GetLoggerObject()->error($e->getDetailedErrorMessage(), ['UserId' => $userId]);
|
|
|
|
$this->d3GetLoggerObject()->debug($e->getTraceAsString());
|
2022-10-31 23:17:04 +01:00
|
|
|
$this->getUtils()->redirect('index.php?cl=login');
|
2022-10-31 00:11:06 +01:00
|
|
|
}
|
2022-10-29 00:19:34 +02:00
|
|
|
}
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
/**
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function d3AssertAuthn(): ?string
|
2022-10-29 00:19:34 +02:00
|
|
|
{
|
2022-11-24 01:02:20 +01:00
|
|
|
$myUtilsView = Registry::getUtilsView();
|
2022-10-29 00:19:34 +02:00
|
|
|
/** @var d3_User_Webauthn $user */
|
2022-11-23 00:18:09 +01:00
|
|
|
$user = $this->d3GetUserObject();
|
2022-11-23 08:46:25 +01:00
|
|
|
$userId = $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_ADMIN_SESSION_CURRENTUSER);
|
2022-11-24 09:10:45 +01:00
|
|
|
$selectedProfile = Registry::getRequest()->getRequestEscapedParameter('profile');
|
2022-10-29 00:19:34 +02:00
|
|
|
|
|
|
|
try {
|
2022-11-13 21:43:33 +01:00
|
|
|
$error = Registry::getRequest()->getRequestEscapedParameter('error');
|
|
|
|
if (strlen((string) $error)) {
|
2022-11-03 13:18:02 +01:00
|
|
|
/** @var WebauthnGetException $e */
|
2022-11-13 21:43:33 +01:00
|
|
|
$e = oxNew(WebauthnGetException::class, $error);
|
2022-11-03 13:18:02 +01:00
|
|
|
throw $e;
|
2022-10-29 00:19:34 +02:00
|
|
|
}
|
|
|
|
|
2022-11-13 21:43:33 +01:00
|
|
|
$credential = Registry::getRequest()->getRequestEscapedParameter('credential');
|
|
|
|
if (strlen((string) $credential)) {
|
2022-11-23 00:18:09 +01:00
|
|
|
$webAuthn = $this->d3GetWebauthnObject();
|
|
|
|
$webAuthn->assertAuthn($credential);
|
2022-10-29 00:19:34 +02:00
|
|
|
|
2022-11-24 01:02:20 +01:00
|
|
|
$user->load($userId);
|
|
|
|
$session = $this->d3GetSession();
|
|
|
|
$adminProfiles = $session->getVariable("aAdminProfiles");
|
|
|
|
$session->initNewSession();
|
|
|
|
$session->setVariable("aAdminProfiles", $adminProfiles);
|
|
|
|
$session->setVariable(WebauthnConf::OXID_ADMIN_AUTH, $userId);
|
|
|
|
|
|
|
|
$cookie = Registry::getUtilsServer()->getOxCookie();
|
|
|
|
if ($cookie === null) {
|
|
|
|
throw oxNew(CookieException::class, 'ERROR_MESSAGE_COOKIE_NOCOOKIE');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($user->oxuser__oxrights->value === 'user') {
|
|
|
|
throw oxNew(UserException::class, 'ERROR_MESSAGE_USER_NOVALIDLOGIN');
|
|
|
|
}
|
|
|
|
$iSubshop = (int) $user->oxuser__oxrights->value;
|
|
|
|
if ($iSubshop) {
|
|
|
|
Registry::getSession()->setVariable("shp", $iSubshop);
|
|
|
|
Registry::getSession()->setVariable('currentadminshop', $iSubshop);
|
|
|
|
Registry::getConfig()->setShopId($iSubshop);
|
|
|
|
}
|
|
|
|
|
|
|
|
//execute onAdminLogin() event
|
|
|
|
$oEvenHandler = oxNew(SystemEventHandler::class);
|
|
|
|
$oEvenHandler->onAdminLogin(Registry::getConfig()->getShopId());
|
|
|
|
|
|
|
|
/** @var d3_LoginController_Webauthn $loginController */
|
2022-10-29 00:19:34 +02:00
|
|
|
$loginController = oxNew(LoginController::class);
|
2022-11-24 01:02:20 +01:00
|
|
|
$loginController->d3webauthnAfterLogin();
|
|
|
|
|
|
|
|
return "admin_start";
|
2022-10-29 00:19:34 +02:00
|
|
|
}
|
2022-11-24 01:02:20 +01:00
|
|
|
} catch (UserException $oEx) {
|
|
|
|
$myUtilsView->addErrorToDisplay('LOGIN_ERROR');
|
|
|
|
$oStr = getStr();
|
|
|
|
$this->addTplParam('user', $oStr->htmlspecialchars($userId));
|
|
|
|
$this->addTplParam('profile', $oStr->htmlspecialchars($selectedProfile));
|
|
|
|
|
|
|
|
return null;
|
|
|
|
} catch (CookieException $oEx) {
|
|
|
|
$myUtilsView->addErrorToDisplay('LOGIN_NO_COOKIE_SUPPORT');
|
|
|
|
$oStr = getStr();
|
|
|
|
$this->addTplParam('user', $oStr->htmlspecialchars($userId));
|
|
|
|
$this->addTplParam('profile', $oStr->htmlspecialchars($selectedProfile));
|
|
|
|
|
|
|
|
return null;
|
|
|
|
} catch (ConnectionException $oEx) {
|
|
|
|
$myUtilsView->addErrorToDisplay($oEx);
|
2022-11-03 13:18:02 +01:00
|
|
|
} catch (WebauthnException $e) {
|
2022-11-23 00:18:09 +01:00
|
|
|
$this->d3GetUtilsViewObject()->addErrorToDisplay($e);
|
|
|
|
$this->d3GetLoggerObject()->error($e->getDetailedErrorMessage(), ['UserId' => $userId]);
|
|
|
|
$this->d3GetLoggerObject()->debug($e->getTraceAsString());
|
2022-10-29 00:19:34 +02:00
|
|
|
$user->logout();
|
|
|
|
}
|
2022-10-30 00:27:11 +02:00
|
|
|
|
2022-11-04 08:38:08 +01:00
|
|
|
return 'login';
|
2022-10-29 00:19:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Utils
|
|
|
|
*/
|
2022-10-30 00:27:11 +02:00
|
|
|
public function getUtils(): Utils
|
2022-10-29 00:19:34 +02:00
|
|
|
{
|
|
|
|
return Registry::getUtils();
|
|
|
|
}
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
/**
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getPreviousClass(): ?string
|
2022-10-29 00:19:34 +02:00
|
|
|
{
|
2022-11-23 08:46:25 +01:00
|
|
|
return $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_ADMIN_SESSION_CURRENTCLASS);
|
2022-10-29 00:19:34 +02:00
|
|
|
}
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2022-10-30 00:27:11 +02:00
|
|
|
public function previousClassIsOrderStep(): bool
|
2022-10-29 00:19:34 +02:00
|
|
|
{
|
2022-11-23 08:46:25 +01:00
|
|
|
$sClassKey = $this->getPreviousClass();
|
2022-11-23 00:18:09 +01:00
|
|
|
$resolvedClass = $this->d3GetControllerClassNameResolver()->getClassNameById($sClassKey);
|
2022-10-30 00:27:11 +02:00
|
|
|
$resolvedClass = $resolvedClass ?: 'start';
|
2022-10-29 00:19:34 +02:00
|
|
|
|
|
|
|
/** @var FrontendController $oController */
|
|
|
|
$oController = oxNew($resolvedClass);
|
|
|
|
return $oController->getIsOrderStep();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2022-10-30 00:27:11 +02:00
|
|
|
public function getIsOrderStep(): bool
|
2022-10-29 00:19:34 +02:00
|
|
|
{
|
|
|
|
return $this->previousClassIsOrderStep();
|
|
|
|
}
|
|
|
|
}
|