123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\User\Observer\Backend;
- use Magento\Framework\Event\Observer as EventObserver;
- use Magento\Framework\Event\ObserverInterface;
- /**
- * User backend observer model for passwords
- */
- class ForceAdminPasswordChangeObserver implements ObserverInterface
- {
- /**
- * Backend configuration interface
- *
- * @var \Magento\User\Model\Backend\Config\ObserverConfig
- */
- protected $observerConfig;
- /**
- * Authorization interface
- *
- * @var \Magento\Framework\AuthorizationInterface
- */
- protected $authorization;
- /**
- * Backend url interface
- *
- * @var \Magento\Backend\Model\UrlInterface
- */
- protected $url;
- /**
- * Backend session
- *
- * @var \Magento\Backend\Model\Session
- */
- protected $session;
- /**
- * Backend authorization session
- *
- * @var \Magento\Backend\Model\Auth\Session
- */
- protected $authSession;
- /**
- * Action flag
- *
- * @var \Magento\Framework\App\ActionFlag
- */
- protected $actionFlag;
- /**
- * Message manager interface
- *
- * @var \Magento\Framework\Message\ManagerInterface
- */
- protected $messageManager;
- /**
- * @param \Magento\Framework\AuthorizationInterface $authorization
- * @param \Magento\User\Model\Backend\Config\ObserverConfig $observerConfig
- * @param \Magento\Backend\Model\UrlInterface $url
- * @param \Magento\Backend\Model\Session $session
- * @param \Magento\Backend\Model\Auth\Session $authSession
- * @param \Magento\Framework\App\ActionFlag $actionFlag
- * @param \Magento\Framework\Message\ManagerInterface $messageManager
- */
- public function __construct(
- \Magento\Framework\AuthorizationInterface $authorization,
- \Magento\User\Model\Backend\Config\ObserverConfig $observerConfig,
- \Magento\Backend\Model\UrlInterface $url,
- \Magento\Backend\Model\Session $session,
- \Magento\Backend\Model\Auth\Session $authSession,
- \Magento\Framework\App\ActionFlag $actionFlag,
- \Magento\Framework\Message\ManagerInterface $messageManager
- ) {
- $this->authorization = $authorization;
- $this->observerConfig = $observerConfig;
- $this->url = $url;
- $this->session = $session;
- $this->authSession = $authSession;
- $this->actionFlag = $actionFlag;
- $this->messageManager = $messageManager;
- }
- /**
- * Force admin to change password
- *
- * @param EventObserver $observer
- * @return void
- */
- public function execute(EventObserver $observer)
- {
- if (!$this->observerConfig->isPasswordChangeForced()) {
- return;
- }
- if (!$this->authSession->isLoggedIn()) {
- return;
- }
- $actionList = [
- 'adminhtml_system_account_index',
- 'adminhtml_system_account_save',
- 'adminhtml_auth_logout',
- 'mui_index_render'
- ];
- /** @var \Magento\Framework\App\Action\Action $controller */
- $controller = $observer->getEvent()->getControllerAction();
- /** @var \Magento\Framework\App\RequestInterface $request */
- $request = $observer->getEvent()->getRequest();
- if ($this->authSession->getPciAdminUserIsPasswordExpired()) {
- if (!in_array($request->getFullActionName(), $actionList)) {
- if ($this->authorization->isAllowed('Magento_Backend::myaccount')) {
- $controller->getResponse()->setRedirect($this->url->getUrl('adminhtml/system_account/'));
- $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
- $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_POST_DISPATCH, true);
- } else {
- /*
- * if admin password is expired and access to 'My Account' page is denied
- * than we need to do force logout with error message
- */
- $this->authSession->clearStorage();
- $this->session->clearStorage();
- $this->messageManager->addErrorMessage(
- __('Your password has expired; please contact your administrator.')
- );
- $controller->getRequest()->setDispatched(false);
- }
- }
- }
- }
- }
|