ltsecurityinc安防产品在线商城代码
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Model\LoginAttempt\SuspiciousDetection;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface;
|
||||
|
||||
class Detector
|
||||
{
|
||||
/**
|
||||
* @var Type\DetectorInterface[]
|
||||
*/
|
||||
private $detectionTypes;
|
||||
|
||||
public function __construct(array $detectionTypes = [])
|
||||
{
|
||||
$this->detectionTypes = $detectionTypes;
|
||||
}
|
||||
|
||||
public function isSuspicious(string $type, LoginAttemptInterface $loginAttempt): bool
|
||||
{
|
||||
return isset($this->detectionTypes[$type])
|
||||
? $this->detectionTypes[$type]->isSuspiciousAttempt($loginAttempt)
|
||||
: false;
|
||||
}
|
||||
}
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Model\LoginAttempt\SuspiciousDetection\Type;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface;
|
||||
use Amasty\AdminActionsLog\Api\Logging\ObjectDataStorageInterface;
|
||||
use Amasty\AdminActionsLog\Model\LoginAttempt\LoginAttempt;
|
||||
use Amasty\AdminActionsLog\Model\LoginAttempt\ResourceModel\CollectionFactory;
|
||||
use Amasty\AdminActionsLog\Model\OptionSource\LoginAttemptStatus;
|
||||
|
||||
abstract class AbstractDetection implements DetectorInterface
|
||||
{
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $loginAttemptCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var ObjectDataStorageInterface
|
||||
*/
|
||||
private $dataStorage;
|
||||
|
||||
public function __construct(
|
||||
CollectionFactory $loginAttemptCollectionFactory,
|
||||
ObjectDataStorageInterface $dataStorage
|
||||
) {
|
||||
$this->loginAttemptCollectionFactory = $loginAttemptCollectionFactory;
|
||||
$this->dataStorage = $dataStorage;
|
||||
}
|
||||
|
||||
abstract public function isSuspiciousAttempt(LoginAttemptInterface $loginAttempt): bool;
|
||||
|
||||
public function getLastSucceedAttempt(LoginAttemptInterface $loginAttempt): LoginAttemptInterface
|
||||
{
|
||||
$storageKey = spl_object_id($loginAttempt) . '.none';
|
||||
if ($this->dataStorage->isExists($storageKey)) {
|
||||
$lastLoginAttempt = $this->dataStorage->get($storageKey);
|
||||
|
||||
return array_shift($lastLoginAttempt);
|
||||
}
|
||||
|
||||
$loginAttemptCollection = $this->loginAttemptCollectionFactory->create();
|
||||
|
||||
$lastLoginAttempt = $loginAttemptCollection->addFieldToFilter(
|
||||
LoginAttempt::USERNAME,
|
||||
$loginAttempt->getUsername()
|
||||
)->addFieldToFilter(LoginAttempt::STATUS, LoginAttemptStatus::SUCCESS)
|
||||
->addFieldToFilter($loginAttemptCollection->getIdFieldName(), ['neq' => $loginAttempt->getId()])
|
||||
->setOrder($loginAttemptCollection->getIdFieldName(), $loginAttemptCollection::SORT_ORDER_DESC)
|
||||
->setPageSize(1)
|
||||
->getFirstItem();
|
||||
$this->dataStorage->set($storageKey, [$lastLoginAttempt]);
|
||||
|
||||
return $lastLoginAttempt;
|
||||
}
|
||||
}
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Model\LoginAttempt\SuspiciousDetection\Type;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface;
|
||||
|
||||
interface DetectorInterface
|
||||
{
|
||||
public function isSuspiciousAttempt(LoginAttemptInterface $loginAttempt): bool;
|
||||
}
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Model\LoginAttempt\SuspiciousDetection\Type;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface;
|
||||
|
||||
class NewDevice extends AbstractDetection
|
||||
{
|
||||
public function isSuspiciousAttempt(LoginAttemptInterface $loginAttempt): bool
|
||||
{
|
||||
$lastAttempt = $this->getLastSucceedAttempt($loginAttempt);
|
||||
|
||||
if ($lastAttempt->getId() && !empty($lastAttempt->getUserAgent())) {
|
||||
return $loginAttempt->getUserAgent() !== $lastAttempt->getUserAgent();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Model\LoginAttempt\SuspiciousDetection\Type;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface;
|
||||
|
||||
class NewIp extends AbstractDetection
|
||||
{
|
||||
public function isSuspiciousAttempt(LoginAttemptInterface $loginAttempt): bool
|
||||
{
|
||||
$lastAttempt = $this->getLastSucceedAttempt($loginAttempt);
|
||||
|
||||
if ($lastAttempt->getId() && !empty($lastAttempt->getIp())) {
|
||||
return $loginAttempt->getIp() !== $lastAttempt->getIp();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Admin Actions Log for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\AdminActionsLog\Model\LoginAttempt\SuspiciousDetection\Type;
|
||||
|
||||
use Amasty\AdminActionsLog\Api\Data\LoginAttemptInterface;
|
||||
|
||||
class NewLocation extends AbstractDetection
|
||||
{
|
||||
public function isSuspiciousAttempt(LoginAttemptInterface $loginAttempt): bool
|
||||
{
|
||||
$lastAttempt = $this->getLastSucceedAttempt($loginAttempt);
|
||||
|
||||
if ($lastAttempt->getId() && !empty($lastAttempt->getLocation())) {
|
||||
return $loginAttempt->getLocation() !== $lastAttempt->getLocation();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user