|
3 | 3 | namespace Scheb\TwoFactorBundle\Security\Http\Firewall; |
4 | 4 |
|
5 | 5 | use Psr\Log\LoggerInterface; |
| 6 | +use Psr\Log\NullLogger; |
6 | 7 | use Scheb\TwoFactorBundle\DependencyInjection\Factory\Security\TwoFactorFactory; |
7 | 8 | use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenFactoryInterface; |
8 | 9 | use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface; |
@@ -138,7 +139,7 @@ public function __construct( |
138 | 139 | $this->twoFactorAccessDecider = $twoFactorAccessDecider; |
139 | 140 | $this->eventDispatcher = $eventDispatcher; |
140 | 141 | $this->twoFactorTokenFactory = $twoFactorTokenFactory; |
141 | | - $this->logger = $logger; |
| 142 | + $this->logger = $logger === null ? new NullLogger() : $logger; |
142 | 143 | $this->trustedDeviceManager = $trustedDeviceManager; |
143 | 144 | } |
144 | 145 |
|
@@ -211,19 +212,15 @@ private function attemptAuthentication(Request $request, TwoFactorTokenInterface |
211 | 212 |
|
212 | 213 | private function onFailure(Request $request, AuthenticationException $failed): Response |
213 | 214 | { |
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]); |
217 | 216 | $this->dispatchTwoFactorAuthenticationEvent(TwoFactorAuthenticationEvents::FAILURE, $request, $this->tokenStorage->getToken()); |
218 | 217 |
|
219 | 218 | return $this->failureHandler->onAuthenticationFailure($request, $failed); |
220 | 219 | } |
221 | 220 |
|
222 | 221 | private function onSuccess(Request $request, TokenInterface $token, TwoFactorTokenInterface $previousTwoFactorToken): Response |
223 | 222 | { |
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()]); |
227 | 224 | $this->tokenStorage->setToken($token); |
228 | 225 | $this->dispatchTwoFactorAuthenticationEvent(TwoFactorAuthenticationEvents::SUCCESS, $request, $token); |
229 | 226 |
|
|
0 commit comments