Skip to content
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

Commit 4a1fe69

Browse files
Spomkyscheb
authored andcommitted
NullLogger added
1 parent bb5ffd6 commit 4a1fe69

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Security/Http/Firewall/TwoFactorListener.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Scheb\TwoFactorBundle\Security\Http\Firewall;
44

55
use Psr\Log\LoggerInterface;
6+
use Psr\Log\NullLogger;
67
use Scheb\TwoFactorBundle\DependencyInjection\Factory\Security\TwoFactorFactory;
78
use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenFactoryInterface;
89
use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface;
@@ -138,7 +139,7 @@ public function __construct(
138139
$this->twoFactorAccessDecider = $twoFactorAccessDecider;
139140
$this->eventDispatcher = $eventDispatcher;
140141
$this->twoFactorTokenFactory = $twoFactorTokenFactory;
141-
$this->logger = $logger;
142+
$this->logger = $logger === null ? new NullLogger() : $logger;
142143
$this->trustedDeviceManager = $trustedDeviceManager;
143144
}
144145

@@ -211,19 +212,15 @@ private function attemptAuthentication(Request $request, TwoFactorTokenInterface
211212

212213
private function onFailure(Request $request, AuthenticationException $failed): Response
213214
{
214-
if ($this->logger) {
215-
$this->logger->info('Two-factor authentication request failed.', ['exception' => $failed]);
216-
}
215+
$this->logger->info('Two-factor authentication request failed.', ['exception' => $failed]);
217216
$this->dispatchTwoFactorAuthenticationEvent(TwoFactorAuthenticationEvents::FAILURE, $request, $this->tokenStorage->getToken());
218217

219218
return $this->failureHandler->onAuthenticationFailure($request, $failed);
220219
}
221220

222221
private function onSuccess(Request $request, TokenInterface $token, TwoFactorTokenInterface $previousTwoFactorToken): Response
223222
{
224-
if ($this->logger) {
225-
$this->logger->info('User has been two-factor authenticated successfully.', ['username' => $token->getUsername()]);
226-
}
223+
$this->logger->info('User has been two-factor authenticated successfully.', ['username' => $token->getUsername()]);
227224
$this->tokenStorage->setToken($token);
228225
$this->dispatchTwoFactorAuthenticationEvent(TwoFactorAuthenticationEvents::SUCCESS, $request, $token);
229226

0 commit comments

Comments
 (0)