Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bundle/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Exception\UnknownTwoFactorProviderException;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistry;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistryInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Trusted\TrustedDeviceManagerInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\TwoFactorFirewallConfig;
use Scheb\TwoFactorBundle\Security\TwoFactor\TwoFactorFirewallContext;
Expand All @@ -28,7 +28,7 @@ class FormController
{
public function __construct(
private readonly TokenStorageInterface $tokenStorage,
private readonly TwoFactorProviderRegistry $providerRegistry,
private readonly TwoFactorProviderRegistryInterface $providerRegistry,
private readonly TwoFactorFirewallContext $twoFactorFirewallContext,
private readonly LogoutUrlGenerator $logoutUrlGenerator,
private readonly TrustedDeviceManagerInterface|null $trustedDeviceManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Scheb\TwoFactorBundle\Security\TwoFactor\Event\TwoFactorAuthenticationEvents;
use Scheb\TwoFactorBundle\Security\TwoFactor\Event\TwoFactorCodeEvent;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\PreparationRecorderInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistry;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistryInterface;
use Symfony\Component\Security\Http\Event\CheckPassportEvent;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

Expand All @@ -23,7 +23,7 @@ class CheckTwoFactorCodeListener extends AbstractCheckCodeListener

public function __construct(
PreparationRecorderInterface $preparationRecorder,
private readonly TwoFactorProviderRegistry $providerRegistry,
private readonly TwoFactorProviderRegistryInterface $providerRegistry,
private readonly EventDispatcherInterface $eventDispatcher,
) {
parent::__construct($preparationRecorder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @final
*/
class TwoFactorConditionRegistry
class TwoFactorConditionRegistry implements TwoFactorConditionRegistryInterface
{
/**
* @param TwoFactorConditionInterface[] $conditions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Scheb\TwoFactorBundle\Security\TwoFactor\Condition;

use Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface;

interface TwoFactorConditionRegistryInterface
{
public function shouldPerformTwoFactorAuthentication(AuthenticationContextInterface $context): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface;
use Scheb\TwoFactorBundle\Security\Http\Authenticator\TwoFactorAuthenticator;
use Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextFactoryInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Condition\TwoFactorConditionRegistry;
use Scheb\TwoFactorBundle\Security\TwoFactor\Condition\TwoFactorConditionRegistryInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderInitiator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -22,7 +22,7 @@ class AuthenticationTokenListener implements EventSubscriberInterface
{
public function __construct(
private readonly string $firewallName,
private readonly TwoFactorConditionRegistry $twoFactorConditionRegistry,
private readonly TwoFactorConditionRegistryInterface $twoFactorConditionRegistry,
private readonly TwoFactorProviderInitiator $twoFactorProviderInitiator,
private readonly AuthenticationContextFactoryInterface $authenticationContextFactory,
private readonly RequestStack $requestStack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class TwoFactorProviderInitiator
{
public function __construct(
private readonly TwoFactorProviderRegistry $providerRegistry,
private readonly TwoFactorProviderRegistryInterface $providerRegistry,
private readonly TwoFactorTokenFactoryInterface $twoFactorTokenFactory,
private readonly TwoFactorProviderDeciderInterface $twoFactorProviderDecider,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TwoFactorProviderPreparationListener implements EventSubscriberInterface,
private readonly LoggerInterface $logger;

public function __construct(
private readonly TwoFactorProviderRegistry $providerRegistry,
private readonly TwoFactorProviderRegistryInterface $providerRegistry,
private readonly PreparationRecorderInterface $preparationRecorder,
LoggerInterface|null $logger,
private readonly string $firewallName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* @final
*/
class TwoFactorProviderRegistry
class TwoFactorProviderRegistry implements TwoFactorProviderRegistryInterface
{
/**
* @param iterable<string,TwoFactorProviderInterface> $providers
Expand All @@ -20,7 +20,7 @@ public function __construct(private readonly iterable $providers)
}

/**
* @return iterable<string,TwoFactorProviderInterface>
* {@inheritDoc}
*/
public function getAllProviders(): iterable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Scheb\TwoFactorBundle\Security\TwoFactor\Provider;

interface TwoFactorProviderRegistryInterface
{
/**
* @return iterable<string,TwoFactorProviderInterface>
*/
public function getAllProviders(): iterable;

public function getProvider(string $providerName): TwoFactorProviderInterface;
}
6 changes: 3 additions & 3 deletions tests/Controller/FormControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorFormRendererInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistry;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistryInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Trusted\TrustedDeviceManagerInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\TwoFactorFirewallConfig;
use Scheb\TwoFactorBundle\Security\TwoFactor\TwoFactorFirewallContext;
Expand All @@ -38,7 +38,7 @@ class FormControllerTest extends TestCase
private const string LOGOUT_PATH = '/logout';

private MockObject&TokenStorageInterface $tokenStorage;
private MockObject&TwoFactorProviderRegistry $providerRegistry;
private MockObject&TwoFactorProviderRegistryInterface $providerRegistry;
private MockObject&SessionInterface $session;
private MockObject&Request $request;
private MockObject&TwoFactorFormRendererInterface $formRenderer;
Expand Down Expand Up @@ -68,7 +68,7 @@ protected function setUp(): void

$this->tokenStorage = $this->createMock(TokenStorageInterface::class);

$this->providerRegistry = $this->createMock(TwoFactorProviderRegistry::class);
$this->providerRegistry = $this->createMock(TwoFactorProviderRegistryInterface::class);
$this->providerRegistry
->expects($this->any())
->method('getProvider')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
use Scheb\TwoFactorBundle\Security\TwoFactor\Event\TwoFactorAuthenticationEvents;
use Scheb\TwoFactorBundle\Security\TwoFactor\Event\TwoFactorCodeEvent;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistry;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistryInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

/**
* @property CheckTwoFactorCodeListener $listener
*/
class CheckTwoFactorCodeListenerTest extends AbstractCheckCodeListenerTestSetup
{
private MockObject&TwoFactorProviderRegistry $providerRegistry;
private MockObject&TwoFactorProviderRegistryInterface $providerRegistry;
private MockObject&EventDispatcherInterface $eventDispatcher;

protected function setUp(): void
{
parent::setUp();

$this->providerRegistry = $this->createMock(TwoFactorProviderRegistry::class);
$this->providerRegistry = $this->createMock(TwoFactorProviderRegistryInterface::class);
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->listener = new CheckTwoFactorCodeListener(
$this->preparationRecorder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Scheb\TwoFactorBundle\Security\Http\Authenticator\TwoFactorAuthenticator;
use Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextFactoryInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Condition\TwoFactorConditionRegistry;
use Scheb\TwoFactorBundle\Security\TwoFactor\Condition\TwoFactorConditionRegistryInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Event\AuthenticationTokenListener;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderInitiator;
use Scheb\TwoFactorBundle\Tests\TestCase;
Expand All @@ -24,14 +24,14 @@ class AuthenticationTokenListenerTest extends TestCase
{
private const string FIREWALL_NAME = 'firewallName';

private MockObject&TwoFactorConditionRegistry $twoFactorConditionRegistry;
private MockObject&TwoFactorConditionRegistryInterface $twoFactorConditionRegistry;
private MockObject&TwoFactorProviderInitiator $twoFactorProviderInitiator;
private MockObject&AuthenticationContextFactoryInterface $authenticationContextFactory;
private AuthenticationTokenListener $listener;

protected function setUp(): void
{
$this->twoFactorConditionRegistry = $this->createMock(TwoFactorConditionRegistry::class);
$this->twoFactorConditionRegistry = $this->createMock(TwoFactorConditionRegistryInterface::class);
$this->twoFactorProviderInitiator = $this->createMock(TwoFactorProviderInitiator::class);
$this->authenticationContextFactory = $this->createMock(AuthenticationContextFactoryInterface::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderDeciderInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderInitiator;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistry;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistryInterface;
use Scheb\TwoFactorBundle\Tests\Security\TwoFactor\Condition\AbstractAuthenticationContextTestCase;

class TwoFactorProviderInitiatorTest extends AbstractAuthenticationContextTestCase
Expand Down Expand Up @@ -40,7 +40,7 @@ protected function setUp(): void

$this->withoutNeedsPreparationProvider = $this->createMock(TwoFactorProviderInterface::class);

$providerRegistry = $this->createMock(TwoFactorProviderRegistry::class);
$providerRegistry = $this->createMock(TwoFactorProviderRegistryInterface::class);
$providerRegistry
->expects($this->any())
->method('getAllProviders')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\PreparationRecorderInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderInterface;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderPreparationListener;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistry;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\TwoFactorProviderRegistryInterface;
use Scheb\TwoFactorBundle\Tests\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -27,7 +27,7 @@ class TwoFactorProviderPreparationListenerTest extends TestCase
private const string FIREWALL_NAME = 'firewallName';
private const string CURRENT_PROVIDER_NAME = 'currentProviderName';

private MockObject&TwoFactorProviderRegistry $providerRegistry;
private MockObject&TwoFactorProviderRegistryInterface $providerRegistry;
private MockObject&Request $request;
private MockObject&PreparationRecorderInterface $preparationRecorder;
private MockObject&TwoFactorToken $token;
Expand All @@ -54,7 +54,7 @@ protected function setUp(): void

$this->preparationRecorder = $this->createMock(PreparationRecorderInterface::class);

$this->providerRegistry = $this->createMock(TwoFactorProviderRegistry::class);
$this->providerRegistry = $this->createMock(TwoFactorProviderRegistryInterface::class);
}

private function initTwoFactorProviderPreparationListener(bool $prepareOnLogin, bool $prepareOnAccessDenied): void
Expand Down
Loading