‪TYPO3CMS  9.5
FormDefinitionConversionService.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
28 
33 {
34 
46  public function ‪addHmacData(array $formDefinition): array
47  {
48  // Extend the hmac hashing key with a "per form editor session" unique key.
49  $sessionToken = $this->‪generateSessionToken();
50  $this->‪persistSessionToken($sessionToken);
51 
52  $converterDto = GeneralUtility::makeInstance(ConverterDto::class, $formDefinition);
53 
54  GeneralUtility::makeInstance(ArrayProcessor::class, $formDefinition)->forEach(
55  GeneralUtility::makeInstance(
56  ArrayProcessing::class,
57  'addHmacData',
58  '(^identifier$|renderables\.([\d]+)\.identifier$)',
59  GeneralUtility::makeInstance(
60  AddHmacDataConverter::class,
61  $converterDto,
62  $sessionToken
63  )
64  )
65  );
66 
67  return $converterDto->getFormDefinition();
68  }
69 
76  public function ‪removeHmacData(array $formDefinition): array
77  {
78  $converterDto = GeneralUtility::makeInstance(ConverterDto::class, $formDefinition);
79 
80  GeneralUtility::makeInstance(ArrayProcessor::class, $formDefinition)->forEach(
81  GeneralUtility::makeInstance(
82  ArrayProcessing::class,
83  'removeHmacData',
84  '(_orig_.*|.*\._orig_.*)\.hmac',
85  GeneralUtility::makeInstance(
86  RemoveHmacDataConverter::class,
87  $converterDto
88  )
89  )
90  );
91 
92  return $converterDto->getFormDefinition();
93  }
94 
101  public function ‪migrateFinisherConfiguration(array $formDefinition): array
102  {
103  $converterDto = GeneralUtility::makeInstance(ConverterDto::class, $formDefinition);
104 
105  GeneralUtility::makeInstance(ArrayProcessor::class, $formDefinition)->forEach(
106  GeneralUtility::makeInstance(
107  ArrayProcessing::class,
108  'migrateFinisherLanguageSettings',
109  '^finishers\.([\d]+)\.options.translation.language$',
110  GeneralUtility::makeInstance(
111  FinisherTranslationLanguageConverter::class,
112  $converterDto
113  )
114  )
115  );
116 
117  return $converterDto->getFormDefinition();
118  }
119 
123  protected function ‪persistSessionToken(string $sessionToken)
124  {
125  $this->‪getBackendUser()->‪setAndSaveSessionData('extFormProtectionSessionToken', $sessionToken);
126  }
127 
133  protected function ‪generateSessionToken()
134  {
135  return GeneralUtility::makeInstance(Random::class)->generateRandomHexString(64);
136  }
137 
142  {
143  return ‪$GLOBALS['BE_USER'];
144  }
145 }
‪TYPO3\CMS\Form\Domain\Configuration
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\FinisherTranslationLanguageConverter
Definition: FinisherTranslationLanguageConverter.php:24
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\ConverterDto
Definition: ConverterDto.php:22
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService
Definition: FormDefinitionConversionService.php:33
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService\generateSessionToken
‪string generateSessionToken()
Definition: FormDefinitionConversionService.php:133
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\RemoveHmacDataConverter
Definition: RemoveHmacDataConverter.php:24
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService\persistSessionToken
‪persistSessionToken(string $sessionToken)
Definition: FormDefinitionConversionService.php:123
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\AddHmacDataConverter
Definition: AddHmacDataConverter.php:27
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessing
Definition: ArrayProcessing.php:25
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessor
Definition: ArrayProcessor.php:28
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService\addHmacData
‪array addHmacData(array $formDefinition)
Definition: FormDefinitionConversionService.php:46
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication\setAndSaveSessionData
‪setAndSaveSessionData($key, $data)
Definition: AbstractUserAuthentication.php:1285
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService\removeHmacData
‪array removeHmacData(array $formDefinition)
Definition: FormDefinitionConversionService.php:76
‪TYPO3\CMS\Core\Crypto\Random
Definition: Random.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService\migrateFinisherConfiguration
‪array migrateFinisherConfiguration(array $formDefinition)
Definition: FormDefinitionConversionService.php:101
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: FormDefinitionConversionService.php:141