Skip to content

Commit

Permalink
Only check the twofactor state once per request
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Dec 1, 2021
1 parent b67c6d9 commit febca70
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/private/Authentication/TwoFactorAuth/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class Manager {
/** @var EventDispatcherInterface */
private $legacyDispatcher;

/** @psalm-var array<string, bool> */
private $userIsTwoFactorAuthenticated = [];

public function __construct(ProviderLoader $providerLoader,
IRegistry $providerRegistry,
MandatoryTwoFactor $mandatoryTwoFactor,
Expand Down Expand Up @@ -118,6 +121,10 @@ public function __construct(ProviderLoader $providerLoader,
* @return boolean
*/
public function isTwoFactorAuthenticated(IUser $user): bool {
if (isset($this->userIsTwoFactorAuthenticated[$user->getUID()])) {
return $this->userIsTwoFactorAuthenticated[$user->getUID()];
}

if ($this->mandatoryTwoFactor->isEnforcedFor($user)) {
return true;
}
Expand All @@ -129,7 +136,8 @@ public function isTwoFactorAuthenticated(IUser $user): bool {
$providerIds = array_keys($enabled);
$providerIdsWithoutBackupCodes = array_diff($providerIds, [self::BACKUP_CODES_PROVIDER_ID]);

return !empty($providerIdsWithoutBackupCodes);
$this->userIsTwoFactorAuthenticated[$user->getUID()] = !empty($providerIdsWithoutBackupCodes);
return $this->userIsTwoFactorAuthenticated[$user->getUID()];
}

/**
Expand Down

0 comments on commit febca70

Please sign in to comment.