Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Authentication Class Reference
Inheritance diagram for Authentication:
BackendAuthentication

Public Member Functions

 __construct (\Magento\Backend\Model\Auth $auth, \Magento\Backend\Model\UrlInterface $url, \Magento\Framework\App\ResponseInterface $response, \Magento\Framework\App\ActionFlag $actionFlag, \Magento\Framework\Message\ManagerInterface $messageManager, \Magento\Backend\Model\UrlInterface $backendUrl, \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\App\BackendAppList $backendAppList, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator)
 
 aroundDispatch (\Magento\Backend\App\AbstractAction $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 

Protected Member Functions

 _processNotLoggedInUser (\Magento\Framework\App\RequestInterface $request)
 
 _performLogin (\Magento\Framework\App\RequestInterface $request)
 
 _redirectIfNeededAfterLogin (\Magento\Framework\App\RequestInterface $request)
 

Protected Attributes

 $_auth
 
 $_openActions
 
 $_url
 
 $_response
 
 $_actionFlag
 
 $messageManager
 
 $backendUrl
 
 $backendAppList
 
 $resultRedirectFactory
 
 $formKeyValidator
 

Detailed Description

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 13 of file Authentication.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Backend\Model\Auth$auth
\Magento\Backend\Model\UrlInterface$url
\Magento\Framework\App\ResponseInterface$response
\Magento\Framework\App\ActionFlag$actionFlag
\Magento\Framework\Message\ManagerInterface$messageManager
\Magento\Backend\Model\UrlInterface$backendUrl
\Magento\Framework\Controller\Result\RedirectFactory$resultRedirectFactory
\Magento\Backend\App\BackendAppList$backendAppList
\Magento\Framework\Data\Form\FormKey\Validator$formKeyValidator

Definition at line 82 of file Authentication.php.

92  {
93  $this->_auth = $auth;
94  $this->_url = $url;
95  $this->_response = $response;
96  $this->_actionFlag = $actionFlag;
97  $this->messageManager = $messageManager;
98  $this->backendUrl = $backendUrl;
99  $this->resultRedirectFactory = $resultRedirectFactory;
100  $this->backendAppList = $backendAppList;
101  $this->formKeyValidator = $formKeyValidator;
102  }
$response
Definition: 404.php:11

Member Function Documentation

◆ _performLogin()

_performLogin ( \Magento\Framework\App\RequestInterface  $request)
protected

Performs login, if user submitted login form

Parameters
\Magento\Framework\App\RequestInterface$request
Returns
bool

Definition at line 196 of file Authentication.php.

197  {
198  $outputValue = true;
199  $postLogin = $request->getPost('login');
200  $username = isset($postLogin['username']) ? $postLogin['username'] : '';
201  $password = isset($postLogin['password']) ? $postLogin['password'] : '';
202  $request->setPostValue('login', null);
203 
204  try {
205  $this->_auth->login($username, $password);
206  } catch (AuthenticationException $e) {
207  if (!$request->getParam('messageSent')) {
208  $this->messageManager->addErrorMessage($e->getMessage());
209  $request->setParam('messageSent', true);
210  $outputValue = false;
211  }
212  }
213  return $outputValue;
214  }

◆ _processNotLoggedInUser()

_processNotLoggedInUser ( \Magento\Framework\App\RequestInterface  $request)
protected

Process not logged in user data

Parameters
\Magento\Framework\App\RequestInterface$request
Returns
void

Definition at line 152 of file Authentication.php.

153  {
154  $isRedirectNeeded = false;
155  if ($request->getPost('login')) {
156  if ($this->formKeyValidator->validate($request)) {
157  if ($this->_performLogin($request)) {
158  $isRedirectNeeded = $this->_redirectIfNeededAfterLogin($request);
159  }
160  } else {
161  $this->_actionFlag->set('', \Magento\Framework\App\ActionInterface::FLAG_NO_DISPATCH, true);
162  $this->_response->setRedirect($this->_url->getCurrentUrl());
163  $this->messageManager->addErrorMessage(__('Invalid Form Key. Please refresh the page.'));
164  $isRedirectNeeded = true;
165  }
166  }
167  if (!$isRedirectNeeded && !$request->isForwarded()) {
168  if ($request->getParam('isIframe')) {
169  $request->setForwarded(true)
170  ->setRouteName('adminhtml')
171  ->setControllerName('auth')
172  ->setActionName('deniedIframe')
173  ->setDispatched(false);
174  } elseif ($request->getParam('isAjax')) {
175  $request->setForwarded(true)
176  ->setRouteName('adminhtml')
177  ->setControllerName('auth')
178  ->setActionName('deniedJson')
179  ->setDispatched(false);
180  } else {
181  $request->setForwarded(true)
182  ->setRouteName('adminhtml')
183  ->setControllerName('auth')
184  ->setActionName('login')
185  ->setDispatched(false);
186  }
187  }
188  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
_performLogin(\Magento\Framework\App\RequestInterface $request)
__()
Definition: __.php:13
_redirectIfNeededAfterLogin(\Magento\Framework\App\RequestInterface $request)

◆ _redirectIfNeededAfterLogin()

_redirectIfNeededAfterLogin ( \Magento\Framework\App\RequestInterface  $request)
protected

Checks, whether Magento requires redirection after successful admin login, and redirects user, if needed

Parameters
\Magento\Framework\App\RequestInterface$request
Returns
bool

Definition at line 222 of file Authentication.php.

223  {
224  $requestUri = null;
225 
226  // Checks, whether secret key is required for admin access or request uri is explicitly set
227  if ($this->_url->useSecretKey()) {
228  $requestUri = $this->_url->getUrl('*/*/*', ['_current' => true]);
229  } elseif ($request) {
230  $requestUri = $request->getRequestUri();
231  }
232 
233  if (!$requestUri) {
234  return false;
235  }
236 
237  $this->_response->setRedirect($requestUri);
238  $this->_actionFlag->set('', \Magento\Framework\App\ActionInterface::FLAG_NO_DISPATCH, true);
239  return true;
240  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ aroundDispatch()

aroundDispatch ( \Magento\Backend\App\AbstractAction  $subject,
\Closure  $proceed,
\Magento\Framework\App\RequestInterface  $request 
)
Parameters
\Magento\Backend\App\AbstractAction$subject
\Closure$proceed
\Magento\Framework\App\RequestInterface$request
Returns
mixed @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 112 of file Authentication.php.

116  {
117  $requestedActionName = $request->getActionName();
118  if (in_array($requestedActionName, $this->_openActions)) {
119  $request->setDispatched(true);
120  } else {
121  if ($this->_auth->getUser()) {
122  $this->_auth->getUser()->reload();
123  }
124  if (!$this->_auth->isLoggedIn()) {
126  } else {
127  $this->_auth->getAuthStorage()->prolong();
128 
129  $backendApp = null;
130  if ($request->getParam('app')) {
131  $backendApp = $this->backendAppList->getCurrentApp();
132  }
133 
134  if ($backendApp) {
135  $resultRedirect = $this->resultRedirectFactory->create();
136  $baseUrl = \Magento\Framework\App\Request\Http::getUrlNoScript($this->backendUrl->getBaseUrl());
137  $baseUrl = $baseUrl . $backendApp->getStartupPage();
138  return $resultRedirect->setUrl($baseUrl);
139  }
140  }
141  }
142  $this->_auth->getAuthStorage()->refreshAcl();
143  return $proceed($request);
144  }
_processNotLoggedInUser(\Magento\Framework\App\RequestInterface $request)

Field Documentation

◆ $_actionFlag

$_actionFlag
protected

Definition at line 44 of file Authentication.php.

◆ $_auth

$_auth
protected

Definition at line 18 of file Authentication.php.

◆ $_openActions

$_openActions
protected
Initial value:
= [
'forgotpassword',
'resetpassword',
'resetpasswordpost',
'logout',
'refresh',
]

Definition at line 23 of file Authentication.php.

◆ $_response

$_response
protected

Definition at line 39 of file Authentication.php.

◆ $_url

$_url
protected

Definition at line 34 of file Authentication.php.

◆ $backendAppList

$backendAppList
protected

Definition at line 59 of file Authentication.php.

◆ $backendUrl

$backendUrl
protected

Definition at line 54 of file Authentication.php.

◆ $formKeyValidator

$formKeyValidator
protected

Definition at line 69 of file Authentication.php.

◆ $messageManager

$messageManager
protected

Definition at line 49 of file Authentication.php.

◆ $resultRedirectFactory

$resultRedirectFactory
protected

Definition at line 64 of file Authentication.php.


The documentation for this class was generated from the following file: