Skip to content

Commit ae08dad

Browse files
committed
move changes out of user and into security (#22833: Short-term admin accounts)
1 parent a6511f5 commit ae08dad

File tree

12 files changed

+10
-278
lines changed

12 files changed

+10
-278
lines changed

app/code/Magento/User/Api/Data/UserInterface.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,4 @@ public function getInterfaceLocale();
162162
* @return $this
163163
*/
164164
public function setInterfaceLocale($interfaceLocale);
165-
166-
/**
167-
* Get user expiration date.
168-
*
169-
* @return string
170-
*/
171-
public function getExpiresAt();
172-
173-
/**
174-
* Set user expiration date.
175-
*
176-
* @param string $expiresAt
177-
* @return $this
178-
*/
179-
public function setExpiresAt($expiresAt);
180165
}

app/code/Magento/User/Block/User/Edit/Tab/Main.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected function _prepareForm()
169169
]
170170
);
171171
}
172-
172+
// TODO: use store time and convert to GMT
173173
$baseFieldset->addField(
174174
'expires_at',
175175
'date',

app/code/Magento/User/Cron/DisableExpiredUsers.php

Lines changed: 0 additions & 68 deletions
This file was deleted.

app/code/Magento/User/Model/ResourceModel/User/Collection.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
1515
{
16-
1716
/**
1817
* Define resource model
1918
*
@@ -28,6 +27,7 @@ protected function _construct()
2827
* Collection Init Select
2928
*
3029
* @return $this
30+
* @since 101.1.0
3131
*/
3232
protected function _initSelect()
3333
{
@@ -42,22 +42,4 @@ protected function _initSelect()
4242
['role_name']
4343
);
4444
}
45-
46-
/**
47-
* Filter for expired, active users.
48-
*
49-
* @param string $now
50-
* @return $this
51-
*/
52-
public function addActiveExpiredUsersFilter($now = null)
53-
{
54-
if ($now === null) {
55-
$now = new \DateTime();
56-
$now->format('Y-m-d H:i:s');
57-
}
58-
$this->addFieldToFilter('expires_at', ['lt' => $now])
59-
->addFieldToFilter('is_active', 1);
60-
61-
return $this;
62-
}
6345
}

app/code/Magento/User/Model/User.php

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ class User extends AbstractModel implements StorageInterface, UserInterface
115115
protected $_encryptor;
116116

117117
/**
118-
* @deprecated
118+
* @deprecated 101.1.0
119119
*/
120120
protected $_transportBuilder;
121121

122122
/**
123-
* @deprecated
123+
* @deprecated 101.1.0
124124
*/
125125
protected $_storeManager;
126126

@@ -140,7 +140,7 @@ class User extends AbstractModel implements StorageInterface, UserInterface
140140
private $notificator;
141141

142142
/**
143-
* @deprecated
143+
* @deprecated 101.1.0
144144
*/
145145
private $deploymentConfig;
146146

@@ -212,14 +212,9 @@ protected function _construct()
212212
* Removing dependencies and leaving only entity's properties.
213213
*
214214
* @return string[]
215-
*
216-
* @SuppressWarnings(PHPMD.SerializationAware)
217-
* @deprecated Do not use PHP serialization.
218215
*/
219216
public function __sleep()
220217
{
221-
trigger_error('Using PHP serialization is deprecated', E_USER_DEPRECATED);
222-
223218
$properties = parent::__sleep();
224219
return array_diff(
225220
$properties,
@@ -245,14 +240,9 @@ public function __sleep()
245240
* Restoring required objects after serialization.
246241
*
247242
* @return void
248-
*
249-
* @SuppressWarnings(PHPMD.SerializationAware)
250-
* @deprecated Do not use PHP serialization.
251243
*/
252244
public function __wakeup()
253245
{
254-
trigger_error('Using PHP serialization is deprecated', E_USER_DEPRECATED);
255-
256246
parent::__wakeup();
257247
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
258248
$this->serializer = $objectManager->get(Json::class);
@@ -322,10 +312,6 @@ protected function _getValidationRulesBeforeSave()
322312
$this->validationRules->addPasswordConfirmationRule($validator, $this->getPasswordConfirmation());
323313
}
324314
}
325-
326-
if (!empty($this->getExpiresAt())) {
327-
$this->validationRules->addExpiresAtRule($validator);
328-
}
329315
return $validator;
330316
}
331317

@@ -420,10 +406,6 @@ public function getRoles()
420406
*/
421407
public function getRole()
422408
{
423-
if ($this->getData('extracted_role')) {
424-
$this->_role = $this->getData('extracted_role');
425-
$this->unsetData('extracted_role');
426-
}
427409
if (null === $this->_role) {
428410
$this->_role = $this->_roleFactory->create();
429411
$roles = $this->getRoles();
@@ -459,7 +441,7 @@ public function roleUserExists()
459441
/**
460442
* Send email with reset password confirmation link.
461443
*
462-
* @deprecated
444+
* @deprecated 101.1.0
463445
* @see NotificatorInterface::sendForgotPassword()
464446
*
465447
* @return $this
@@ -539,7 +521,7 @@ protected function createChangesDescriptionString()
539521
* @throws NotificationExceptionInterface
540522
* @return $this
541523
* @since 100.1.0
542-
* @deprecated
524+
* @deprecated 101.1.0
543525
* @see NotificatorInterface::sendUpdated()
544526
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
545527
*/
@@ -921,22 +903,6 @@ public function setInterfaceLocale($interfaceLocale)
921903
return $this->setData('interface_locale', $interfaceLocale);
922904
}
923905

924-
/**
925-
* @inheritDoc
926-
*/
927-
public function getExpiresAt()
928-
{
929-
return $this->_getData('expires_at');
930-
}
931-
932-
/**
933-
* @inheritDoc
934-
*/
935-
public function setExpiresAt($expiresAt)
936-
{
937-
return $this->setData('expires_at', $expiresAt);
938-
}
939-
940906
/**
941907
* Security check for admin user
942908
*

app/code/Magento/User/Model/UserValidationRules.php

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66

77
namespace Magento\User\Model;
88

9-
use Magento\User\Model\Validator\ExpiresAt;
109
use Magento\Framework\Validator\EmailAddress;
1110
use Magento\Framework\Validator\NotEmpty;
1211
use Magento\Framework\Validator\Regex;
1312
use Magento\Framework\Validator\StringLength;
14-
use Magento\Framework\App\ObjectManager;
1513

1614
/**
1715
* Class for adding validation rules to an Admin user
@@ -25,20 +23,6 @@ class UserValidationRules
2523
* Minimum length of admin password
2624
*/
2725
const MIN_PASSWORD_LENGTH = 7;
28-
/**
29-
* @var Validator\ExpiresAt|null
30-
*/
31-
private $expiresValiator;
32-
33-
/**
34-
* UserValidationRules constructor.
35-
* @param Validator\ExpiresAt|null $expiresValiator
36-
*/
37-
public function __construct(?ExpiresAt $expiresValiator = null)
38-
{
39-
$this->expiresValiator = $expiresValiator
40-
?: ObjectManager::getInstance()->get(ExpiresAt::class);
41-
}
4226

4327
/**
4428
* Adds validation rule for user first name, last name, username and email
@@ -141,36 +125,4 @@ public function addPasswordConfirmationRule(
141125
$validator->addRule($passwordConfirmation, 'password');
142126
return $validator;
143127
}
144-
145-
/**
146-
* Adds validation rule for expiration date.
147-
*
148-
* @param \Magento\Framework\Validator\DataObject $validator
149-
* @return \Magento\Framework\Validator\DataObject
150-
* @throws \Zend_Validate_Exception
151-
*/
152-
public function addExpiresAtRule(\Magento\Framework\Validator\DataObject $validator)
153-
{
154-
$dateValidator = new \Zend_Validate_Date(
155-
[
156-
'format' => \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT,
157-
]
158-
);
159-
$dateValidator->setMessage(
160-
__('"Expiration date" invalid type entered.'),
161-
\Zend_Validate_Date::INVALID
162-
);
163-
$dateValidator->setMessage(
164-
__('"Expiration date" is not a valid date.'),
165-
\Zend_Validate_Date::INVALID_DATE
166-
);
167-
$dateValidator->setMessage(
168-
__('"Expiration date" does not fit the required date format.'),
169-
\Zend_Validate_Date::FALSEFORMAT
170-
);
171-
$validator->addRule($dateValidator, 'expires_at');
172-
$validator->addRule($this->expiresValiator, 'expires_at');
173-
174-
return $validator;
175-
}
176128
}

app/code/Magento/User/Test/Unit/Model/UserValidationRulesTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77

88
use Magento\User\Model\UserValidationRules;
99

10-
/**
11-
* Class UserValidationRulesTest
12-
*
13-
* @package Magento\User\Test\Unit\Model
14-
*/
1510
class UserValidationRulesTest extends \PHPUnit\Framework\TestCase
1611
{
1712
/**
@@ -47,10 +42,4 @@ public function testAddPasswordConfirmationRule()
4742
$this->validator->expects($this->once())->method('addRule')->willReturn($this->validator);
4843
$this->assertSame($this->validator, $this->rules->addPasswordConfirmationRule($this->validator, ''));
4944
}
50-
51-
public function testAddExpiresAtRule()
52-
{
53-
$this->validator->expects($this->atMost(2))->method('addRule')->willReturn($this->validator);
54-
$this->assertSame($this->validator, $this->rules->addExpiresAtRule($this->validator));
55-
}
5645
}

app/code/Magento/User/etc/crontab.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/code/Magento/User/etc/db_schema.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@
3636
default="0" comment="Failure Number"/>
3737
<column xsi:type="timestamp" name="first_failure" on_update="false" nullable="true" comment="First Failure"/>
3838
<column xsi:type="timestamp" name="lock_expires" on_update="false" nullable="true"
39-
comment="Expiration Lock Date"/>
40-
<column xsi:type="timestamp" name="expires_at" on_update="false" nullable="true"
41-
comment="User Expiration Date"/>
39+
comment="Expiration Lock Dates"/>
4240
<constraint xsi:type="primary" referenceId="PRIMARY">
4341
<column name="user_id"/>
4442
</constraint>

app/code/Magento/User/etc/db_schema_whitelist.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"interface_locale": true,
2020
"failures_num": true,
2121
"first_failure": true,
22-
"lock_expires": true,
23-
"expires_at": true
22+
"lock_expires": true
2423
},
2524
"constraint": {
2625
"PRIMARY": true,
@@ -43,4 +42,4 @@
4342
"ADMIN_PASSWORDS_USER_ID_ADMIN_USER_USER_ID": true
4443
}
4544
}
46-
}
45+
}

0 commit comments

Comments
 (0)