summaryrefslogtreecommitdiffstats
path: root/lib/private/Authentication/TwoFactorAuth
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2021-03-05 16:02:17 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2021-03-22 20:57:10 +0100
commit3c5cf825b396eacdc3e2376137e010552796119e (patch)
tree4454b1c5264908a0dc65e6d31d786a87b335577e /lib/private/Authentication/TwoFactorAuth
parent90909ab9b9f2263e854788802794007a6d766356 (diff)
downloadnextcloud-server-3c5cf825b396eacdc3e2376137e010552796119e.tar.gz
nextcloud-server-3c5cf825b396eacdc3e2376137e010552796119e.zip
Add real events for enabled 2fa providers for users
* Shiny new events * Listener to still emit the old event Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Authentication/TwoFactorAuth')
-rw-r--r--lib/private/Authentication/TwoFactorAuth/Manager.php20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/private/Authentication/TwoFactorAuth/Manager.php b/lib/private/Authentication/TwoFactorAuth/Manager.php
index d95cc8b1ebf..4391f7d108e 100644
--- a/lib/private/Authentication/TwoFactorAuth/Manager.php
+++ b/lib/private/Authentication/TwoFactorAuth/Manager.php
@@ -37,6 +37,9 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Authentication\TwoFactorAuth\IActivatableAtLogin;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\Authentication\TwoFactorAuth\IRegistry;
+use OCP\Authentication\TwoFactorAuth\TwoFactorProviderForUserDisabled;
+use OCP\Authentication\TwoFactorAuth\TwoFactorProviderForUserEnabled;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\ISession;
use OCP\IUser;
@@ -79,9 +82,12 @@ class Manager {
/** @var ITimeFactory */
private $timeFactory;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $dispatcher;
+ /** @var EventDispatcherInterface */
+ private $legacyDispatcher;
+
public function __construct(ProviderLoader $providerLoader,
IRegistry $providerRegistry,
MandatoryTwoFactor $mandatoryTwoFactor,
@@ -91,7 +97,8 @@ class Manager {
LoggerInterface $logger,
TokenProvider $tokenProvider,
ITimeFactory $timeFactory,
- EventDispatcherInterface $eventDispatcher) {
+ IEventDispatcher $eventDispatcher,
+ EventDispatcherInterface $legacyDispatcher) {
$this->providerLoader = $providerLoader;
$this->providerRegistry = $providerRegistry;
$this->mandatoryTwoFactor = $mandatoryTwoFactor;
@@ -102,6 +109,7 @@ class Manager {
$this->tokenProvider = $tokenProvider;
$this->timeFactory = $timeFactory;
$this->dispatcher = $eventDispatcher;
+ $this->legacyDispatcher = $legacyDispatcher;
}
/**
@@ -267,14 +275,18 @@ class Manager {
$this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $tokenId);
$dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]);
- $this->dispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent);
+ $this->legacyDispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent);
+
+ $this->dispatcher->dispatchTyped(new TwoFactorProviderForUserEnabled($user, $provider));
$this->publishEvent($user, 'twofactor_success', [
'provider' => $provider->getDisplayName(),
]);
} else {
$dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]);
- $this->dispatcher->dispatch(IProvider::EVENT_FAILED, $dispatchEvent);
+ $this->legacyDispatcher->dispatch(IProvider::EVENT_FAILED, $dispatchEvent);
+
+ $this->dispatcher->dispatchTyped(new TwoFactorProviderForUserDisabled($user, $provider));
$this->publishEvent($user, 'twofactor_failed', [
'provider' => $provider->getDisplayName(),