Skip to content

Commit e7bc266

Browse files
author
Melnikov, Igor(imelnikov)
committed
Merge pull request #466 from magento-extensibility/MAGETWO-50209-get-rid-of-helpers
[Extensibility] MAGETWO-50209: Get rid of Helpers in Password Security Management
2 parents 65186a2 + 605410f commit e7bc266

File tree

143 files changed

+3269
-2933
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+3269
-2933
lines changed

app/bootstrap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
error_reporting(E_ALL);
1111
#ini_set('display_errors', 1);
12-
umask(0);
1312

1413
/* PHP version validation */
1514
if (version_compare(phpversion(), '5.5.0', '<') === true) {

app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,28 @@
1010
use Magento\Framework\Exception\LocalizedException;
1111
use Magento\Framework\Controller\ResultFactory;
1212
use Magento\Framework\Exception\State\UserLockedException;
13+
use Magento\Security\Model\SecurityCookie;
1314

1415
class Save extends \Magento\Backend\Controller\Adminhtml\System\Account
1516
{
1617
/**
17-
* @var \Magento\Security\Helper\SecurityCookie
18+
* @var SecurityCookie
1819
*/
19-
protected $securityCookieHelper;
20+
private $securityCookie;
2021

2122
/**
22-
* @param \Magento\Backend\App\Action\Context $context
23-
* @param \Magento\Security\Helper\SecurityCookie $securityCookieHelper
23+
* Get security cookie
24+
*
25+
* @return SecurityCookie
26+
* @deprecated
2427
*/
25-
public function __construct(
26-
\Magento\Backend\App\Action\Context $context,
27-
\Magento\Security\Helper\SecurityCookie $securityCookieHelper
28-
) {
29-
parent::__construct($context);
30-
$this->securityCookieHelper = $securityCookieHelper;
28+
private function getSecurityCookie()
29+
{
30+
if (!($this->securityCookie instanceof SecurityCookie)) {
31+
return \Magento\Framework\App\ObjectManager::getInstance()->get(SecurityCookie::class);
32+
} else {
33+
return $this->securityCookie;
34+
}
3135
}
3236

3337
/**
@@ -79,7 +83,7 @@ public function execute()
7983
}
8084
} catch (UserLockedException $e) {
8185
$this->_auth->logout();
82-
$this->securityCookieHelper->setLogoutReasonCookie(
86+
$this->getSecurityCookie()->setLogoutReasonCookie(
8387
\Magento\Security\Model\AdminSessionsManager::LOGOUT_REASON_USER_LOCKED
8488
);
8589
} catch (ValidatorException $e) {

app/code/Magento/Backend/i18n/en_US.csv

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ YTD,YTD
206206
"Authentication storage is incorrect.","Authentication storage is incorrect."
207207
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
208208
"Authentication error occurred.","Authentication error occurred."
209+
"Admin session lifetime must be less than or equal to 31536000 seconds (one year)","Admin session lifetime must be less than or equal to 31536000 seconds (one year)"
210+
"Admin session lifetime must be greater than or equal to 60 seconds","Admin session lifetime must be greater than or equal to 60 seconds"
209211
Order,Order
210212
"Order #%1","Order #%1"
211213
"Access denied","Access denied"
@@ -391,7 +393,7 @@ Security,Security
391393
"Add Secret Key to URLs","Add Secret Key to URLs"
392394
"Login is Case Sensitive","Login is Case Sensitive"
393395
"Admin Session Lifetime (seconds)","Admin Session Lifetime (seconds)"
394-
"Values less than 60 are ignored.","Values less than 60 are ignored."
396+
"Please enter at least 60 and at most 31536000 (one year).","Please enter at least 60 and at most 31536000 (one year)."
395397
"Enable Charts","Enable Charts"
396398
Web,Web
397399
"Url Options","Url Options"

app/code/Magento/Backup/Model/Fs/Collection.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ protected function _hideBackupsForApache()
9191
$filename = '.htaccess';
9292
if (!$this->_varDirectory->isFile($filename)) {
9393
$this->_varDirectory->writeFile($filename, 'deny from all');
94-
$this->_varDirectory->changePermissions($filename, 0640);
9594
}
9695
}
9796

app/code/Magento/Captcha/Helper/Data.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ public function getImgDir($website = null)
150150
$mediaDir = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA);
151151
$captchaDir = '/captcha/' . $this->_getWebsiteCode($website);
152152
$mediaDir->create($captchaDir);
153-
$mediaDir->changePermissions($captchaDir, DriverInterface::WRITEABLE_DIRECTORY_MODE);
154-
155153
return $mediaDir->getAbsolutePath($captchaDir) . '/';
156154
}
157155

app/code/Magento/Captcha/Observer/CheckUserEditObserver.php

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
*/
66
namespace Magento\Captcha\Observer;
77

8+
use Magento\Customer\Model\AuthenticationInterface;
89
use Magento\Framework\Event\ObserverInterface;
9-
use Magento\Framework\Exception\NoSuchEntityException;
10-
use Magento\Customer\Helper\AccountManagement as AccountManagementHelper;
1110
use Magento\Customer\Model\Session;
1211
use Magento\Framework\App\Config\ScopeConfigInterface;
13-
use Magento\Customer\Api\CustomerRepositoryInterface;
1412

1513
/**
1614
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -48,58 +46,50 @@ class CheckUserEditObserver implements ObserverInterface
4846
protected $captchaStringResolver;
4947

5048
/**
51-
* Account manager
49+
* Authentication
5250
*
53-
* @var AccountManagementHelper
51+
* @var AuthenticationInterface
5452
*/
55-
protected $accountManagementHelper;
53+
protected $authentication;
5654

5755
/**
5856
* @var Session
5957
*/
60-
protected $session;
58+
protected $customerSession;
6159

6260
/**
6361
* @var ScopeConfigInterface
6462
*/
6563
protected $scopeConfig;
6664

67-
/**
68-
* @var CustomerRepositoryInterface
69-
*/
70-
protected $customerRepository;
71-
7265
/**
7366
* @param \Magento\Captcha\Helper\Data $helper
7467
* @param \Magento\Framework\App\ActionFlag $actionFlag
7568
* @param \Magento\Framework\Message\ManagerInterface $messageManager
7669
* @param \Magento\Framework\App\Response\RedirectInterface $redirect
7770
* @param CaptchaStringResolver $captchaStringResolver
78-
* @param AccountManagementHelper $accountManagementHelper
71+
* @param AuthenticationInterface $authentication
7972
* @param Session $customerSession
8073
* @param ScopeConfigInterface $scopeConfig
81-
* @param CustomerRepositoryInterface $customerRepository
8274
*/
8375
public function __construct(
8476
\Magento\Captcha\Helper\Data $helper,
8577
\Magento\Framework\App\ActionFlag $actionFlag,
8678
\Magento\Framework\Message\ManagerInterface $messageManager,
8779
\Magento\Framework\App\Response\RedirectInterface $redirect,
8880
CaptchaStringResolver $captchaStringResolver,
89-
AccountManagementHelper $accountManagementHelper,
81+
AuthenticationInterface $authentication,
9082
Session $customerSession,
91-
ScopeConfigInterface $scopeConfig,
92-
CustomerRepositoryInterface $customerRepository
83+
ScopeConfigInterface $scopeConfig
9384
) {
9485
$this->helper = $helper;
9586
$this->actionFlag = $actionFlag;
9687
$this->messageManager = $messageManager;
9788
$this->redirect = $redirect;
9889
$this->captchaStringResolver = $captchaStringResolver;
99-
$this->accountManagementHelper = $accountManagementHelper;
90+
$this->authentication = $authentication;
10091
$this->customerSession = $customerSession;
10192
$this->scopeConfig = $scopeConfig;
102-
$this->customerRepository = $customerRepository;
10393
}
10494

10595
/**
@@ -120,14 +110,17 @@ public function execute(\Magento\Framework\Event\Observer $observer)
120110
self::FORM_ID
121111
)
122112
)) {
123-
try {
124-
$customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
125-
$this->accountManagementHelper->processCustomerLockoutData($customer->getId());
126-
$this->customerRepository->save($customer);
127-
} catch (NoSuchEntityException $e) {
128-
//do nothing as customer existance is validated later in authenticate method
113+
$customerId = $this->customerSession->getCustomerId();
114+
$this->authentication->processAuthenticationFailure($customerId);
115+
if ($this->authentication->isLocked($customerId)) {
116+
$this->customerSession->logout();
117+
$this->customerSession->start();
118+
$message = __(
119+
'The account is locked. Please wait and try again or contact %1.',
120+
$this->scopeConfig->getValue('contact/email/recipient_email')
121+
);
122+
$this->messageManager->addError($message);
129123
}
130-
$this->workWithLock();
131124
$this->messageManager->addError(__('Incorrect CAPTCHA'));
132125
$this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
133126
$this->redirect->redirect($controller->getResponse(), '*/*/edit');
@@ -140,24 +133,4 @@ public function execute(\Magento\Framework\Event\Observer $observer)
140133

141134
return $this;
142135
}
143-
144-
/**
145-
* Logout a user if it is locked
146-
*
147-
* @throws \Magento\Framework\Exception\SessionException
148-
* @return void
149-
*/
150-
protected function workWithLock()
151-
{
152-
$customerModel = $this->customerSession->getCustomer();
153-
if ($customerModel->isCustomerLocked()) {
154-
$this->customerSession->logout();
155-
$this->customerSession->start();
156-
$message = __(
157-
'The account is locked. Please wait and try again or contact %1.',
158-
$this->scopeConfig->getValue('contact/email/recipient_email')
159-
);
160-
$this->messageManager->addError($message);
161-
}
162-
}
163136
}

app/code/Magento/Captcha/Observer/CheckUserLoginObserver.php

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*/
66
namespace Magento\Captcha\Observer;
77

8+
use Magento\Customer\Model\AuthenticationInterface;
89
use Magento\Framework\Event\ObserverInterface;
910
use Magento\Framework\Exception\NoSuchEntityException;
10-
use Magento\Customer\Helper\AccountManagement as AccountManagementHelper;
1111
use Magento\Customer\Api\CustomerRepositoryInterface;
1212

1313
/**
@@ -53,11 +53,11 @@ class CheckUserLoginObserver implements ObserverInterface
5353
protected $customerRepository;
5454

5555
/**
56-
* Account manager
56+
* Authentication
5757
*
58-
* @var AccountManagementHelper
58+
* @var AuthenticationInterface
5959
*/
60-
protected $accountManagementHelper;
60+
protected $authentication;
6161

6262
/**
6363
* @param \Magento\Captcha\Helper\Data $helper
@@ -83,25 +83,10 @@ public function __construct(
8383
$this->_customerUrl = $customerUrl;
8484
}
8585

86-
/**
87-
* Set email notification
88-
*
89-
* @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
90-
* @return void
91-
* @deprecated
92-
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
93-
*/
94-
private function setCustomerRepository(\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository)
95-
{
96-
97-
$this->customerRepository = $customerRepository;
98-
}
99-
10086
/**
10187
* Get customer repository
10288
*
10389
* @return \Magento\Customer\Api\CustomerRepositoryInterface
104-
* @deprecated
10590
*/
10691
private function getCustomerRepository()
10792
{
@@ -116,39 +101,24 @@ private function getCustomerRepository()
116101
}
117102

118103
/**
119-
* Set account management helper
120-
*
121-
* @param AccountManagementHelper $accountManagementHelper
122-
* @return void
123-
* @deprecated
124-
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
125-
*/
126-
private function setAccountManagementHelper(AccountManagementHelper $accountManagementHelper)
127-
{
128-
129-
$this->accountManagementHelper = $accountManagementHelper;
130-
}
131-
132-
/**
133-
* Get account management helper
104+
* Get authentication
134105
*
135-
* @return AccountManagementHelper
136-
* @deprecated
106+
* @return AuthenticationInterface
137107
*/
138-
private function getAccountManagementHelper()
108+
private function getAuthentication()
139109
{
140110

141-
if (!($this->accountManagementHelper instanceof \Magento\Customer\Helper\AccountManagement)) {
111+
if (!($this->authentication instanceof AuthenticationInterface)) {
142112
return \Magento\Framework\App\ObjectManager::getInstance()->get(
143-
'Magento\Customer\Helper\AccountManagement'
113+
AuthenticationInterface::class
144114
);
145115
} else {
146-
return $this->accountManagementHelper;
116+
return $this->authentication;
147117
}
148118
}
149119

150120
/**
151-
* Check Captcha On User Login Page
121+
* Check captcha on user login page
152122
*
153123
* @param \Magento\Framework\Event\Observer $observer
154124
* @throws NoSuchEntityException
@@ -168,8 +138,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
168138
if (!$captchaModel->isCorrect($word)) {
169139
try {
170140
$customer = $this->getCustomerRepository()->get($login);
171-
$this->getAccountManagementHelper()->processCustomerLockoutData($customer->getId());
172-
$this->getCustomerRepository()->save($customer);
141+
$this->getAuthentication()->processAuthenticationFailure($customer->getId());
173142
} catch (NoSuchEntityException $e) {
174143
//do nothing as customer existance is validated later in authenticate method
175144
}

0 commit comments

Comments
 (0)