File tree Expand file tree Collapse file tree
Integration/Authentication/TwoFactorAuth/Infrastructure
Unit/Authentication/TwoFactorAuth
Infrastructure/Provider/Email Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99
1010namespace OxidEsales \SecurityModule \Authentication \OAuth2 \Service ;
1111
12- use OxidEsales \SecurityModule \Authentication \OAuth2 \Exception \ProviderNotActiveException ;
1312use OxidEsales \SecurityModule \Authentication \OAuth2 \Exception \ProviderNotFoundException ;
1413use OxidEsales \SecurityModule \Authentication \OAuth2 \Infrastructure \Provider \ProviderAdapterInterface ;
15- use OxidEsales \SecurityModule \Authentication \OAuth2 \Service \Exception \ProviderNotActive ;
1614use Symfony \Component \Translation \Provider \ProviderInterface ;
1715
1816class ProviderCollector implements ProviderCollectorInterface
Original file line number Diff line number Diff line change 55 * See LICENSE file for license details.
66 */
77
8- namespace OxidEsales \ SecurityModule \ Authentication \ TwoFactorAuth \ Service ;
8+ declare (strict_types= 1 ) ;
99
10- interface NotifierServiceInterface
11- {
10+ namespace OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Exception ;
1211
12+ class NotifierNotFoundException extends \Exception
13+ {
1314}
Original file line number Diff line number Diff line change 77
88declare (strict_types=1 );
99
10- namespace OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Provider ;
10+ namespace OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Provider \ Email ;
1111
1212use OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Provider \Factory \EmailFactoryInterface ;
13+ use OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Provider \NotifierAdapterInterface ;
1314
14- class EmailAdapter
15+ class EmailAdapter implements NotifierAdapterInterface
1516{
1617 public function __construct (
1718 readonly private EmailFactoryInterface $ emailFactory ,
1819 ) {
1920 }
2021
21- public function getName ()
22+ public function getName (): string
2223 {
2324 return 'email ' ;
2425 }
2526
26- public function notify ($ recipient , $ code ): void
27+ public function notify (string $ recipient , string $ code ): void
2728 {
2829 $ emailModel = $ this ->emailFactory ->create ();
2930 $ emailModel ->sendEmail (
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Provider ;
4+
5+ interface NotifierAdapterInterface
6+ {
7+ public function getName (): string ;
8+
9+ public function notify (string $ recipient , string $ code ): void ;
10+ }
Original file line number Diff line number Diff line change @@ -6,5 +6,5 @@ services:
66 autowire : true
77 public : false
88
9- OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Provider\EmailAdapter :
9+ OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Provider\Email\ EmailAdapter :
1010 tags : [ 'security.twofa.tag.notify.provider' ]
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Copyright © OXID eSales AG. All rights reserved.
5+ * See LICENSE file for license details.
6+ */
7+
8+ declare (strict_types=1 );
9+
10+ namespace OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Service ;
11+
12+ use OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Exception \NotifierNotFoundException ;
13+ use OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Provider \NotifierAdapterInterface ;
14+
15+ class NotifierCollector implements NotifierCollectorInterface
16+ {
17+ private readonly array $ collectedNotifiers ;
18+
19+ /**
20+ * @param iterable<NotifierAdapterInterface> $notifiers
21+ */
22+ public function __construct (
23+ protected iterable $ notifiers ,
24+ ) {
25+ $ this ->collectedNotifiers = iterator_to_array ($ this ->notifiers , false );
26+ }
27+
28+ public function getNotifier (string $ name ): NotifierAdapterInterface
29+ {
30+ $ notifierFound = array_filter (
31+ $ this ->collectedNotifiers ,
32+ fn ($ notifier ) => $ notifier ->getName () === $ name
33+ );
34+
35+ if (!$ notifierFound ) {
36+ throw new NotifierNotFoundException ();
37+ }
38+
39+ return reset ($ notifierFound );
40+ }
41+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Copyright © OXID eSales AG. All rights reserved.
5+ * See LICENSE file for license details.
6+ */
7+
8+ namespace OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Service ;
9+
10+ use OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Exception \NotifierNotFoundException ;
11+ use OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Provider \NotifierAdapterInterface ;
12+
13+ interface NotifierCollectorInterface
14+ {
15+ /**
16+ * @throws NotifierNotFoundException
17+ */
18+ public function getNotifier (string $ name ): NotifierAdapterInterface ;
19+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -8,12 +8,14 @@ services:
88
99 OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\ModuleSettingsServiceInterface :
1010 class : OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\ModuleSettingsService
11+ public : true
1112
1213 OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\AuthorizeServiceInterface :
1314 class : OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\AuthorizeService
15+ public : true
1416
15- OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\NotifierServiceInterface :
16- class : OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\NotifierService
17+ OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\NotifierCollectorInterface :
18+ class : OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\NotifierCollector
1719 public : true
1820 arguments :
1921 $notifiers : !tagged 'security.twofa.tag.notify.provider'
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Copyright © OXID eSales AG. All rights reserved.
5+ * See LICENSE file for license details.
6+ */
7+
8+ declare (strict_types=1 );
9+
10+ namespace OxidEsales \SecurityModule \Tests \Integration \Authentication \TwoFactorAuth \Infrastructure \Factory ;
11+
12+ use OxidEsales \Eshop \Application \Model \User ;
13+ use OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Factory \UserFactory ;
14+ use PHPUnit \Framework \TestCase ;
15+
16+ class UserFactoryTest extends TestCase
17+ {
18+ public function testCreateUserFactory (): void
19+ {
20+ $ userFactory = new UserFactory ();
21+ $ userModel = $ userFactory ->create ();
22+
23+ $ this ->assertInstanceOf (User::class, $ userModel );
24+ }
25+
26+ public function testCreateMultipleUserFactory (): void
27+ {
28+ $ userFactory = new UserFactory ();
29+
30+ $ userModel = $ userFactory ->create ();
31+ $ this ->assertInstanceOf (User::class, $ userModel );
32+
33+ $ newUserFactory = $ userFactory ->create ();
34+ $ this ->assertInstanceOf (User::class, $ newUserFactory );
35+ $ this ->assertNotSame ($ userModel , $ newUserFactory );
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments