2 declare(strict_types = 1);
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
49 private const ALLOWED_ACTIONS = [
'maintenance',
'settings',
'upgrade',
'environment'];
63 $this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
75 $flags = (int)($request->getQueryParams()[
'flags'] ?? 0);
76 $targetController = (string)($request->getQueryParams()[
'targetController'] ??
'');
77 $targetHash = (string)($request->getQueryParams()[
'targetHash'] ??
'');
78 $expectedTargetHash = GeneralUtility::hmac($targetController, BackendModuleController::class);
79 $flagInstallToolPassword = (bool)($flags & self::FLAG_INSTALL_TOOL_PASSWORD);
80 $flagInvalidPassword =
false;
82 if (!in_array($targetController, self::ALLOWED_ACTIONS,
true)
83 || !hash_equals($expectedTargetHash, $targetHash)) {
86 if ($flags & self::FLAG_CONFIRMATION_REQUEST) {
93 $flagInvalidPassword =
true;
96 $view = GeneralUtility::makeInstance(StandaloneView::class);
97 $view->getTemplatePaths()->setTemplatePathAndFilename(
100 'Resources/Private/Templates/BackendModule/BackendUserConfirmation.html'
103 $view->assignMultiple([
104 'flagInvalidPassword' => $flagInvalidPassword,
105 'flagInstallToolPassword' => $flagInstallToolPassword,
106 'languageFileReference' =>
'LLL:EXT:install/Resources/Private/Language/BackendModule.xlf',
108 'targetController' => $targetController,
109 'targetHash' => $targetHash,
111 'flags' => $flags & ~self::FLAG_CONFIRMATION_REQUEST ^ self::FLAG_INSTALL_TOOL_PASSWORD,
114 'targetController' => $targetController,
115 'targetHash' => $targetHash,
117 'flags' => $flags | self::FLAG_CONFIRMATION_REQUEST,
122 return new HtmlResponse($view->render());
184 'targetController' => $targetController,
185 'targetHash' => GeneralUtility::hmac($targetController, BackendModuleController::class),
187 return new RedirectResponse((
string)$redirectUri, 403);
192 return $this->uriBuilder->buildUriFromRoute(
193 'install.backend-user-confirmation',
208 $redirectLocation =
'install.php?install[controller]=' . $controller .
'&install[context]=backend';
209 return new RedirectResponse($redirectLocation, 303);
220 $parsedBody = $request->getParsedBody();
221 $password = $parsedBody[
'confirmationPassword'] ??
null;
222 $installToolPassword =
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'installToolPassword'] ??
null;
223 if (!is_string($password) || empty($installToolPassword)) {
228 $hashFactory = GeneralUtility::makeInstance(PasswordHashFactory::class);
229 $hashInstance = $hashFactory->get($installToolPassword,
'BE');
230 return $hashInstance->checkPassword($password, $installToolPassword);
231 }
catch (InvalidPasswordHashException $exception) {
245 $parsedBody = $request->getParsedBody();
246 $password = empty($parsedBody[
'confirmationPasswordInternal'])
247 ? ($parsedBody[
'confirmationPassword'] ??
null)
248 : $parsedBody[
'confirmationPasswordInternal'];
249 if (!is_string($password)) {
257 'status' =>
'sudo-mode',
258 'origin' => BackendModuleController::class,
259 'uname' => $backendUser->user[
'username'],
260 'uident' => $password,
267 $authenticated =
false;
269 foreach ($this->getAuthServices($backendUser, $loginData, $authInfo) as
$service) {
270 $ret = (int)
$service->authUser($backendUser->user);
280 $authenticated =
true;
283 return $authenticated;
294 protected function getAuthServices(BackendUserAuthentication $backendUser, array $loginData, array $authInfo): \Generator
297 $subType =
'authUserBE';
298 while (
$service = GeneralUtility::makeInstanceService(
'auth', $subType, $serviceChain)) {
299 $serviceChain[] =
$service->getServiceKey();
303 $service->initAuth($subType, $loginData, $authInfo, $backendUser);
321 if ($this->sessionService ===
null) {
322 $this->sessionService =
new SessionService();
323 $this->sessionService->startSession();
333 $rsaEncryptionEncoder = GeneralUtility::makeInstance(RsaEncryptionEncoder::class);
334 $rsaEncryptionEncoder->enableRsaEncryption(
true);