Skip to content

Commit

Permalink
move changes out of user and into security (#22833: Short-term admin …
Browse files Browse the repository at this point in the history
…accounts)
  • Loading branch information
lfolco committed Jun 21, 2019
1 parent a6511f5 commit ae08dad
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 278 deletions.
15 changes: 0 additions & 15 deletions app/code/Magento/User/Api/Data/UserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,4 @@ public function getInterfaceLocale();
* @return $this
*/
public function setInterfaceLocale($interfaceLocale);

/**
* Get user expiration date.
*
* @return string
*/
public function getExpiresAt();

/**
* Set user expiration date.
*
* @param string $expiresAt
* @return $this
*/
public function setExpiresAt($expiresAt);
}
2 changes: 1 addition & 1 deletion app/code/Magento/User/Block/User/Edit/Tab/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected function _prepareForm()
]
);
}

// TODO: use store time and convert to GMT
$baseFieldset->addField(
'expires_at',
'date',
Expand Down
68 changes: 0 additions & 68 deletions app/code/Magento/User/Cron/DisableExpiredUsers.php

This file was deleted.

20 changes: 1 addition & 19 deletions app/code/Magento/User/Model/ResourceModel/User/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{

/**
* Define resource model
*
Expand All @@ -28,6 +27,7 @@ protected function _construct()
* Collection Init Select
*
* @return $this
* @since 101.1.0
*/
protected function _initSelect()
{
Expand All @@ -42,22 +42,4 @@ protected function _initSelect()
['role_name']
);
}

/**
* Filter for expired, active users.
*
* @param string $now
* @return $this
*/
public function addActiveExpiredUsersFilter($now = null)
{
if ($now === null) {
$now = new \DateTime();
$now->format('Y-m-d H:i:s');
}
$this->addFieldToFilter('expires_at', ['lt' => $now])
->addFieldToFilter('is_active', 1);

return $this;
}
}
44 changes: 5 additions & 39 deletions app/code/Magento/User/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ class User extends AbstractModel implements StorageInterface, UserInterface
protected $_encryptor;

/**
* @deprecated
* @deprecated 101.1.0
*/
protected $_transportBuilder;

/**
* @deprecated
* @deprecated 101.1.0
*/
protected $_storeManager;

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

/**
* @deprecated
* @deprecated 101.1.0
*/
private $deploymentConfig;

Expand Down Expand Up @@ -212,14 +212,9 @@ protected function _construct()
* Removing dependencies and leaving only entity's properties.
*
* @return string[]
*
* @SuppressWarnings(PHPMD.SerializationAware)
* @deprecated Do not use PHP serialization.
*/
public function __sleep()
{
trigger_error('Using PHP serialization is deprecated', E_USER_DEPRECATED);

$properties = parent::__sleep();
return array_diff(
$properties,
Expand All @@ -245,14 +240,9 @@ public function __sleep()
* Restoring required objects after serialization.
*
* @return void
*
* @SuppressWarnings(PHPMD.SerializationAware)
* @deprecated Do not use PHP serialization.
*/
public function __wakeup()
{
trigger_error('Using PHP serialization is deprecated', E_USER_DEPRECATED);

parent::__wakeup();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$this->serializer = $objectManager->get(Json::class);
Expand Down Expand Up @@ -322,10 +312,6 @@ protected function _getValidationRulesBeforeSave()
$this->validationRules->addPasswordConfirmationRule($validator, $this->getPasswordConfirmation());
}
}

if (!empty($this->getExpiresAt())) {
$this->validationRules->addExpiresAtRule($validator);
}
return $validator;
}

Expand Down Expand Up @@ -420,10 +406,6 @@ public function getRoles()
*/
public function getRole()
{
if ($this->getData('extracted_role')) {
$this->_role = $this->getData('extracted_role');
$this->unsetData('extracted_role');
}
if (null === $this->_role) {
$this->_role = $this->_roleFactory->create();
$roles = $this->getRoles();
Expand Down Expand Up @@ -459,7 +441,7 @@ public function roleUserExists()
/**
* Send email with reset password confirmation link.
*
* @deprecated
* @deprecated 101.1.0
* @see NotificatorInterface::sendForgotPassword()
*
* @return $this
Expand Down Expand Up @@ -539,7 +521,7 @@ protected function createChangesDescriptionString()
* @throws NotificationExceptionInterface
* @return $this
* @since 100.1.0
* @deprecated
* @deprecated 101.1.0
* @see NotificatorInterface::sendUpdated()
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
Expand Down Expand Up @@ -921,22 +903,6 @@ public function setInterfaceLocale($interfaceLocale)
return $this->setData('interface_locale', $interfaceLocale);
}

/**
* @inheritDoc
*/
public function getExpiresAt()
{
return $this->_getData('expires_at');
}

/**
* @inheritDoc
*/
public function setExpiresAt($expiresAt)
{
return $this->setData('expires_at', $expiresAt);
}

/**
* Security check for admin user
*
Expand Down
48 changes: 0 additions & 48 deletions app/code/Magento/User/Model/UserValidationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

namespace Magento\User\Model;

use Magento\User\Model\Validator\ExpiresAt;
use Magento\Framework\Validator\EmailAddress;
use Magento\Framework\Validator\NotEmpty;
use Magento\Framework\Validator\Regex;
use Magento\Framework\Validator\StringLength;
use Magento\Framework\App\ObjectManager;

/**
* Class for adding validation rules to an Admin user
Expand All @@ -25,20 +23,6 @@ class UserValidationRules
* Minimum length of admin password
*/
const MIN_PASSWORD_LENGTH = 7;
/**
* @var Validator\ExpiresAt|null
*/
private $expiresValiator;

/**
* UserValidationRules constructor.
* @param Validator\ExpiresAt|null $expiresValiator
*/
public function __construct(?ExpiresAt $expiresValiator = null)
{
$this->expiresValiator = $expiresValiator
?: ObjectManager::getInstance()->get(ExpiresAt::class);
}

/**
* Adds validation rule for user first name, last name, username and email
Expand Down Expand Up @@ -141,36 +125,4 @@ public function addPasswordConfirmationRule(
$validator->addRule($passwordConfirmation, 'password');
return $validator;
}

/**
* Adds validation rule for expiration date.
*
* @param \Magento\Framework\Validator\DataObject $validator
* @return \Magento\Framework\Validator\DataObject
* @throws \Zend_Validate_Exception
*/
public function addExpiresAtRule(\Magento\Framework\Validator\DataObject $validator)
{
$dateValidator = new \Zend_Validate_Date(
[
'format' => \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT,
]
);
$dateValidator->setMessage(
__('"Expiration date" invalid type entered.'),
\Zend_Validate_Date::INVALID
);
$dateValidator->setMessage(
__('"Expiration date" is not a valid date.'),
\Zend_Validate_Date::INVALID_DATE
);
$dateValidator->setMessage(
__('"Expiration date" does not fit the required date format.'),
\Zend_Validate_Date::FALSEFORMAT
);
$validator->addRule($dateValidator, 'expires_at');
$validator->addRule($this->expiresValiator, 'expires_at');

return $validator;
}
}
11 changes: 0 additions & 11 deletions app/code/Magento/User/Test/Unit/Model/UserValidationRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

use Magento\User\Model\UserValidationRules;

/**
* Class UserValidationRulesTest
*
* @package Magento\User\Test\Unit\Model
*/
class UserValidationRulesTest extends \PHPUnit\Framework\TestCase
{
/**
Expand Down Expand Up @@ -47,10 +42,4 @@ public function testAddPasswordConfirmationRule()
$this->validator->expects($this->once())->method('addRule')->willReturn($this->validator);
$this->assertSame($this->validator, $this->rules->addPasswordConfirmationRule($this->validator, ''));
}

public function testAddExpiresAtRule()
{
$this->validator->expects($this->atMost(2))->method('addRule')->willReturn($this->validator);
$this->assertSame($this->validator, $this->rules->addExpiresAtRule($this->validator));
}
}
17 changes: 0 additions & 17 deletions app/code/Magento/User/etc/crontab.xml

This file was deleted.

4 changes: 1 addition & 3 deletions app/code/Magento/User/etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
default="0" comment="Failure Number"/>
<column xsi:type="timestamp" name="first_failure" on_update="false" nullable="true" comment="First Failure"/>
<column xsi:type="timestamp" name="lock_expires" on_update="false" nullable="true"
comment="Expiration Lock Date"/>
<column xsi:type="timestamp" name="expires_at" on_update="false" nullable="true"
comment="User Expiration Date"/>
comment="Expiration Lock Dates"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="user_id"/>
</constraint>
Expand Down
5 changes: 2 additions & 3 deletions app/code/Magento/User/etc/db_schema_whitelist.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"interface_locale": true,
"failures_num": true,
"first_failure": true,
"lock_expires": true,
"expires_at": true
"lock_expires": true
},
"constraint": {
"PRIMARY": true,
Expand All @@ -43,4 +42,4 @@
"ADMIN_PASSWORDS_USER_ID_ADMIN_USER_USER_ID": true
}
}
}
}
Loading

0 comments on commit ae08dad

Please sign in to comment.