Skip to content

EspoCRM – Open Source CRM Application

Ref

Yurii15f309435cd8
diff --git a/application/Espo/Core/Authentication/Hook/Hooks/FailedAttemptsLimit.php b/application/Espo/Core/Authentication/Hook/Hooks/FailedAttemptsLimit.php
index 3b70ae11df..f2738ba596 100644
--- a/application/Espo/Core/Authentication/Hook/Hooks/FailedAttemptsLimit.php
+++ b/application/Espo/Core/Authentication/Hook/Hooks/FailedAttemptsLimit.php
@@ -38,9 +38,8 @@ use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Authentication\ConfigDataProvider;
use Espo\ORM\EntityManager;
use Espo\Entities\AuthLogRecord;
-
-use DateTime;
use Espo\ORM\Name\Attribute;
+use DateTime;
use Exception;
use RuntimeException;
@@ -71,9 +70,9 @@ class FailedAttemptsLimit implements BeforeLogin
$ipAddress = $this->util->obtainIpFromRequest($request);
$where = [
- 'requestTime>' => $this->getTimeFrom($request, $failedAttemptsPeriod)->format('U'),
- 'isDenied' => true,
- 'ipAddress' => $ipAddress,
+ AuthLogRecord::FIELD_REQUEST_TIME . '>' => $this->getTimeFrom($request, $failedAttemptsPeriod)->format('U'),
+ AuthLogRecord::FIELD_IS_DENIED => true,
+ AuthLogRecord::FIELD_IP_ADDRESS => $ipAddress,
];
$wasFailed = (bool) $this->entityManager
diff --git a/application/Espo/Core/Authentication/Hook/Hooks/FailedCodeAttemptsLimit.php b/application/Espo/Core/Authentication/Hook/Hooks/FailedCodeAttemptsLimit.php
index d01a09b280..ff7602781f 100644
--- a/application/Espo/Core/Authentication/Hook/Hooks/FailedCodeAttemptsLimit.php
+++ b/application/Espo/Core/Authentication/Hook/Hooks/FailedCodeAttemptsLimit.php
@@ -36,9 +36,8 @@ use Espo\Core\Authentication\Hook\BeforeLogin;
use Espo\Core\Exceptions\Forbidden;
use Espo\Entities\AuthLogRecord;
use Espo\ORM\EntityManager;
-
-use DateTime;
use Espo\ORM\Name\Attribute;
+use DateTime;
use Exception;
use RuntimeException;
@@ -73,10 +72,10 @@ class FailedCodeAttemptsLimit implements BeforeLogin
$failedAttemptsPeriod = $this->configDataProvider->getFailedCodeAttemptsPeriod();
$where = [
- 'requestTime>' => $this->getTimeFrom($request, $failedAttemptsPeriod)->format('U'),
- 'isDenied' => true,
- 'username' => $data->getUsername(),
- 'denialReason' => AuthLogRecord::DENIAL_REASON_WRONG_CODE,
+ AuthLogRecord::FIELD_REQUEST_TIME . '>' => $this->getTimeFrom($request, $failedAttemptsPeriod)->format('U'),
+ AuthLogRecord::FIELD_IS_DENIED => true,
+ AuthLogRecord::FIELD_USERNAME => $data->getUsername(),
+ AuthLogRecord::FIELD_DENIAL_REASON => AuthLogRecord::DENIAL_REASON_WRONG_CODE,
];
$wasFailed = (bool) $this->entityManager
diff --git a/application/Espo/Core/Authentication/Hook/Hooks/IpAddressWhitelist.php b/application/Espo/Core/Authentication/Hook/Hooks/IpAddressWhitelist.php
index c6a3b0608b..e623612669 100644
--- a/application/Espo/Core/Authentication/Hook/Hooks/IpAddressWhitelist.php
+++ b/application/Espo/Core/Authentication/Hook/Hooks/IpAddressWhitelist.php
@@ -39,6 +39,9 @@ use Espo\Core\Authentication\Util\IpAddressUtil;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Utils\Config;
+/**
+ * @noinspection PhpUnused
+ */
class IpAddressWhitelist implements OnLogin
{
public function __construct(
diff --git a/application/Espo/Core/Authentication/Hook/Hooks/UsernameFailedAttemptsLimit.php b/application/Espo/Core/Authentication/Hook/Hooks/UsernameFailedAttemptsLimit.php
index 8ad84c3bbb..bc100c6720 100644
--- a/application/Espo/Core/Authentication/Hook/Hooks/UsernameFailedAttemptsLimit.php
+++ b/application/Espo/Core/Authentication/Hook/Hooks/UsernameFailedAttemptsLimit.php
@@ -76,9 +76,9 @@ class UsernameFailedAttemptsLimit implements BeforeLogin
$repo = $this->entityManager->getRDBRepositoryByClass(AuthLogRecord::class);
$where = [
- 'username' => $data->getUsername(),
- 'requestTime>' => $this->getTimeFrom($request, $failedAttemptsPeriod)->format('U'),
- 'isDenied' => true,
+ AuthLogRecord::FIELD_USERNAME => $data->getUsername(),
+ AuthLogRecord::FIELD_REQUEST_TIME . '>' => $this->getTimeFrom($request, $failedAttemptsPeriod)->format('U'),
+ AuthLogRecord::FIELD_IS_DENIED => true,
];
$wasFailed = (bool) $repo
@@ -103,9 +103,9 @@ class UsernameFailedAttemptsLimit implements BeforeLogin
$repo
->select([Attribute::ID])
->where([
- 'username' => $data->getUsername(),
- 'ipAddress' => $ipAddress,
- 'isDenied' => false,
+ AuthLogRecord::FIELD_USERNAME => $data->getUsername(),
+ AuthLogRecord::FIELD_IP_ADDRESS => $ipAddress,
+ AuthLogRecord::FIELD_IS_DENIED => false,
])
->findOne()
) {
diff --git a/application/Espo/Entities/AuthLogRecord.php b/application/Espo/Entities/AuthLogRecord.php
index a82adf2e48..9938c23442 100644
--- a/application/Espo/Entities/AuthLogRecord.php
+++ b/application/Espo/Entities/AuthLogRecord.php
@@ -33,30 +33,34 @@ use Espo\Core\ORM\Entity;
class AuthLogRecord extends Entity
{
- public const ENTITY_TYPE = 'AuthLogRecord';
+ public const string ENTITY_TYPE = 'AuthLogRecord';
- public const DENIAL_REASON_CREDENTIALS = 'CREDENTIALS';
- public const DENIAL_REASON_WRONG_CODE = 'WRONG_CODE';
- public const DENIAL_REASON_INACTIVE_USER = 'INACTIVE_USER';
- public const DENIAL_REASON_IS_PORTAL_USER = 'IS_PORTAL_USER';
- public const DENIAL_REASON_IS_NOT_PORTAL_USER = 'IS_NOT_PORTAL_USER';
- public const DENIAL_REASON_USER_IS_NOT_IN_PORTAL = 'USER_IS_NOT_IN_PORTAL';
- public const DENIAL_REASON_IS_SYSTEM_USER = 'IS_SYSTEM_USER';
- public const DENIAL_REASON_FORBIDDEN = 'FORBIDDEN';
+ public const string DENIAL_REASON_CREDENTIALS = 'CREDENTIALS';
+ public const string DENIAL_REASON_WRONG_CODE = 'WRONG_CODE';
+ public const string DENIAL_REASON_INACTIVE_USER = 'INACTIVE_USER';
+ public const string DENIAL_REASON_IS_PORTAL_USER = 'IS_PORTAL_USER';
+ public const string DENIAL_REASON_IS_NOT_PORTAL_USER = 'IS_NOT_PORTAL_USER';
+ public const string DENIAL_REASON_USER_IS_NOT_IN_PORTAL = 'USER_IS_NOT_IN_PORTAL';
+ public const string DENIAL_REASON_IS_SYSTEM_USER = 'IS_SYSTEM_USER';
+ public const string DENIAL_REASON_FORBIDDEN = 'FORBIDDEN';
public const string ATTR_AUTH_TOKEN_ID = 'authTokenId';
public const string FIELD_REQUEST_TIME = 'requestTime';
+ public const string FIELD_USERNAME = 'username';
+ public const string FIELD_IP_ADDRESS = 'ipAddress';
+ public const string FIELD_IS_DENIED = 'isDenied';
+ public const string FIELD_DENIAL_REASON = 'denialReason';
public function setUsername(?string $username): self
{
- $this->set('username', $username);
+ $this->set(self::FIELD_USERNAME, $username);
return $this;
}
public function setIpAddress(?string $ipAddress): self
{
- $this->set('ipAddress', $ipAddress);
+ $this->set(self::FIELD_IP_ADDRESS, $ipAddress);
return $this;
}
@@ -112,14 +116,14 @@ class AuthLogRecord extends Entity
public function setIsDenied(bool $isDenied = true): self
{
- $this->set('isDenied', $isDenied);
+ $this->set(self::FIELD_IS_DENIED, $isDenied);
return $this;
}
public function setDenialReason(?string $denialReason): self
{
- $this->set('denialReason', $denialReason);
+ $this->set(self::FIELD_DENIAL_REASON, $denialReason);
return $this;
}