Skip to content

Commit

Permalink
REST API + Fixed _isAllowed
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Oct 22, 2017
1 parent e5370c0 commit 566e0c3
Show file tree
Hide file tree
Showing 50 changed files with 272 additions and 106 deletions.
31 changes: 31 additions & 0 deletions Api/TfaInterface.php
Expand Up @@ -98,4 +98,35 @@ public function getProvidersToActivate($userId);
* @return boolean
*/
public function getProviderIsAllowed($userId, $providerCode);

/**
* Get default provider code
* @param int $userId
* @return string
*/
public function getDefaultProviderCode($userId);

/**
* Set default provider code
* @param int $userId
* @param string $providerCode
* @return boolean
*/
public function setDefaultProviderCode($userId, $providerCode);

/**
* Set providers
* @param int $userId
* @param string $providersCodes
* @return boolean
*/
public function setProvidersCodes($userId, $providersCodes);

/**
* Reset default provider code
* @param int $userId
* @param string $providerCode
* @return boolean
*/
public function resetProviderConfig($userId, $providerCode);
}
3 changes: 3 additions & 0 deletions Block/Provider/Authy/Configure.php
Expand Up @@ -23,6 +23,9 @@
use Magento\Backend\Block\Template;
use MSP\TwoFactorAuth\Model\ResourceModel\Country\CollectionFactory as CountryCollectionFactory;

/**
* @SuppressWarnings(PHPMD.LongVariable)
*/
class Configure extends Template
{
/**
Expand Down
15 changes: 15 additions & 0 deletions Controller/Adminhtml/AbstractAction.php
@@ -0,0 +1,15 @@
<?php
namespace MSP\TwoFactorAuth\Controller\Adminhtml;

abstract class AbstractAction extends \Magento\Backend\App\Action
{
public function dispatch(\Magento\Framework\App\RequestInterface $request)
{
if (!$this->_isAllowed()) {
$this->_response->setStatusHeader(403, '1.1', 'Forbidden');
return $this->_redirect('*/auth/login');
}

return parent::dispatch($request);
}
}
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Authy/Auth.php
Expand Up @@ -25,9 +25,13 @@
use Magento\Framework\View\Result\PageFactory;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Api\UserConfigManagerInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Authy;

class Auth extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Auth extends AbstractAction
{
/**
* @var TfaInterface
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Authy/Authpost.php
Expand Up @@ -28,10 +28,14 @@
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Api\TfaSessionInterface;
use MSP\TwoFactorAuth\Api\TrustedManagerInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Authy;
use Magento\Framework\Event\ManagerInterface as EventInterface;

class Authpost extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Authpost extends AbstractAction
{
/**
* @var TfaInterface
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Authy/Configure.php
Expand Up @@ -25,9 +25,13 @@
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\View\Result\PageFactory;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Authy;

class Configure extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Configure extends AbstractAction
{
/**
* @var PageFactory
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Authy/Configurepost.php
Expand Up @@ -26,9 +26,13 @@
use Magento\Framework\View\Result\PageFactory;
use MSP\SecuritySuiteCommon\Api\SecuritySuiteInterface;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Authy;

class Configurepost extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Configurepost extends AbstractAction
{
/**
* @var PageFactory
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Authy/Onetouch.php
Expand Up @@ -24,9 +24,13 @@
use Magento\Backend\App\Action;
use Magento\Framework\Controller\Result\JsonFactory;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Authy;

class Onetouch extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Onetouch extends AbstractAction
{
/**
* @var Authy
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Authy/Token.php
Expand Up @@ -24,9 +24,13 @@
use Magento\Backend\App\Action;
use Magento\Framework\Controller\Result\JsonFactory;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Authy;

class Token extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Token extends AbstractAction
{
/**
* @var Authy
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Authy/Verify.php
Expand Up @@ -27,9 +27,13 @@
use Magento\Framework\View\Result\PageFactory;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Api\UserConfigManagerInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Authy;

class Verify extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Verify extends AbstractAction
{
/**
* @var PageFactory
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Authy/Verifyonetouch.php
Expand Up @@ -27,10 +27,14 @@
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Api\TfaSessionInterface;
use MSP\TwoFactorAuth\Api\TrustedManagerInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Authy;
use Magento\Framework\Event\ManagerInterface as EventInterface;

class Verifyonetouch extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Verifyonetouch extends AbstractAction
{
/**
* @var Authy
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Authy/Verifypost.php
Expand Up @@ -28,9 +28,13 @@
use MSP\SecuritySuiteCommon\Api\SecuritySuiteInterface;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Api\TfaSessionInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Authy;

class Verifypost extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Verifypost extends AbstractAction
{
/**
* @var PageFactory
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Duo/Auth.php
Expand Up @@ -25,9 +25,13 @@
use Magento\Framework\View\Result\PageFactory;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Api\UserConfigManagerInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\DuoSecurity;

class Auth extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Auth extends AbstractAction
{
/**
* @var TfaInterface
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Duo/Authpost.php
Expand Up @@ -27,10 +27,14 @@
use MSP\SecuritySuiteCommon\Api\SecuritySuiteInterface;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Api\TfaSessionInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\DuoSecurity;
use Magento\Framework\Event\ManagerInterface as EventInterface;

class Authpost extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Authpost extends AbstractAction
{
/**
* @var TfaInterface
Expand Down
3 changes: 2 additions & 1 deletion Controller/Adminhtml/Duo/Configure.php
Expand Up @@ -23,8 +23,9 @@
use Magento\Backend\Model\Auth\Session;
use Magento\Backend\App\Action;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;

class Configure extends Action
class Configure extends AbstractAction
{
/**
* @var TfaInterface
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Google/Auth.php
Expand Up @@ -25,9 +25,13 @@
use Magento\Framework\View\Result\PageFactory;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Api\UserConfigManagerInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Google;

class Auth extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Auth extends AbstractAction
{
/**
* @var TfaInterface
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Google/Authpost.php
Expand Up @@ -28,10 +28,14 @@
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Api\TfaSessionInterface;
use MSP\TwoFactorAuth\Api\TrustedManagerInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Google;
use Magento\Framework\Event\ManagerInterface as EventInterface;

class Authpost extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Authpost extends AbstractAction
{
/**
* @var TfaInterface
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Google/Configure.php
Expand Up @@ -24,9 +24,13 @@
use Magento\Backend\App\Action;
use Magento\Framework\View\Result\PageFactory;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Google;

class Configure extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Configure extends AbstractAction
{
/**
* @var TfaInterface
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Google/Configurepost.php
Expand Up @@ -27,10 +27,14 @@
use MSP\SecuritySuiteCommon\Api\SecuritySuiteInterface;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Api\TfaSessionInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Google;
use Magento\Framework\Event\ManagerInterface as EventInterface;

class Configurepost extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Configurepost extends AbstractAction
{
/**
* @var TfaInterface
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/Google/Qr.php
Expand Up @@ -25,9 +25,13 @@
use Magento\Framework\Controller\Result\Raw;
use Magento\Framework\View\Result\PageFactory;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\Google;

class Qr extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Qr extends AbstractAction
{
/**
* @var TfaInterface
Expand Down
3 changes: 2 additions & 1 deletion Controller/Adminhtml/Tfa/Index.php
Expand Up @@ -25,8 +25,9 @@
use Magento\Framework\Exception\LocalizedException;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Api\UserConfigManagerInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;

class Index extends Action
class Index extends AbstractAction
{
/**
* @var TfaInterface
Expand Down
8 changes: 6 additions & 2 deletions Controller/Adminhtml/Tfa/Reset.php
Expand Up @@ -26,8 +26,12 @@
use Magento\User\Model\UserFactory;
use Magento\User\Model\ResourceModel\User as UserResourceModel;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;

class Reset extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Reset extends AbstractAction
{
/**
* @var UserResourceModel
Expand Down Expand Up @@ -73,7 +77,7 @@ public function execute()
throw new LocalizedException(__('Unknown provider'));
}

$provider->resetConfiguration($user);
$provider->resetConfiguration($user->getId());

$this->messageManager->addSuccessMessage(__('Configuration has been reset for this user'));
return $this->_redirect('adminhtml/user/edit', ['user_id' => $userId]);
Expand Down
3 changes: 2 additions & 1 deletion Controller/Adminhtml/Tfa/Revoke.php
Expand Up @@ -23,8 +23,9 @@
use Magento\Backend\App\Action;
use Magento\Framework\App\ResponseInterface;
use MSP\TwoFactorAuth\Api\TrustedManagerInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;

class Revoke extends Action
class Revoke extends AbstractAction
{
/**
* @var TrustedManagerInterface
Expand Down
6 changes: 5 additions & 1 deletion Controller/Adminhtml/U2f/Auth.php
Expand Up @@ -25,9 +25,13 @@
use Magento\Framework\View\Result\PageFactory;
use MSP\TwoFactorAuth\Api\TfaInterface;
use MSP\TwoFactorAuth\Api\UserConfigManagerInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\U2fKey;

class Auth extends Action
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Auth extends AbstractAction
{
/**
* @var TfaInterface
Expand Down
8 changes: 4 additions & 4 deletions Controller/Adminhtml/U2f/Authpost.php
Expand Up @@ -26,16 +26,16 @@
use MSP\SecuritySuiteCommon\Api\SecuritySuiteInterface;
use MSP\TwoFactorAuth\Api\TfaSessionInterface;
use MSP\TwoFactorAuth\Api\TrustedManagerInterface;
use MSP\TwoFactorAuth\Controller\Adminhtml\AbstractAction;
use MSP\TwoFactorAuth\Model\Provider\Engine\U2fKey;
use MSP\TwoFactorAuth\Model\Tfa;
use Magento\Framework\Event\ManagerInterface as EventInterface;

/**
* Class Authpost
* @package MSP\TwoFactorAuth\Controller\Adminhtml\U2f
* @SuppressWarnings("PHPMD.CouplingBetweenObjects")
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class Authpost extends Action
class Authpost extends AbstractAction
{
/**
* @var Tfa
Expand Down

0 comments on commit 566e0c3

Please sign in to comment.