|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\AdminAdobeIms\Plugin; |
| 10 | + |
| 11 | +use Magento\AdminAdobeIms\Service\ImsConfig; |
| 12 | +use Magento\Backend\Model\Auth; |
| 13 | +use Magento\Framework\Controller\Result\Redirect; |
| 14 | +use Magento\Framework\Controller\Result\RedirectFactory; |
| 15 | +use Magento\Framework\Message\ManagerInterface as MessageManagerInterface; |
| 16 | + |
| 17 | +class DisableAdminLoginAuthPlugin |
| 18 | +{ |
| 19 | + /** @var ImsConfig */ |
| 20 | + private ImsConfig $imsConfig; |
| 21 | + |
| 22 | + /** @var RedirectFactory */ |
| 23 | + private RedirectFactory $redirectFactory; |
| 24 | + |
| 25 | + /** @var MessageManagerInterface */ |
| 26 | + private MessageManagerInterface $messageManager; |
| 27 | + |
| 28 | + /** |
| 29 | + * @param ImsConfig $imsConfig |
| 30 | + * @param RedirectFactory $redirectFactory |
| 31 | + * @param MessageManagerInterface $messageManager |
| 32 | + */ |
| 33 | + public function __construct( |
| 34 | + ImsConfig $imsConfig, |
| 35 | + RedirectFactory $redirectFactory, |
| 36 | + MessageManagerInterface $messageManager |
| 37 | + ) { |
| 38 | + $this->imsConfig = $imsConfig; |
| 39 | + $this->redirectFactory = $redirectFactory; |
| 40 | + $this->messageManager = $messageManager; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * When trying to call the login but IMS is enabled redirect to the main page with error message |
| 45 | + * |
| 46 | + * @param Auth $subject |
| 47 | + * @param callable $proceed |
| 48 | + * @param string $username |
| 49 | + * @param string $password |
| 50 | + * @return void |
| 51 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 52 | + */ |
| 53 | + public function aroundLogin(Auth $subject, callable $proceed, string $username, string $password): void |
| 54 | + { |
| 55 | + if ($this->imsConfig->enabled() === false) { |
| 56 | + $proceed($username, $password); |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + /** @var Redirect $resultRedirect */ |
| 61 | + $resultRedirect = $this->redirectFactory->create(); |
| 62 | + $this->messageManager->addErrorMessage(__('Please sign in with Adobe ID')); |
| 63 | + $resultRedirect->setPath('admin'); |
| 64 | + } |
| 65 | +} |
0 commit comments