-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/mage-os/mirror-security-…
…package into develop
- Loading branch information
Showing
6 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Copyright 2024 Adobe | ||
* All Rights Reserved. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\TwoFactorAuth\Model\Config\Backend; | ||
|
||
use Magento\Framework\App\Config\Value; | ||
use Magento\Framework\App\Config\Data\ProcessorInterface; | ||
use Magento\Framework\Exception\ValidatorException; | ||
use OTPHP\TOTPInterface; | ||
|
||
class Leeway extends Value implements ProcessorInterface | ||
{ | ||
/** | ||
* Fetch Totp default period value | ||
* | ||
* @return int | ||
*/ | ||
private function getDefaultPeriod(): int | ||
{ | ||
return TOTPInterface::DEFAULT_PERIOD; | ||
} | ||
|
||
/** | ||
* Process the value before saving. | ||
* | ||
* @param mixed $value The configuration value. | ||
* @return mixed The processed value. | ||
* @throws ValidatorException If the value is invalid. | ||
*/ | ||
public function processValue($value) | ||
{ | ||
if (!is_numeric($value)) { | ||
throw new ValidatorException(__('The Leeway must be a numeric value.')); | ||
} | ||
$numericValue = (int) $value; | ||
return $numericValue; | ||
} | ||
|
||
/** | ||
* Validates the value before saving. | ||
* | ||
* @throws ValidatorException If the value is invalid. | ||
*/ | ||
public function beforeSave() | ||
{ | ||
$value = $this->getValue(); | ||
$period = $this->getDefaultPeriod(); | ||
if (!is_numeric($value) || $value < 1 || $value >= $period) { | ||
throw new ValidatorException( | ||
__( | ||
'Invalid Leeway value. It must be between 1 and %1 as default period is %2', | ||
$period-1, | ||
$period | ||
) | ||
); | ||
} | ||
|
||
return parent::beforeSave(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters