Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Dispatch event on failed mfa attempt
By dispatching a new PSR-14 Event on a failed multi-factor authentication attempt, it's now possible to consider such failed attempts in the "send email on failed login" functionality. The improved log message does now also use the correct "action" and "error" types, which allows further functionality, such as the corresponding dashboard widget, to make use of those information. Resolves: #100129 Releases: main, 12.4 Change-Id: I52047bc45dba124f050aa31640444ce4af12c4df Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79816 Reviewed-by: Oliver Bartsch <bo@cedev.de> Tested-by: core-ci <typo3@b13.com> Tested-by: Oliver Bartsch <bo@cedev.de>
- Loading branch information
Showing
7 changed files
with
135 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
typo3/sysext/core/Classes/Authentication/Event/AbstractAuthenticationFailedEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\Core\Authentication\Event; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication; | ||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; | ||
|
||
/** | ||
* Class to be extended by events, fired after authentication has failed | ||
*/ | ||
abstract class AbstractAuthenticationFailedEvent | ||
{ | ||
public function __construct( | ||
private readonly ServerRequestInterface $request | ||
) { | ||
} | ||
|
||
/** | ||
* Returns the user, who failed to authenticate successfully | ||
*/ | ||
abstract public function getUser(): AbstractUserAuthentication; | ||
|
||
public function isFrontendAttempt(): bool | ||
{ | ||
return !$this->isBackendAttempt(); | ||
} | ||
|
||
public function isBackendAttempt(): bool | ||
{ | ||
return $this->getUser() instanceof BackendUserAuthentication; | ||
} | ||
|
||
public function getRequest(): ServerRequestInterface | ||
{ | ||
return $this->request; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
typo3/sysext/core/Classes/Authentication/Event/MfaVerificationFailedEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\Core\Authentication\Event; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication; | ||
use TYPO3\CMS\Core\Authentication\Mfa\MfaProviderPropertyManager; | ||
|
||
/** | ||
* Event fired after MFA verification failed. | ||
*/ | ||
final class MfaVerificationFailedEvent extends AbstractAuthenticationFailedEvent | ||
{ | ||
public function __construct( | ||
private readonly ServerRequestInterface $request, | ||
private readonly MfaProviderPropertyManager $propertyManager, | ||
) { | ||
parent::__construct($this->request); | ||
} | ||
|
||
public function getUser(): AbstractUserAuthentication | ||
{ | ||
return $this->propertyManager->getUser(); | ||
} | ||
|
||
public function getProviderIdentifier(): string | ||
{ | ||
return $this->propertyManager->getIdentifier(); | ||
} | ||
|
||
public function getProviderProperties(): array | ||
{ | ||
return $this->propertyManager->getProperties(); | ||
} | ||
} |