Skip to content

Commit 8dcfe83

Browse files
author
Cari Spruiell
committed
Merge branches 'MAGETWO-34695-Admin-Login' and 'develop' of github.scm.corp.ebay.com:magento-api/magento2ce into develop
Conflicts: app/code/Magento/Backend/etc/di.xml
2 parents 5b69b87 + 882a1c1 commit 8dcfe83

File tree

11 files changed

+341
-9
lines changed

11 files changed

+341
-9
lines changed

app/code/Magento/Backend/App/Action/Plugin/Authentication.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,49 @@ class Authentication
4545
*/
4646
protected $messageManager;
4747

48+
/**
49+
* @var \Magento\Backend\Model\UrlInterface
50+
*/
51+
protected $backendUrl;
52+
53+
/**
54+
* @var \Magento\Backend\App\BackendAppList
55+
*/
56+
protected $backendAppList;
57+
58+
/**
59+
* @var \Magento\Framework\Controller\Result\RedirectFactory
60+
*/
61+
protected $resultRedirectFactory;
62+
4863
/**
4964
* @param \Magento\Backend\Model\Auth $auth
5065
* @param \Magento\Backend\Model\UrlInterface $url
5166
* @param \Magento\Framework\App\ResponseInterface $response
5267
* @param \Magento\Framework\App\ActionFlag $actionFlag
5368
* @param \Magento\Framework\Message\ManagerInterface $messageManager
69+
* @param \Magento\Backend\Model\UrlInterface $backendUrl
70+
* @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory
71+
* @param \Magento\Backend\App\BackendAppList $backendAppList
5472
*/
5573
public function __construct(
5674
\Magento\Backend\Model\Auth $auth,
5775
\Magento\Backend\Model\UrlInterface $url,
5876
\Magento\Framework\App\ResponseInterface $response,
5977
\Magento\Framework\App\ActionFlag $actionFlag,
60-
\Magento\Framework\Message\ManagerInterface $messageManager
78+
\Magento\Framework\Message\ManagerInterface $messageManager,
79+
\Magento\Backend\Model\UrlInterface $backendUrl,
80+
\Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory,
81+
\Magento\Backend\App\BackendAppList $backendAppList
6182
) {
6283
$this->_auth = $auth;
6384
$this->_url = $url;
6485
$this->_response = $response;
6586
$this->_actionFlag = $actionFlag;
6687
$this->messageManager = $messageManager;
88+
$this->backendUrl = $backendUrl;
89+
$this->resultRedirectFactory = $resultRedirectFactory;
90+
$this->backendAppList = $backendAppList;
6791
}
6892

6993
/**
@@ -90,6 +114,18 @@ public function aroundDispatch(
90114
$this->_processNotLoggedInUser($request);
91115
} else {
92116
$this->_auth->getAuthStorage()->prolong();
117+
118+
$backendApp = null;
119+
if ($request->getParam('app')) {
120+
$backendApp = $this->backendAppList->getCurrentApp();
121+
}
122+
123+
if ($backendApp) {
124+
$resultRedirect = $this->resultRedirectFactory->create();
125+
$baseUrl = \Magento\Framework\App\Request\Http::getUrlNoScript($this->backendUrl->getBaseUrl());
126+
$baseUrl = $baseUrl . $backendApp->getStartupPage();
127+
return $resultRedirect->setUrl($baseUrl);
128+
}
93129
}
94130
}
95131
$this->_auth->getAuthStorage()->refreshAcl();
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\App;
8+
9+
/**
10+
* Backend Application which uses Magento Backend authentication process
11+
*/
12+
class BackendApp
13+
{
14+
/**
15+
* @var null
16+
*/
17+
private $cookiePath;
18+
19+
/**
20+
* @var null
21+
*/
22+
private $startupPage;
23+
24+
/**
25+
* @var null
26+
*/
27+
private $aclResourceName;
28+
29+
/**
30+
* @param string $cookiePath
31+
* @param string $startupPage
32+
* @param string $aclResourceName
33+
*/
34+
public function __construct(
35+
$cookiePath,
36+
$startupPage,
37+
$aclResourceName
38+
) {
39+
$this->cookiePath = $cookiePath;
40+
$this->startupPage = $startupPage;
41+
$this->aclResourceName = $aclResourceName;
42+
}
43+
44+
/**
45+
* Cookie path for the application to set cookie to
46+
*
47+
* @return string
48+
*/
49+
public function getCookiePath()
50+
{
51+
return $this->cookiePath;
52+
}
53+
54+
/**
55+
* Startup Page of the application to redirect after login
56+
*
57+
* @return string
58+
*/
59+
public function getStartupPage()
60+
{
61+
return $this->startupPage;
62+
}
63+
64+
/**
65+
* ACL resource name to authorize access to
66+
*
67+
* @return string
68+
*/
69+
public function getAclResource()
70+
{
71+
return $this->aclResourceName;
72+
}
73+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\App;
8+
9+
/**
10+
* List of Backend Applications to allow injection of them through the DI
11+
*/
12+
class BackendAppList
13+
{
14+
/**
15+
* @var BackendApp[]
16+
*/
17+
private $backendApps = [];
18+
19+
/**
20+
* @var \Magento\Framework\App\RequestInterface
21+
*/
22+
private $request;
23+
24+
/**
25+
* @param \Magento\Framework\App\Request\Http $request
26+
* @param array $backendApps
27+
*/
28+
public function __construct(
29+
\Magento\Framework\App\Request\Http $request,
30+
array $backendApps = []
31+
) {
32+
$this->backendApps = $backendApps;
33+
$this->request = $request;
34+
}
35+
36+
/**
37+
* Get Backend app based on its name
38+
*
39+
* @return BackendApp|null
40+
*/
41+
public function getCurrentApp()
42+
{
43+
$appName = $this->request->getQuery('app');
44+
if ($appName && isset($this->backendApps[$appName])) {
45+
return $this->backendApps[$appName];
46+
}
47+
}
48+
49+
/**
50+
* Retrieve backend application by name
51+
*
52+
* @param string $appName
53+
* @return BackendApp|null
54+
*/
55+
public function getBackendApp($appName)
56+
{
57+
if (isset($this->backendApps[$appName])) {
58+
return $this->backendApps[$appName];
59+
}
60+
return null;
61+
}
62+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Controller\Adminhtml\BackendApp;
7+
8+
use Magento\Backend\App\AbstractAction;
9+
10+
/**
11+
* Controller which handles authentication of backend app and redirects back to set cookie with backend app path
12+
*/
13+
class Redirect extends AbstractAction
14+
{
15+
/**
16+
* Array of actions which can be processed without secret key validation
17+
*
18+
* @var array
19+
*/
20+
protected $_publicActions = ['redirect'];
21+
22+
/**
23+
* @var \Magento\Backend\App\BackendAppList|null
24+
*/
25+
private $backendAppList;
26+
27+
/**
28+
* @param \Magento\Backend\App\Action\Context $context
29+
* @param \Magento\Backend\App\BackendAppList $backendAppList
30+
*/
31+
public function __construct(
32+
\Magento\Backend\App\Action\Context $context,
33+
\Magento\Backend\App\BackendAppList $backendAppList
34+
) {
35+
parent::__construct($context);
36+
$this->backendAppList = $backendAppList;
37+
}
38+
39+
/**
40+
* @return \Magento\Framework\Controller\ResultInterface
41+
*/
42+
public function execute()
43+
{
44+
$resultRedirect = $this->resultRedirectFactory->create();
45+
if ($this->getRequest()->getParam('app')) {
46+
$url = $this->getUrl('*/*/*', []) . '?app=' . $this->getRequest()->getParam('app');
47+
return $resultRedirect->setUrl($url);
48+
}
49+
return $resultRedirect->setUrl($this->getUrl('*/index/index'));
50+
}
51+
52+
/**
53+
* @return bool
54+
*/
55+
protected function _isAllowed()
56+
{
57+
$backendApp = $this->backendAppList->getBackendApp(
58+
$this->getRequest()->getParam('app')
59+
);
60+
if ($backendApp) {
61+
return $this->_authorization->isAllowed($backendApp->getAclResource());
62+
}
63+
return true;
64+
}
65+
}

app/code/Magento/Backend/Model/Session/AdminConfig.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ class AdminConfig extends Config
3434
*/
3535
protected $_storeManager;
3636

37+
/**
38+
* @var \Magento\Backend\App\BackendAppList
39+
*/
40+
private $backendAppList;
41+
3742
/**
3843
* @param \Magento\Framework\ValidatorFactory $validatorFactory
3944
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
4045
* @param \Magento\Framework\Stdlib\String $stringHelper
4146
* @param \Magento\Framework\App\RequestInterface $request
47+
* @param \Magento\Backend\App\BackendAppList $backendAppList
4248
* @param Filesystem $filesystem
4349
* @param DeploymentConfig $deploymentConfig
4450
* @param string $scopeType
@@ -53,6 +59,7 @@ public function __construct(
5359
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
5460
\Magento\Framework\Stdlib\String $stringHelper,
5561
\Magento\Framework\App\RequestInterface $request,
62+
\Magento\Backend\App\BackendAppList $backendAppList,
5663
Filesystem $filesystem,
5764
DeploymentConfig $deploymentConfig,
5865
$scopeType,
@@ -71,9 +78,9 @@ public function __construct(
7178
$scopeType,
7279
$lifetimePath
7380
);
74-
7581
$this->_frontNameResolver = $frontNameResolver;
7682
$this->_storeManager = $storeManager;
83+
$this->backendAppList = $backendAppList;
7784
$adminPath = $this->extractAdminPath();
7885
$this->setCookiePath($adminPath);
7986
$this->setName($sessionName);
@@ -86,10 +93,17 @@ public function __construct(
8693
*/
8794
private function extractAdminPath()
8895
{
89-
$parsedUrl = parse_url($this->_storeManager->getStore()->getBaseUrl());
90-
$baseUrl = $parsedUrl['path'];
91-
$adminPath = $this->_frontNameResolver->getFrontName();
92-
93-
return $baseUrl . $adminPath;
96+
$backendApp = $this->backendAppList->getCurrentApp();
97+
$cookiePath = null;
98+
$baseUrl = $parsedUrl = parse_url($this->_storeManager->getStore()->getBaseUrl(), PHP_URL_PATH);
99+
if (!$backendApp) {
100+
$cookiePath = $baseUrl . $this->_frontNameResolver->getFrontName();
101+
return $cookiePath;
102+
}
103+
//In case of application authenticating through the admin login, the script name should be removed
104+
//from the path, because application has own script.
105+
$baseUrl = \Magento\Framework\App\Request\Http::getUrlNoScript($baseUrl);
106+
$cookiePath = $baseUrl . $backendApp->getCookiePath();
107+
return $cookiePath;
94108
}
95109
}

app/code/Magento/Backend/etc/acl.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
</resource>
3939
<resource id="Magento_Backend::tools" title="Tools" sortOrder="50">
4040
<resource id="Magento_Backend::cache" title="Cache Management" sortOrder="10" />
41+
<resource id="Magento_Backend::setup_wizard" title="Web Setup Wizard" sortOrder="20" />
4142
</resource>
4243
<resource id="Magento_Backend::system_other_settings" title="Other Settings" sortOrder="80" />
4344
</resource>

app/code/Magento/Backend/etc/adminhtml/menu.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
<add id="Magento_Backend::stores_attributes" title="Attributes" module="Magento_Backend" sortOrder="40" parent="Magento_Backend::stores" resource="Magento_Backend::stores_attributes"/>
2828
<add id="Magento_Backend::other_settings" title="Other Settings" module="Magento_Backend" sortOrder="50" parent="Magento_Backend::stores" resource="Magento_Backend::stores_other_settings"/>
2929
<add id="Magento_Backend::system_other_settings" title="Other Settings" module="Magento_Backend" sortOrder="80" parent="Magento_Backend::system" resource="Magento_Backend::system_other_settings"/>
30+
<add id="Magento_Backend::setup_wizard" action="adminhtml/backendapp/redirect/app/setup" title="Web Setup Wizard" module="Magento_Backend" sortOrder="80" parent="Magento_Backend::system_tools" resource="Magento_Backend::setup_wizard"/>
3031
</menu>
3132
</config>

app/code/Magento/Backend/etc/di.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,18 @@
160160
</argument>
161161
</arguments>
162162
</type>
163+
<virtualType name="Magento\Setup\BackendApp" type="Magento\Backend\App\BackendApp">
164+
<arguments>
165+
<argument name="cookiePath" xsi:type="string">setup</argument>
166+
<argument name="startupPage" xsi:type="string">setup</argument>
167+
<argument name="aclResourceName" xsi:type="string">Magento_Backend::setup_wizard</argument>
168+
</arguments>
169+
</virtualType>
170+
<type name="Magento\Backend\App\BackendAppList">
171+
<arguments>
172+
<argument name="backendApps" xsi:type="array">
173+
<item name="setup" xsi:type="object">Magento\Setup\BackendApp</item>
174+
</argument>
175+
</arguments>
176+
</type>
163177
</config>

lib/internal/Magento/Framework/App/Request/Http.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,25 @@ public static function getDistroBaseUrlPath($server)
345345
return $result;
346346
}
347347

348+
/**
349+
* Return url with no script name
350+
*
351+
* @param string $url
352+
* @return string
353+
*/
354+
public static function getUrlNoScript($url)
355+
{
356+
if (!isset($_SERVER['SCRIPT_NAME'])) {
357+
return $url;
358+
}
359+
360+
if (($pos = strripos($url, basename($_SERVER['SCRIPT_NAME']))) !== false) {
361+
$url = substr($url, 0, $pos);
362+
}
363+
364+
return $url;
365+
}
366+
348367
/**
349368
* Retrieve full action name
350369
*

0 commit comments

Comments
 (0)