Skip to content

Commit f3f15c1

Browse files
committed
MAGETWO-43691: Custom admin path does not work correctly
- initial implementation
1 parent 0d08a72 commit f3f15c1

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

app/code/Magento/Backend/App/Area/FrontNameResolver.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,33 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver
4141
/**
4242
* @param \Magento\Backend\App\Config $config
4343
* @param DeploymentConfig $deploymentConfig
44+
* @param \Magento\Backend\Model\UrlInterface $backendUrl
4445
*/
45-
public function __construct(\Magento\Backend\App\Config $config, DeploymentConfig $deploymentConfig)
46+
public function __construct(
47+
\Magento\Backend\App\Config $config,
48+
DeploymentConfig $deploymentConfig,
49+
\Magento\Backend\Model\UrlInterface $backendUrl
50+
)
4651
{
4752
$this->config = $config;
4853
$this->defaultFrontName = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME);
54+
$this->backendUrl = $backendUrl;
4955
}
5056

5157
/**
5258
* Retrieve area front name
5359
*
60+
* @param string $host If set, verify front name is valid for this url (hostname is correct)
5461
* @return string
5562
*/
56-
public function getFrontName()
63+
public function getFrontName($host = null)
5764
{
65+
if ($host) {
66+
$bu = $this->backendUrl->getBaseUrl();
67+
if (stripos($bu, $host) === false) {
68+
return false;
69+
}
70+
}
5871
$isCustomPathUsed = (bool)(string)$this->config->getValue(self::XML_PATH_USE_CUSTOM_ADMIN_PATH);
5972
if ($isCustomPathUsed) {
6073
return (string)$this->config->getValue(self::XML_PATH_CUSTOM_ADMIN_PATH);

app/code/Magento/Backend/App/Router/NoRouteHandler.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,24 @@ class NoRouteHandler implements \Magento\Framework\App\Router\NoRouteHandlerInte
1919
*/
2020
protected $routeConfig;
2121

22+
/**
23+
* @var \Magento\Backend\Model\UrlInterface
24+
*/
25+
protected $backendUrl;
26+
2227
/**
2328
* @param \Magento\Backend\Helper\Data $helper
2429
* @param \Magento\Framework\App\Route\ConfigInterface $routeConfig
30+
* @param \Magento\Backend\Model\UrlInterface $backendUrl
2531
*/
2632
public function __construct(
2733
\Magento\Backend\Helper\Data $helper,
28-
\Magento\Framework\App\Route\ConfigInterface $routeConfig
34+
\Magento\Framework\App\Route\ConfigInterface $routeConfig,
35+
\Magento\Backend\Model\UrlInterface $backendUrl
2936
) {
3037
$this->helper = $helper;
3138
$this->routeConfig = $routeConfig;
39+
$this->backendUrl = $backendUrl;
3240
}
3341

3442
/**
@@ -43,11 +51,15 @@ public function process(\Magento\Framework\App\RequestInterface $request)
4351
$areaFrontName = array_shift($requestPathParams);
4452

4553
if ($areaFrontName == $this->helper->getAreaFrontName()) {
46-
$moduleName = $this->routeConfig->getRouteFrontName('adminhtml');
47-
$actionNamespace = 'noroute';
48-
$actionName = 'index';
49-
$request->setModuleName($moduleName)->setControllerName($actionNamespace)->setActionName($actionName);
50-
return true;
54+
$baseUrl = $this->backendUrl->getBaseUrl();
55+
if (!stripos($baseUrl, $_SERVER['HTTP_HOST']) === false)
56+
{
57+
$moduleName = $this->routeConfig->getRouteFrontName('adminhtml');
58+
$actionNamespace = 'noroute';
59+
$actionName = 'index';
60+
$request->setModuleName($moduleName)->setControllerName($actionNamespace)->setActionName($actionName);
61+
return true;
62+
}
5163
}
5264
return false;
5365
}

lib/internal/Magento/Framework/App/Area/FrontNameResolverInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ interface FrontNameResolverInterface
1616
/**
1717
* Retrieve front name
1818
*
19-
* @return string
19+
* @param null|string $host If set, only return frontname if it is valid for the host
20+
* @return null|string
2021
*/
21-
public function getFrontName();
22+
public function getFrontName($host = null);
2223
}

lib/internal/Magento/Framework/App/AreaList.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ public function getCodeByFrontName($frontName)
6969
{
7070
foreach ($this->_areas as $areaCode => &$areaInfo) {
7171
if (!isset($areaInfo['frontName']) && isset($areaInfo['frontNameResolver'])) {
72-
$areaInfo['frontName'] = $this->_resolverFactory->create(
73-
$areaInfo['frontNameResolver']
74-
)->getFrontName();
72+
$resolver = $this->_resolverFactory->create($areaInfo['frontNameResolver']);
73+
$areaInfo['frontName'] = $resolver->getFrontName($_SERVER['HTTP_HOST']);
7574
}
7675
if ($areaInfo['frontName'] == $frontName) {
7776
return $areaCode;

0 commit comments

Comments
 (0)