Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log failed twofactor authentication #37401

Merged
merged 1 commit into from
Jun 15, 2020
Merged
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
6 changes: 6 additions & 0 deletions changelog/unreleased/37401
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Log failed twofactor authentication

When user entered bad twofactor authentication (i.e. code) there was no message
in application log. This change will log this failed authentication.

https://github.com/owncloud/core/pull/37401
17 changes: 16 additions & 1 deletion lib/private/Authentication/TwoFactorAuth/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use OCP\AppFramework\QueryException;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\IConfig;
use OCP\IRequest;
use OCP\ILogger;
use OCP\ISession;
use OCP\IUser;

Expand All @@ -44,15 +46,25 @@ class Manager {
/** @var IConfig */
private $config;

/** @var IRequest */
private $request;

/** @var ILogger */
private $logger;

/**
* @param AppManager $appManager
* @param ISession $session
* @param IConfig $config
* @param IRequest $request
* @param ILogger $logger
*/
public function __construct(AppManager $appManager, ISession $session, IConfig $config) {
public function __construct(AppManager $appManager, ISession $session, IConfig $config, IRequest $request, ILogger $logger) {
$this->appManager = $appManager;
$this->session = $session;
$this->config = $config;
$this->request = $request;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -157,6 +169,9 @@ public function verifyChallenge($providerId, IUser $user, $challenge) {
$result = $provider->verifyChallenge($user, $challenge);
if ($result) {
$this->session->remove(self::SESSION_UID_KEY);
} else {
$this->logger->warning("Two factor verify failed: '{$user->getUserName()}' (Remote IP: '{$this->request->getRemoteAddress()}')",
['app' => 'core']);
}
return $result;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public function __construct($webRoot, \OC\Config $config) {
});

$this->registerService('\OC\Authentication\TwoFactorAuth\Manager', function (Server $c) {
return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig());
return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getRequest(), $c->getLogger());
});

$this->registerService('NavigationManager', function (Server $c) {
Expand Down
10 changes: 9 additions & 1 deletion tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class ManagerTest extends TestCase {
/** @var \OCP\IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $config;

/** @var \OCP\IRequest | \PHPUnit\Framework\MockObject\MockObject */
private $request;

/** @var \OCP\ILogger | \PHPUnit\Framework\MockObject\MockObject */
private $logger;

/** @var \OCP\Authentication\TwoFactorAuth\IProvider|\PHPUnit\Framework\MockObject\MockObject */
private $fakeProvider;

Expand All @@ -54,9 +60,11 @@ protected function setUp(): void {
->getMock();
$this->session = $this->createMock('\OCP\ISession');
$this->config = $this->createMock('\OCP\IConfig');
$this->request = $this->createMock('\OCP\IRequest');
$this->logger = $this->createMock('\OCP\ILogger');

$this->manager = $this->getMockBuilder('\OC\Authentication\TwoFactorAuth\Manager')
->setConstructorArgs([$this->appManager, $this->session, $this->config])
->setConstructorArgs([$this->appManager, $this->session, $this->config, $this->request, $this->logger])
->setMethods(['loadTwoFactorApp']) // Do not actually load the apps
->getMock();

Expand Down