|
5 | 5 | namespace Scheb\TwoFactorBundle\Security\Http\Firewall; |
6 | 6 |
|
7 | 7 | use Psr\Log\LoggerInterface; |
| 8 | +use Psr\Log\NullLogger; |
8 | 9 | use Scheb\TwoFactorBundle\DependencyInjection\Factory\Security\TwoFactorFactory; |
9 | 10 | use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenFactoryInterface; |
10 | 11 | use Scheb\TwoFactorBundle\Security\Authentication\Token\TwoFactorTokenInterface; |
@@ -140,7 +141,7 @@ public function __construct( |
140 | 141 | $this->twoFactorAccessDecider = $twoFactorAccessDecider; |
141 | 142 | $this->eventDispatcher = $eventDispatcher; |
142 | 143 | $this->twoFactorTokenFactory = $twoFactorTokenFactory; |
143 | | - $this->logger = $logger; |
| 144 | + $this->logger = $logger === null ? new NullLogger() : $logger; |
144 | 145 | $this->trustedDeviceManager = $trustedDeviceManager; |
145 | 146 | } |
146 | 147 |
|
@@ -215,19 +216,15 @@ private function attemptAuthentication(Request $request, TwoFactorTokenInterface |
215 | 216 |
|
216 | 217 | private function onFailure(Request $request, AuthenticationException $failed): Response |
217 | 218 | { |
218 | | - if ($this->logger) { |
219 | | - $this->logger->info('Two-factor authentication request failed.', ['exception' => $failed]); |
220 | | - } |
| 219 | + $this->logger->info('Two-factor authentication request failed.', ['exception' => $failed]); |
221 | 220 | $this->dispatchTwoFactorAuthenticationEvent(TwoFactorAuthenticationEvents::FAILURE, $request, $this->tokenStorage->getToken()); |
222 | 221 |
|
223 | 222 | return $this->failureHandler->onAuthenticationFailure($request, $failed); |
224 | 223 | } |
225 | 224 |
|
226 | 225 | private function onSuccess(Request $request, TokenInterface $token, TwoFactorTokenInterface $previousTwoFactorToken): Response |
227 | 226 | { |
228 | | - if ($this->logger) { |
229 | | - $this->logger->info('User has been two-factor authenticated successfully.', ['username' => $token->getUsername()]); |
230 | | - } |
| 227 | + $this->logger->info('User has been two-factor authenticated successfully.', ['username' => $token->getUsername()]); |
231 | 228 | $this->tokenStorage->setToken($token); |
232 | 229 | $this->dispatchTwoFactorAuthenticationEvent(TwoFactorAuthenticationEvents::SUCCESS, $request, $token); |
233 | 230 |
|
|
0 commit comments