Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
RequestThrottler Class Reference

Public Member Functions

 __construct (RequestLogReader $requestLogReader, RequestLogWriter $requestLogWriter, RequestLogConfig $requestLogConfig)
 
 throttle ($userName, $userType)
 
 resetAuthenticationFailuresCount ($userName, $userType)
 
 logAuthenticationFailure ($userName, $userType)
 

Data Fields

const USER_TYPE_CUSTOMER = 2
 
const USER_TYPE_ADMIN = 3
 

Detailed Description

Model for OAuth admin/customer token requests throttling.

Definition at line 17 of file RequestThrottler.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( RequestLogReader  $requestLogReader,
RequestLogWriter  $requestLogWriter,
RequestLogConfig  $requestLogConfig 
)

Initialize dependencies.

Parameters
RequestLogReader$requestLogReader
RequestLogWriter$requestLogWriter
RequestLogConfig$requestLogConfig

Definition at line 46 of file RequestThrottler.php.

50  {
51  $this->requestLogReader = $requestLogReader;
52  $this->requestLogWriter = $requestLogWriter;
53  $this->requestLogConfig = $requestLogConfig;
54  }

Member Function Documentation

◆ logAuthenticationFailure()

logAuthenticationFailure (   $userName,
  $userType 
)

Increment authentication failures count and lock user account if the limit is reached.

Account will be locked until lock expires.

Parameters
string$userName
int$userType
Returns
void

Definition at line 100 of file RequestThrottler.php.

101  {
102  $this->requestLogWriter->incrementFailuresCount($userName, $userType);
103  }

◆ resetAuthenticationFailuresCount()

resetAuthenticationFailuresCount (   $userName,
  $userType 
)

Reset count of failed authentication attempts.

Unlock user account and make generation of OAuth tokens possible for this account again.

Parameters
string$userName
int$userType
Returns
void

Definition at line 86 of file RequestThrottler.php.

87  {
88  $this->requestLogWriter->resetFailuresCount($userName, $userType);
89  }

◆ throttle()

throttle (   $userName,
  $userType 
)

Throw exception if user account is currently locked because of too many failed authentication attempts.

Parameters
string$userName
int$userType
Returns
void
Exceptions
AuthenticationException

Definition at line 64 of file RequestThrottler.php.

65  {
66  $count = $this->requestLogReader->getFailuresCount($userName, $userType);
67  if ($count >= $this->requestLogConfig->getMaxFailuresCount()) {
68  throw new AuthenticationException(
69  __(
70  'The account sign-in was incorrect or your account is disabled temporarily. '
71  . 'Please wait and try again later.'
72  )
73  );
74  }
75  }
$count
Definition: recent.phtml:13
__()
Definition: __.php:13

Field Documentation

◆ USER_TYPE_ADMIN

const USER_TYPE_ADMIN = 3

Definition at line 23 of file RequestThrottler.php.

◆ USER_TYPE_CUSTOMER

const USER_TYPE_CUSTOMER = 2

#+ Web API user type

Definition at line 22 of file RequestThrottler.php.


The documentation for this class was generated from the following file: