diff options
-rw-r--r-- | core/Controller/TwoFactorChallengeController.php | 11 | ||||
-rw-r--r-- | tests/Core/Controller/TwoFactorChallengeControllerTest.php | 5 |
2 files changed, 15 insertions, 1 deletions
diff --git a/core/Controller/TwoFactorChallengeController.php b/core/Controller/TwoFactorChallengeController.php index e08454caea6..30f33230d8f 100644 --- a/core/Controller/TwoFactorChallengeController.php +++ b/core/Controller/TwoFactorChallengeController.php @@ -35,6 +35,7 @@ use OCP\Authentication\TwoFactorAuth\IActivatableAtLogin; use OCP\Authentication\TwoFactorAuth\IProvider; use OCP\Authentication\TwoFactorAuth\IProvidesCustomCSP; use OCP\Authentication\TwoFactorAuth\TwoFactorException; +use OCP\ILogger; use OCP\IRequest; use OCP\ISession; use OCP\IURLGenerator; @@ -51,6 +52,9 @@ class TwoFactorChallengeController extends Controller { /** @var ISession */ private $session; + /** @var ILogger */ + private $logger; + /** @var IURLGenerator */ private $urlGenerator; @@ -61,14 +65,16 @@ class TwoFactorChallengeController extends Controller { * @param IUserSession $userSession * @param ISession $session * @param IURLGenerator $urlGenerator + * @param ILogger $logger */ public function __construct($appName, IRequest $request, Manager $twoFactorManager, IUserSession $userSession, - ISession $session, IURLGenerator $urlGenerator) { + ISession $session, IURLGenerator $urlGenerator, ILogger $logger) { parent::__construct($appName, $request); $this->twoFactorManager = $twoFactorManager; $this->userSession = $userSession; $this->session = $session; $this->urlGenerator = $urlGenerator; + $this->logger = $logger; } /** @@ -208,6 +214,9 @@ class TwoFactorChallengeController extends Controller { $this->session->set('two_factor_auth_error_message', $e->getMessage()); } + $ip = $this->request->getRemoteAddress(); + $uid = $user->getUID(); + $this->logger->warning("Two-factor challenge failed: $uid (Remote IP: $ip)"); $this->session->set('two_factor_auth_error', true); return new RedirectResponse($this->urlGenerator->linkToRoute('core.TwoFactorChallenge.showChallenge', [ 'challengeProviderId' => $provider->getId(), diff --git a/tests/Core/Controller/TwoFactorChallengeControllerTest.php b/tests/Core/Controller/TwoFactorChallengeControllerTest.php index 1a2a4d8eaa5..b899a1b236a 100644 --- a/tests/Core/Controller/TwoFactorChallengeControllerTest.php +++ b/tests/Core/Controller/TwoFactorChallengeControllerTest.php @@ -57,6 +57,9 @@ class TwoFactorChallengeControllerTest extends TestCase { /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ private $urlGenerator; + /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */ + private $logger; + /** @var TwoFactorChallengeController|\PHPUnit\Framework\MockObject\MockObject */ private $controller; @@ -68,6 +71,7 @@ class TwoFactorChallengeControllerTest extends TestCase { $this->userSession = $this->createMock(IUserSession::class); $this->session = $this->createMock(ISession::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->logger = $this->createMock(ILogger::class); $this->controller = $this->getMockBuilder(TwoFactorChallengeController::class) ->setConstructorArgs([ @@ -77,6 +81,7 @@ class TwoFactorChallengeControllerTest extends TestCase { $this->userSession, $this->session, $this->urlGenerator, + $this->logger, ]) ->setMethods(['getLogoutUrl']) ->getMock(); |