Skip to content

Commit

Permalink
Merge pull request #409 from magento-performance/cabpi-278-disable-po…
Browse files Browse the repository at this point in the history
…st-to-old-login

CABPI-278: Disable post to old login
  • Loading branch information
andimov authored Mar 30, 2022
2 parents b3eec32 + 44b0c2c commit c134871
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\AdminAdobeIms\Plugin;

use Magento\AdminAdobeIms\Service\ImsConfig;
use Magento\Backend\Model\Auth;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\Message\ManagerInterface as MessageManagerInterface;

class DisableAdminLoginAuthPlugin
{
/** @var ImsConfig */
private ImsConfig $imsConfig;

/** @var RedirectFactory */
private RedirectFactory $redirectFactory;

/** @var MessageManagerInterface */
private MessageManagerInterface $messageManager;

/**
* @param ImsConfig $imsConfig
* @param RedirectFactory $redirectFactory
* @param MessageManagerInterface $messageManager
*/
public function __construct(
ImsConfig $imsConfig,
RedirectFactory $redirectFactory,
MessageManagerInterface $messageManager
) {
$this->imsConfig = $imsConfig;
$this->redirectFactory = $redirectFactory;
$this->messageManager = $messageManager;
}

/**
* When trying to call the login but IMS is enabled redirect to the main page with error message
*
* @param Auth $subject
* @param callable $proceed
* @param string $username
* @param string $password
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundLogin(Auth $subject, callable $proceed, string $username, string $password): void
{
if ($this->imsConfig->enabled() === false) {
$proceed($username, $password);
return;
}

/** @var Redirect $resultRedirect */
$resultRedirect = $this->redirectFactory->create();
$this->messageManager->addErrorMessage(__('Please sign in with Adobe ID'));
$resultRedirect->setPath('admin');
}
}
4 changes: 4 additions & 0 deletions app/code/Magento/AdminAdobeIms/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@
</argument>
</arguments>
</type>
<type name="Magento\Backend\Model\Auth">
<plugin name="disable_admin_login_auth"
type="Magento\AdminAdobeIms\Plugin\DisableAdminLoginAuthPlugin"/>
</type>
</config>

0 comments on commit c134871

Please sign in to comment.