2022-10-24 22:24:40 +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-24 22:24:40 +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-24 22:24:40 +02:00
|
|
|
*/
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-10-24 22:24:40 +02:00
|
|
|
namespace D3\Webauthn\Application\Controller;
|
|
|
|
|
2022-11-02 14:45:47 +01:00
|
|
|
use D3\Webauthn\Application\Controller\Traits\accountTrait;
|
2022-10-25 01:01:10 +02:00
|
|
|
use D3\Webauthn\Application\Model\Credential\PublicKeyCredential;
|
|
|
|
use D3\Webauthn\Application\Model\Credential\PublicKeyCredentialList;
|
2022-11-03 13:18:02 +01:00
|
|
|
use D3\Webauthn\Application\Model\Exceptions\WebauthnCreateException;
|
2022-10-26 21:37:02 +02:00
|
|
|
use D3\Webauthn\Application\Model\Webauthn;
|
2022-11-01 23:42:25 +01:00
|
|
|
use D3\Webauthn\Application\Model\WebauthnConf;
|
2022-10-26 21:37:02 +02:00
|
|
|
use D3\Webauthn\Application\Model\WebauthnErrors;
|
2022-11-03 13:18:02 +01:00
|
|
|
use D3\Webauthn\Application\Model\Exceptions\WebauthnException;
|
|
|
|
use Doctrine\DBAL\Driver\Exception as DoctrineDriverException;
|
|
|
|
use Doctrine\DBAL\Exception as DoctrineException;
|
2022-10-24 22:24:40 +02:00
|
|
|
use OxidEsales\Eshop\Application\Controller\AccountController;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
2022-11-04 22:02:44 +01:00
|
|
|
use OxidEsales\Eshop\Core\SeoEncoder;
|
2022-11-17 00:27:43 +01:00
|
|
|
use OxidEsales\Eshop\Core\UtilsView;
|
2022-11-03 13:18:02 +01:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2022-11-17 00:27:43 +01:00
|
|
|
use Psr\Log\LoggerInterface;
|
2022-10-24 22:24:40 +02:00
|
|
|
|
|
|
|
class d3_account_webauthn extends AccountController
|
|
|
|
{
|
2022-11-02 14:45:47 +01:00
|
|
|
use accountTrait;
|
|
|
|
|
2022-10-24 22:24:40 +02:00
|
|
|
protected $_sThisTemplate = 'd3_account_webauthn.tpl';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2022-10-30 00:27:11 +02:00
|
|
|
public function render(): string
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
|
|
|
$sRet = parent::render();
|
|
|
|
|
|
|
|
$this->addTplParam('user', $this->getUser());
|
2022-11-17 00:27:43 +01:00
|
|
|
$this->addTplParam('readonly', (bool) !($this->getWebauthnObject()->isAvailable()));
|
2022-10-27 14:52:20 +02:00
|
|
|
|
2022-10-24 22:24:40 +02:00
|
|
|
return $sRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-26 21:37:02 +02:00
|
|
|
* @return publicKeyCredentialList
|
2022-11-04 22:02:44 +01:00
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws DoctrineDriverException
|
|
|
|
* @throws DoctrineException
|
|
|
|
* @throws NotFoundExceptionInterface
|
2022-10-24 22:24:40 +02:00
|
|
|
*/
|
2022-10-30 00:27:11 +02:00
|
|
|
public function getCredentialList(): PublicKeyCredentialList
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
2022-10-26 21:37:02 +02:00
|
|
|
$oUser = $this->getUser();
|
2022-11-17 00:27:43 +01:00
|
|
|
$credentialList = $this->getPublicKeyCredentialListObject();
|
2022-10-26 21:37:02 +02:00
|
|
|
return $credentialList->getAllFromUser($oUser);
|
|
|
|
}
|
2022-10-24 22:24:40 +02:00
|
|
|
|
2022-11-03 13:18:02 +01:00
|
|
|
/**
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
* @throws DoctrineDriverException
|
|
|
|
* @throws DoctrineException
|
2022-11-04 22:02:44 +01:00
|
|
|
* @return void
|
2022-11-03 13:18:02 +01:00
|
|
|
*/
|
2022-11-04 22:02:44 +01:00
|
|
|
public function requestNewCredential(): void
|
2022-10-26 21:37:02 +02:00
|
|
|
{
|
2022-11-03 13:18:02 +01:00
|
|
|
try {
|
|
|
|
$this->setAuthnRegister();
|
|
|
|
$this->setPageType('requestnew');
|
|
|
|
} catch (WebauthnException $e) {
|
2022-11-17 00:27:43 +01:00
|
|
|
$this->getLogger()->error($e->getDetailedErrorMessage(), ['UserId: ' => $this->getUser()->getId()]);
|
|
|
|
$this->getLogger()->debug($e->getTraceAsString());
|
|
|
|
$this->getUtilsViewObject()->addErrorToDisplay($e);
|
2022-11-03 13:18:02 +01:00
|
|
|
}
|
2022-10-26 21:37:02 +02:00
|
|
|
}
|
2022-10-24 22:24:40 +02:00
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
/**
|
|
|
|
* @param $pageType
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setPageType($pageType): void
|
2022-10-26 21:37:02 +02:00
|
|
|
{
|
|
|
|
$this->addTplParam('pageType', $pageType);
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
|
2022-11-03 13:18:02 +01:00
|
|
|
/**
|
|
|
|
* @throws WebauthnException
|
|
|
|
* @throws DoctrineDriverException
|
|
|
|
* @throws DoctrineException
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
2022-11-04 22:02:44 +01:00
|
|
|
* @return void
|
2022-11-03 13:18:02 +01:00
|
|
|
*/
|
2022-11-04 22:02:44 +01:00
|
|
|
public function setAuthnRegister(): void
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
2022-11-17 00:27:43 +01:00
|
|
|
$publicKeyCredentialCreationOptions = $this->getWebauthnObject()->getCreationOptions($this->getUser());
|
2022-10-31 00:11:06 +01:00
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
$this->addTplParam('webauthn_publickey_create', $publicKeyCredentialCreationOptions);
|
2022-10-26 21:37:02 +02:00
|
|
|
$this->addTplParam('isAdmin', isAdmin());
|
|
|
|
$this->addTplParam('keyname', Registry::getRequest()->getRequestEscapedParameter('credenialname'));
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws DoctrineDriverException
|
|
|
|
* @throws DoctrineException
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
*/
|
|
|
|
public function saveAuthn(): void
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
2022-11-03 13:18:02 +01: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 WebauthnCreateException $e */
|
2022-11-13 21:43:33 +01:00
|
|
|
$e = oxNew( WebauthnCreateException::class, $error);
|
2022-11-03 13:18:02 +01:00
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
|
2022-11-13 21:43:33 +01:00
|
|
|
$credential = Registry::getRequest()->getRequestEscapedParameter('credential');
|
|
|
|
if (strlen((string) $credential)) {
|
2022-11-03 13:18:02 +01:00
|
|
|
/** @var Webauthn $webauthn */
|
2022-11-17 00:27:43 +01:00
|
|
|
$webauthn = $this->getWebauthnObject();
|
2022-11-13 21:43:33 +01:00
|
|
|
$webauthn->saveAuthn($credential, Registry::getRequest()->getRequestEscapedParameter('keyname'));
|
2022-11-03 13:18:02 +01:00
|
|
|
}
|
|
|
|
} catch (WebauthnException $e) {
|
2022-11-17 00:27:43 +01:00
|
|
|
$this->getUtilsViewObject()->addErrorToDisplay( $e );
|
2022-10-26 21:37:02 +02:00
|
|
|
}
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function deleteKey(): void
|
2022-10-24 22:24:40 +02:00
|
|
|
{
|
2022-11-17 00:27:43 +01:00
|
|
|
$deleteId = Registry::getRequest()->getRequestEscapedParameter('deleteoxid');
|
|
|
|
if ($deleteId) {
|
2022-10-26 21:37:02 +02:00
|
|
|
/** @var PublicKeyCredential $credential */
|
2022-11-17 00:27:43 +01:00
|
|
|
$credential = $this->getPublicKeyCredentialObject();
|
|
|
|
$credential->delete($deleteId);
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-04 22:02:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getBreadCrumb(): array
|
|
|
|
{
|
|
|
|
$aPaths = [];
|
|
|
|
$aPath = [];
|
|
|
|
|
|
|
|
$iBaseLanguage = Registry::getLang()->getBaseLanguage();
|
|
|
|
/** @var SeoEncoder $oSeoEncoder */
|
|
|
|
$oSeoEncoder = Registry::getSeoEncoder();
|
|
|
|
$aPath['title'] = Registry::getLang()->translateString('MY_ACCOUNT', $iBaseLanguage, false);
|
|
|
|
$aPath['link'] = $oSeoEncoder->getStaticUrl($this->getViewConfig()->getSelfLink() . "cl=account");
|
|
|
|
$aPaths[] = $aPath;
|
|
|
|
|
|
|
|
$aPath['title'] = Registry::getLang()->translateString('D3_WEBAUTHN_ACCOUNT', $iBaseLanguage, false);
|
|
|
|
$aPath['link'] = $this->getLink();
|
|
|
|
$aPaths[] = $aPath;
|
|
|
|
|
|
|
|
return $aPaths;
|
|
|
|
}
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Webauthn
|
|
|
|
*/
|
|
|
|
public function getWebauthnObject(): Webauthn
|
|
|
|
{
|
|
|
|
return oxNew(Webauthn::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return PublicKeyCredential
|
|
|
|
*/
|
|
|
|
public function getPublicKeyCredentialObject(): PublicKeyCredential
|
|
|
|
{
|
|
|
|
return oxNew(PublicKeyCredential::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return PublicKeyCredentialList
|
|
|
|
*/
|
|
|
|
public function getPublicKeyCredentialListObject(): PublicKeyCredentialList
|
|
|
|
{
|
|
|
|
return oxNew(PublicKeyCredentialList::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return LoggerInterface
|
|
|
|
*/
|
|
|
|
public function getLogger(): LoggerInterface
|
|
|
|
{
|
|
|
|
return Registry::getLogger();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return UtilsView
|
|
|
|
*/
|
|
|
|
public function getUtilsViewObject(): UtilsView
|
|
|
|
{
|
|
|
|
return Registry::getUtilsView();
|
|
|
|
}
|
2022-10-24 22:24:40 +02:00
|
|
|
}
|