Skip to content

Commit

Permalink
New security suite layer
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Jul 31, 2017
1 parent f5cbb6d commit aa88a17
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Api/RestrictInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

interface RestrictInterface
{
const XML_PATH_ENABLED = 'msp_securitysuite/adminrestriction/enabled';
const XML_PATH_AUTHORIZED_RANGES = 'msp_securitysuite/adminrestriction/authorized_ranges';
const XML_PATH_ENABLED = 'msp_securitysuite_adminrestriction/general/enabled';
const XML_PATH_AUTHORIZED_RANGES = 'msp_securitysuite_adminrestriction/general/authorized_ranges';

/**
* Return true if current user is allowed to access backend
Expand Down
19 changes: 15 additions & 4 deletions Plugin/AppInterfacePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Magento\Framework\AppInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\Response\Http;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\UrlInterface;
use MSP\AdminRestriction\Api\RestrictInterface;
use MSP\SecuritySuiteCommon\Api\LogManagementInterface;
Expand Down Expand Up @@ -61,11 +62,16 @@ class AppInterfacePlugin
* @var RestrictInterface
*/
private $restrict;

/**
* @var UtilsInterface
*/
private $utils;

/**
* @var ObjectManagerInterface
*/
private $objectManager;

public function __construct(
RequestInterface $request,
Expand All @@ -74,7 +80,8 @@ public function __construct(
State $state,
EventInterface $event,
RestrictInterface $restrict,
UtilsInterface $utils
UtilsInterface $utils,
ObjectManagerInterface $objectManager
) {
$this->request = $request;
$this->http = $http;
Expand All @@ -83,6 +90,7 @@ public function __construct(
$this->restrict = $restrict;
$this->event = $event;
$this->utils = $utils;
$this->objectManager = $objectManager;
}

public function aroundLaunch(AppInterface $subject, \Closure $proceed)
Expand All @@ -95,9 +103,12 @@ public function aroundLaunch(AppInterface $subject, \Closure $proceed)
]);

$this->state->setAreaCode('frontend');
$this->http->setRedirect($this->url->getUrl('msp_security_suite/stop', [
'reason' => 'Unauthorized access attempt',
]));

// Must use object manager because a session cannot be activated before setting area
$this->objectManager->get('MSP\SecuritySuiteCommon\Api\SessionInterface')
->setEmergencyStopMessage(__('Unauthorized access attempt'));

$this->http->setRedirect($this->url->getUrl('msp_security_suite/stop'));
return $this->http;
}
}
Expand Down
68 changes: 68 additions & 0 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* MageSpecialist
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category MSP
* @package MSP_AdminRestriction
* @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace MSP\AdminRestriction\Setup;

use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
use MSP\SecuritySuiteCommon\Model\ConfigMigration;

class UpgradeData implements UpgradeDataInterface
{
/**
* @var ConfigMigration
*/
private $configMigration;

public function __construct(
ConfigMigration $configMigration
)
{
$this->configMigration = $configMigration;
}

protected function upgradeTo010200(ModuleDataSetupInterface $setup)
{
$this->configMigration->doConfigMigration(
$setup,
'msp_securitysuite/adminrestriction',
'msp_securitysuite_adminrestriction/general'
);
}

/**
* Upgrades data for a module
*
* @param ModuleDataSetupInterface $setup
* @param ModuleContextInterface $context
* @return void
*/
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();

if (version_compare($context->getVersion(), '1.2.0') < 0) {
$this->upgradeTo010200($setup);
}

$setup->endSetup();
}
}
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"description": "Magento2 Admin IP based restriction - Member of MageSpecialist SecuritySuite",
"require": {
"php": "~7.0.0",
"msp/common": "*",
"msp/security-suite-common": ">=1.0.3",

"msp/security-suite-common": "^1.2",
"magento/magento-composer-installer": "*"
},
"suggest": {
Expand Down
18 changes: 15 additions & 3 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,21 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="msp_securitysuite">
<group id="adminrestriction" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Backend IP Restriction</label>

<section id="msp_securitysuite_adminrestriction" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Backend IP restriction</label>
<tab>msp_securitysuite</tab>
<resource>MSP_SecuritySuite::config</resource>

<group id="general" translate="label" type="text" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General</label>
<comment><![CDATA[
<div class="msp_securitysuite-comment">
This module is a memeber of <strong><a target="_blank" href="https://github.com/magespecialist/m2-MSP_Security_Suite">MageSpecialist Security Suite</a></strong>. <a target="_blank" href="https://github.com/magespecialist/m2-MSP_Security_Suite">Click here</a> to see all the Security Suite modules.<br />
Source code, installation and configuration guide: <a target="_blank" href="https://github.com/magespecialist/m2-MSP_Security_Suite">https://github.com/magespecialist/m2-MSP_Security_Suite</a>.
</div>
]]></comment>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
8 changes: 4 additions & 4 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<msp_securitysuite>
<adminrestriction>
<msp_securitysuite_adminrestriction>
<general>
<enabled>0</enabled>
</adminrestriction>
</msp_securitysuite>
</general>
</msp_securitysuite_adminrestriction>
</default>
</config>
3 changes: 1 addition & 2 deletions etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MSP_AdminRestriction" setup_version="1.0.1">
<module name="MSP_AdminRestriction" setup_version="1.2.0">
<sequence>
<module name="MSP_Common"/>
<module name="MSP_SecuritySuiteCommon"/>
</sequence>
</module>
Expand Down

0 comments on commit aa88a17

Please sign in to comment.