mfaProviderRegistry = $mfaProviderRegistry; } /** * Main action for handling the request and returning the response */ abstract public function handleRequest(ServerRequestInterface $request): ResponseInterface; protected function isActionAllowed(string $action): bool { return in_array($action, $this->allowedActions, true); } protected function isProviderAllowed(string $identifier): bool { return isset($this->allowedProviders[$identifier]); } protected function isValidIdentifier(string $identifier): bool { return $identifier !== '' && $this->isProviderAllowed($identifier) && $this->mfaProviderRegistry->hasProvider($identifier); } /** * Initialize MFA configuration based on TSconfig and global configuration */ protected function initializeMfaConfiguration(): void { $backendUser = $this->getBackendUser(); $this->mfaTsConfig = $backendUser->getTSConfig()['auth.']['mfa.'] ?? []; $this->mfaRequired = $backendUser->isMfaSetupRequired(); // Set up allowed providers based on user TSconfig and user groupData $this->allowedProviders = array_filter($this->mfaProviderRegistry->getProviders(), function (string $identifier) use ($backendUser): bool { return $backendUser->check('mfa_providers', $identifier) && !GeneralUtility::inList(($this->mfaTsConfig['disableProviders'] ?? ''), $identifier); }, ARRAY_FILTER_USE_KEY); } /** * Get the recommended provider */ protected function getRecommendedProvider(): ?MfaProviderManifestInterface { $recommendedProviderIdentifier = (string)($this->mfaTsConfig['recommendedProvider'] ?? ''); // Check if valid and allowed to be default provider, which is obviously a prerequisite if (!$this->isValidIdentifier($recommendedProviderIdentifier) || !$this->mfaProviderRegistry->getProvider($recommendedProviderIdentifier)->isDefaultProviderAllowed() ) { // If the provider, defined in user TSconfig is not valid or is not set, check the globally defined $recommendedProviderIdentifier = (string)($GLOBALS['TYPO3_CONF_VARS']['BE']['recommendedMfaProvider'] ?? ''); if (!$this->isValidIdentifier($recommendedProviderIdentifier) || !$this->mfaProviderRegistry->getProvider($recommendedProviderIdentifier)->isDefaultProviderAllowed() ) { // If also not valid or not set, return return null; } } return $this->mfaProviderRegistry->getProvider($recommendedProviderIdentifier); } protected function getBackendUser(): BackendUserAuthentication { return $GLOBALS['BE_USER']; } protected function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } }