Skip to content

Commit 5689118

Browse files
committed
OXDEV-9078 Move settings to new settings interface
1 parent e55428c commit 5689118

16 files changed

Lines changed: 105 additions & 281 deletions

File tree

src/Authentication/TwoFactorAuth/Factory/TwoFAServiceFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Factory;
1111

1212
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Exception\AuthenticationTypeNotFoundException;
13-
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\ModuleSettingsServiceInterface;
1413
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\TwoFAServiceInterface;
14+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings\TwoFASettingsInterface;
1515

1616
class TwoFAServiceFactory implements TwoFAServiceFactoryInterface
1717
{
1818
public function __construct(
19-
private ModuleSettingsServiceInterface $settings,
19+
private TwoFASettingsInterface $settings,
2020
private array $implementations,
2121
) {
2222
}

src/Authentication/TwoFactorAuth/Service/AuthorizeService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111

1212
use OxidEsales\EshopCommunity\Internal\Framework\Session\SessionInterface;
1313
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Repository\UserRepositoryInterface;
14+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings\TwoFASettingsInterface;
1415

1516
class AuthorizeService implements AuthorizeServiceInterface
1617
{
1718
public const USER_SESSION_KEY = 'pending_authorized_user';
1819

1920
public function __construct(
20-
private ModuleSettingsServiceInterface $moduleSettings,
21+
private TwoFASettingsInterface $moduleSettings,
2122
private VerificationCollectorServiceInterface $verifyCollector,
2223
private NotifierCollectorInterface $notifierCollector,
2324
private ResendOTPServiceInterface $resendOTPService,

src/Authentication/TwoFactorAuth/Service/ModuleSettingsService.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/Authentication/TwoFactorAuth/Service/ModuleSettingsServiceInterface.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Authentication/TwoFactorAuth/Service/services.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ services:
88
bind:
99
OxidEsales\Eshop\Core\Utils: '@=service("OxidEsales\\SecurityModule\\Core\\Registry").getUtils()'
1010

11-
OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\ModuleSettingsServiceInterface:
12-
class: OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\ModuleSettingsService
13-
public: true
14-
1511
OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\UserServiceInterface:
1612
class: OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\UserService
1713
public: true

src/Authentication/TwoFactorAuth/Settings/TwoFASettings.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,33 @@
1010
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings;
1111

1212
use OxidEsales\Eshop\Core\Config;
13+
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
14+
use OxidEsales\SecurityModule\Core\Module;
1315

1416
class TwoFASettings implements TwoFASettingsInterface
1517
{
18+
public const ACTIVE = 'oeSecurityTwoFactorAuthEnabled';
19+
20+
public const TWO_FACTOR_TYPE = 'oeSecurityTwoFactorAuthType';
21+
1622
public function __construct(
1723
private Config $config,
24+
private ModuleSettingServiceInterface $moduleSettingService,
1825
) {
1926
}
2027

28+
public function isTwoFactorAuthEnabled(): bool
29+
{
30+
return $this->moduleSettingService->getBoolean(self::ACTIVE, Module::MODULE_ID);
31+
}
32+
33+
public function getTwoFactorAuthType(): string
34+
{
35+
return $this->moduleSettingService->getString(self::TWO_FACTOR_TYPE, Module::MODULE_ID)
36+
->trim()
37+
->toString();
38+
}
39+
2140
public function getVerificationUrl(): string
2241
{
2342
return $this->config->getShopHomeUrl() . 'cl=twofactorauth';

src/Authentication/TwoFactorAuth/Settings/TwoFASettingsInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,9 @@
1111

1212
interface TwoFASettingsInterface
1313
{
14+
public function isTwoFactorAuthEnabled(): bool;
15+
16+
public function getTwoFactorAuthType(): string;
17+
1418
public function getVerificationUrl(): string;
1519
}

src/Authentication/TwoFactorAuth/Settings/services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ services:
55

66
OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings\TwoFASettingsInterface:
77
class: OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings\TwoFASettings
8+
public: true

src/Shared/Model/User.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
use OxidEsales\Eshop\Core\Exception\UserException;
1414
use OxidEsales\Eshop\Core\Registry;
1515
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\TwoFAUserServiceInterface;
16+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings\TwoFASettingsInterface;
1617
use OxidEsales\SecurityModule\Captcha\Captcha\Image\Exception\CaptchaValidateException as ImageCaptchaException;
1718
use OxidEsales\SecurityModule\Captcha\Captcha\HoneyPot\Exception\CaptchaValidateException as HoneyPotCaptchaException;
1819
use OxidEsales\SecurityModule\Captcha\Service\CaptchaServiceInterface;
1920
use OxidEsales\SecurityModule\Captcha\Service\ModuleSettingsServiceInterface as CaptchaSettingsServiceInterface;
20-
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\ModuleSettingsServiceInterface
21-
as TwoFASettingsServiceInterface;
2221
use OxidEsales\SecurityModule\Shared\Core\InputValidator;
2322

2423
/**
@@ -91,7 +90,7 @@ protected function onLogin($userName, #[\SensitiveParameter] $password)
9190
parent::onLogin($userName, $password);
9291

9392
$userId = $this->getId();
94-
$settingsService = $this->getService(TwoFASettingsServiceInterface::class);
93+
$settingsService = $this->getService(TwoFASettingsInterface::class);
9594
if ($userId && $settingsService->isTwoFactorAuthEnabled() && !$this->isAdmin()) {
9695
$twoFAUserService = $this->getService(TwoFAUserServiceInterface::class);
9796
if (!$twoFAUserService->isChallengeVerified($userId)) {

tests/Codeception/Acceptance/BaseCest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
use Codeception\Util\Fixtures;
1313
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
14+
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
1415
use OxidEsales\SecurityModule\Authentication\OAuth2\Service\ModuleSettingsServiceInterface
1516
as OAuthModuleSettingsServiceInterface;
16-
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\ModuleSettingsServiceInterface
17-
as TwoFASettingsServiceInterface;
17+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings\TwoFASettings;
1818
use OxidEsales\SecurityModule\Captcha\Service\ModuleSettingsServiceInterface as CaptchaSettingsServiceInterface;
19+
use OxidEsales\SecurityModule\Core\Module;
1920
use OxidEsales\SecurityModule\PasswordPolicy\Service\ModuleSettingsServiceInterface as PasswordSettingsServiceInterface;
2021

2122
abstract class BaseCest
@@ -42,7 +43,11 @@ protected function setCaptchaState(bool $state)
4243

4344
protected function setTwoFactorAuthState(bool $state)
4445
{
45-
ContainerFacade::get(TwoFASettingsServiceInterface::class)->saveIsTwoFactorAuthEnabled($state);
46+
ContainerFacade::get(ModuleSettingServiceInterface::class)->saveBoolean(
47+
TwoFASettings::ACTIVE,
48+
$state,
49+
Module::MODULE_ID
50+
);
4651
}
4752

4853
protected function setProviderState(bool $state)

0 commit comments

Comments
 (0)