Skip to content

Commit

Permalink
Initial commit v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Rus0 committed Aug 6, 2020
1 parent af170e9 commit 77a94e1
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 0 deletions.
19 changes: 19 additions & 0 deletions COPYING.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright © 2020-present Wolfsellers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions Model/ControllerActionPredispatch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace WolfSellers\EnableDisableTfa\Model;

use Magento\TwoFactorAuth\TestFramework\ControllerActionPredispatch as MagentoControllerActionPredispatch;

class ControllerActionPredispatch extends MagentoControllerActionPredispatch
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright © Wolfsellers All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace WolfSellers\EnableDisableTfa\Plugin\Backend\Magento\TwoFactorAuth\Observer;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Event\Observer;
use Magento\TwoFactorAuth\Observer\ControllerActionPredispatch as MagentoControllerActionPredispatch;

class ControllerActionPredispatch
{
const TWOFACTOR_AUTH_ENABLED = "twofactorauth/general/enabled";

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* ControllerActionPredispatch constructor.
* @param ScopeConfigInterface $scopeConfig
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(
ScopeConfigInterface $scopeConfig
) {

$this->scopeConfig = $scopeConfig;
}

public function aroundExecute(
MagentoControllerActionPredispatch $subject,
callable $proceed,
Observer $observer
) {
if($this->scopeConfig->isSetFlag(self::TWOFACTOR_AUTH_ENABLED)) {
$proceed($observer);
}
}
}

36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Magento 2 Module WolfSellers Enable Disable 2FA

- [Main Functionalities](#markdown-header-main-functionalities)
- [Installation](#markdown-header-installation)
- [Tested](#markdown-header-tested)


## Main Functionalities
Adds enable disable feature switch for the Two-factor Authorization for Magento 2.4

It can be configured in `Stores > Configuration > 2FA > General > Enabled` by default is set to no, so the admin can be used.
Change it back in production.

## Installation

### 1. Composer (recommended)

- Install the module composer by running `composer require wolfsellers/module-enabledisabletfa`
- Enable the module by running `php bin/magento module:enable WolfSellers_EnableDisableTfa`
- Apply database updates by running `php bin/magento setup:upgrade`
- Flush the cache by running `php bin/magento cache:flush`

### 2. Download zip (not recommended)

- Download the zip file from github
- Extract the files in `app/code/WolfSellers/EnableDisableTfa/`
- Enable the module by running `php bin/magento module:enable WolfSellers_EnableDisableTfa`
- Apply database updates by running `php bin/magento setup:upgrade`
- Flush the cache by running `php bin/magento cache:flush`

## Tested

Tested in Magento 2.4.0, versions:
- Community
- Enterprise
- Cloud
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "wolfsellers/module-enabledisabletfa",
"description": "Adds enable disable switch for the Two-factor Authorization",
"type": "magento2-module",
"license": "MIT",
"version": "1.0.0",
"authors": [
{
"name": "Rus0",
"email": "[email protected]",
"homepage": "https://wolfsellers.com"
}
],
"minimum-stability": "dev",
"require": {
"magento/module-two-factor-auth": "^1.0.*"
},
"autoload": {
"psr-4": {
"WolfSellers\\EnableDisableTfa\\": ""
},
"files": [
"registration.php"
]
}
}
8 changes: 8 additions & 0 deletions etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\TwoFactorAuth\Observer\ControllerActionPredispatch">
<plugin name="WolfSellers_EnableDisableTfa_Plugin_Backend_Magento_TwoFactorAuth_Observer_ControllerActionPredispatch"
disabled="false" sortOrder="0"
type="WolfSellers\EnableDisableTfa\Plugin\Backend\Magento\TwoFactorAuth\Observer\ControllerActionPredispatch"/>
</type>
</config>
16 changes: 16 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="twofactorauth">
<tab>security</tab>
<resource>Magento_TwoFactorAuth::config</resource>
<group id="general">
<field id="enabled" showInDefault="1" showInStore="0" showInWebsite="0" sortOrder="0" translate="label" type="select">
<label>Enabled</label>
<comment>Enables/Disables Two-factor authorization</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
10 changes: 10 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<twofactorauth>
<general>
<enabled>0</enabled>
</general>
</twofactorauth>
</default>
</config>
4 changes: 4 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\TwoFactorAuth\TestFramework\ControllerActionPredispatch" type="WolfSellers\EnableDisableTfa\Model\ControllerActionPredispatch" />
</config>
8 changes: 8 additions & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="WolfSellers_EnableDisableTfa">
<sequence>
<module name="Magento_TwoFactorAuth"/>
</sequence>
</module>
</config>
9 changes: 9 additions & 0 deletions registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Wolfsellers All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'WolfSellers_EnableDisableTfa', __DIR__);

0 comments on commit 77a94e1

Please sign in to comment.