Skip to content

Commit

Permalink
Merge branch 'ims-phase1' of github.com:magento-performance/magento2c…
Browse files Browse the repository at this point in the history
…e into CABPI-389

# Conflicts:
#	app/code/Magento/AdminAdobeIms/Service/ImsOrganizationService.php
#	app/code/Magento/AdminAdobeIms/etc/config.xml
  • Loading branch information
andimov committed May 6, 2022
2 parents 9648b84 + 1bf8395 commit 0af8c77
Show file tree
Hide file tree
Showing 51 changed files with 863 additions and 264 deletions.
16 changes: 5 additions & 11 deletions app/code/Magento/AdminAdobeIms/Block/Adminhtml/ImsReAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@

namespace Magento\AdminAdobeIms\Block\Adminhtml;

use Magento\AdminAdobeIms\Model\Auth;
use Magento\AdminAdobeIms\Service\ImsConfig;
use Magento\AdobeImsApi\Api\ConfigProviderInterface;
use Magento\AdobeImsApi\Api\ConfigInterface;
use Magento\AdobeImsApi\Api\UserAuthorizedInterface;
use Magento\AdobeImsApi\Api\UserProfileRepositoryInterface;
use Magento\Authorization\Model\UserContextInterface;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Serialize\Serializer\JsonHexTag;

/**
Expand All @@ -38,7 +32,7 @@ class ImsReAuth extends Template
/**
* @var ImsConfig
*/
private $imsConfig;
private $adminImsConfig;

/**
* JsonHexTag Serializer Instance
Expand All @@ -51,17 +45,17 @@ class ImsReAuth extends Template
* SignIn constructor.
*
* @param Context $context
* @param ImsConfig $imsConfig
* @param ImsConfig $adminImsConfig
* @param JsonHexTag $json
* @param array $data
*/
public function __construct(
Context $context,
ImsConfig $imsConfig,
ImsConfig $adminImsConfig,
JsonHexTag $json,
array $data = []
) {
$this->imsConfig = $imsConfig;
$this->adminImsConfig = $adminImsConfig;
$this->serializer = $json;
parent::__construct($context, $data);
}
Expand Down Expand Up @@ -92,7 +86,7 @@ private function getDefaultComponentConfig(): array
'component' => self::ADOBE_IMS_JS_REAUTH,
'template' => self::ADOBE_IMS_REAUTH,
'loginConfig' => [
'url' => $this->imsConfig->getAdminAdobeImsReAuthUrl(),
'url' => $this->adminImsConfig->getAdminAdobeImsReAuthUrl(),
'callbackParsingParams' => [
'regexpPattern' => self::RESPONSE_REGEXP_PATTERN,
'codeIndex' => self::RESPONSE_CODE_INDEX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
class Disabled extends Field
{
/** @var ImsConfig */
private ImsConfig $imsConfig;
private ImsConfig $adminImsConfig;

/**
* @param Context $context
* @param SecureHtmlRenderer $secureRenderer
* @param ImsConfig $imsConfig
* @param ImsConfig $adminImsConfig
* @param array $data
*/
public function __construct(
Context $context,
SecureHtmlRenderer $secureRenderer,
ImsConfig $imsConfig,
ImsConfig $adminImsConfig,
array $data = []
) {
parent::__construct($context, $data, $secureRenderer);
$this->imsConfig = $imsConfig;
$this->adminImsConfig = $adminImsConfig;
}

/**
Expand All @@ -43,7 +43,7 @@ public function __construct(
*/
public function render(AbstractElement $element): string
{
if ($this->imsConfig->enabled() === false) {
if ($this->adminImsConfig->enabled() === false) {
return parent::render($element);
}
return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ class AdminAdobeImsDisableCommand extends Command
/**
* @var ImsConfig
*/
private ImsConfig $imsConfig;
private ImsConfig $adminImsConfig;

/**
* @var TypeListInterface
*/
private TypeListInterface $cacheTypeList;

/**
* @param ImsConfig $imsConfig
* @param ImsConfig $adminImsConfig
* @param TypeListInterface $cacheTypeList
*/
public function __construct(
ImsConfig $imsConfig,
ImsConfig $adminImsConfig,
TypeListInterface $cacheTypeList
) {
parent::__construct();
$this->imsConfig = $imsConfig;
$this->adminImsConfig = $adminImsConfig;

$this->setName('admin:adobe-ims:disable')
->setDescription('Disable Adobe IMS Module');
Expand All @@ -53,7 +53,7 @@ public function __construct(
protected function execute(InputInterface $input, OutputInterface $output): ?int
{
try {
$this->imsConfig->disableModule();
$this->adminImsConfig->disableModule();
$this->cacheTypeList->cleanType(Config::TYPE_IDENTIFIER);
$output->writeln(__('Admin Adobe IMS integration is disabled'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class AdminAdobeImsEnableCommand extends Command
/**
* @var ImsConfig
*/
private ImsConfig $imsConfig;
private ImsConfig $adminImsConfig;

/**
* @var ImsConnection
*/
private ImsConnection $imsConnection;
private ImsConnection $adminImsConnection;

/**
* @var ImsCommandOptionService
Expand All @@ -74,22 +74,22 @@ class AdminAdobeImsEnableCommand extends Command
private UpdateTokensService $updateTokensService;

/**
* @param ImsConfig $imsConfig
* @param ImsConnection $imsConnection
* @param ImsConfig $adminImsConfig
* @param ImsConnection $adminImsConnection
* @param ImsCommandOptionService $imsCommandOptionService
* @param TypeListInterface $cacheTypeList
* @param UpdateTokensService $updateTokensService
*/
public function __construct(
ImsConfig $imsConfig,
ImsConnection $imsConnection,
ImsConfig $adminImsConfig,
ImsConnection $adminImsConnection,
ImsCommandOptionService $imsCommandOptionService,
TypeListInterface $cacheTypeList,
UpdateTokensService $updateTokensService
) {
parent::__construct();
$this->imsConfig = $imsConfig;
$this->imsConnection = $imsConnection;
$this->adminImsConfig = $adminImsConfig;
$this->adminImsConnection = $adminImsConnection;
$this->imsCommandOptionService = $imsCommandOptionService;
$this->cacheTypeList = $cacheTypeList;
$this->updateTokensService = $updateTokensService;
Expand Down Expand Up @@ -198,9 +198,9 @@ private function enableModule(
string $organizationId,
bool $isTwoFactorAuthEnabled
): bool {
$testAuth = $this->imsConnection->testAuth($clientId);
$testAuth = $this->adminImsConnection->testAuth($clientId);
if ($testAuth) {
$this->imsConfig->enableModule($clientId, $clientSecret, $organizationId, $isTwoFactorAuthEnabled);
$this->adminImsConfig->enableModule($clientId, $clientSecret, $organizationId, $isTwoFactorAuthEnabled);
$this->cacheTypeList->cleanType(Config::TYPE_IDENTIFIER);
$this->updateTokensService->execute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ class AdminAdobeImsInfoCommand extends Command
/**
* @var ImsConfig
*/
private ImsConfig $imsConfig;
private ImsConfig $adminImsConfig;

/**
* @var ImsConnection
*/
private ImsConnection $imsConnection;
private ImsConnection $adminImsConnection;

/**
* @param ImsConfig $imsConfig
* @param ImsConnection $imsConnection
* @param ImsConfig $adminImsConfig
* @param ImsConnection $adminImsConnection
*/
public function __construct(
ImsConfig $imsConfig,
ImsConnection $imsConnection
ImsConfig $adminImsConfig,
ImsConnection $adminImsConnection
) {
parent::__construct();
$this->imsConfig = $imsConfig;
$this->imsConnection = $imsConnection;
$this->adminImsConfig = $adminImsConfig;
$this->adminImsConnection = $adminImsConnection;

$this->setName('admin:adobe-ims:info')
->setDescription('Information of Adobe IMS Module configuration');
Expand All @@ -67,12 +67,12 @@ public function __construct(
protected function execute(InputInterface $input, OutputInterface $output): ?int
{
try {
if ($this->imsConfig->enabled()) {
$clientId = $this->imsConfig->getApiKey();
if ($this->imsConnection->testAuth($clientId)) {
$clientSecret = $this->imsConfig->getPrivateKey() ? 'configured' : 'not configured';
if ($this->adminImsConfig->enabled()) {
$clientId = $this->adminImsConfig->getApiKey();
if ($this->adminImsConnection->testAuth($clientId)) {
$clientSecret = $this->adminImsConfig->getPrivateKey() ? 'configured' : 'not configured';
$output->writeln(self::CLIENT_ID_NAME . ': ' . $clientId);
$output->writeln(self::ORGANIZATION_ID_NAME . ': ' . $this->imsConfig->getOrganizationId());
$output->writeln(self::ORGANIZATION_ID_NAME . ': ' . $this->adminImsConfig->getOrganizationId());
$output->writeln(self::CLIENT_SECRET_NAME . ' ' . $clientSecret);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ class AdminAdobeImsStatusCommand extends Command
/**
* @var ImsConfig
*/
private ImsConfig $imsConfig;
private ImsConfig $adminImsConfig;

/**
* @param ImsConfig $imsConfig
* @param ImsConfig $adminImsConfig
*/
public function __construct(
ImsConfig $imsConfig
ImsConfig $adminImsConfig
) {
parent::__construct();
$this->imsConfig = $imsConfig;
$this->adminImsConfig = $adminImsConfig;

$this->setName('admin:adobe-ims:status')
->setDescription('Status of Adobe IMS Module');
Expand Down Expand Up @@ -66,6 +66,6 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
*/
private function getModuleStatus(): string
{
return $this->imsConfig->enabled() ? self::MODE_ENABLE .'d' : self::MODE_DISABLE.'d';
return $this->adminImsConfig->enabled() ? self::MODE_ENABLE .'d' : self::MODE_DISABLE.'d';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ class ImsCallback extends Auth implements HttpGetActionInterface
/**
* @var ImsConnection
*/
private ImsConnection $imsConnection;
private ImsConnection $adminImsConnection;

/**
* @var ImsConfig
*/
private ImsConfig $imsConfig;
private ImsConfig $adminImsConfig;

/**
* @var ImsOrganizationService
*/
private ImsOrganizationService $organizationService;
private ImsOrganizationService $adminOrganizationService;

/**
* @var AdminLoginProcessService
Expand All @@ -53,24 +53,24 @@ class ImsCallback extends Auth implements HttpGetActionInterface

/**
* @param Context $context
* @param ImsConnection $imsConnection
* @param ImsConfig $imsConfig
* @param ImsOrganizationService $organizationService
* @param ImsConnection $adminImsConnection
* @param ImsConfig $adminImsConfig
* @param ImsOrganizationService $adminOrganizationService
* @param AdminLoginProcessService $adminLoginProcessService
* @param AdminAdobeImsLogger $logger
*/
public function __construct(
Context $context,
ImsConnection $imsConnection,
ImsConfig $imsConfig,
ImsOrganizationService $organizationService,
ImsConnection $adminImsConnection,
ImsConfig $adminImsConfig,
ImsOrganizationService $adminOrganizationService,
AdminLoginProcessService $adminLoginProcessService,
AdminAdobeImsLogger $logger
) {
parent::__construct($context);
$this->imsConnection = $imsConnection;
$this->imsConfig = $imsConfig;
$this->organizationService = $organizationService;
$this->adminImsConnection = $adminImsConnection;
$this->adminImsConfig = $adminImsConfig;
$this->adminOrganizationService = $adminOrganizationService;
$this->adminLoginProcessService = $adminLoginProcessService;
$this->logger = $logger;
}
Expand All @@ -86,7 +86,7 @@ public function execute(): Redirect
$resultRedirect = $this->resultRedirectFactory->create();
$resultRedirect->setPath($this->_helper->getHomePageUrl());

if (!$this->imsConfig->enabled()) {
if (!$this->adminImsConfig->enabled()) {
$this->getMessageManager()->addErrorMessage('Adobe Sign-In is disabled.');
return $resultRedirect;
}
Expand All @@ -98,13 +98,13 @@ public function execute(): Redirect
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
}

$tokenResponse = $this->imsConnection->getTokenResponse($code);
$tokenResponse = $this->adminImsConnection->getTokenResponse($code);

$profile = $this->imsConnection->getProfile($tokenResponse->getAccessToken());
$profile = $this->adminImsConnection->getProfile($tokenResponse->getAccessToken());
if (empty($profile['email'])) {
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
}
$this->organizationService->checkOrganizationAllocation($profile);
$this->adminOrganizationService->checkOrganizationAllocation($profile);
$this->adminLoginProcessService->execute($tokenResponse, $profile);
} catch (AdobeImsAuthorizationException $e) {
$this->logger->error($e->getMessage());
Expand Down
Loading

0 comments on commit 0af8c77

Please sign in to comment.