‪TYPO3CMS  10.4
FormDefinitionConversionService.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
30 
35 {
36 
48  public function ‪addHmacData(array $formDefinition): array
49  {
50  // Extend the hmac hashing key with a "per form editor session" unique key.
51  $sessionToken = $this->‪generateSessionToken();
52  $this->‪persistSessionToken($sessionToken);
53 
54  $converterDto = GeneralUtility::makeInstance(ConverterDto::class, $formDefinition);
55 
56  GeneralUtility::makeInstance(ArrayProcessor::class, $formDefinition)->forEach(
57  GeneralUtility::makeInstance(
58  ArrayProcessing::class,
59  'addHmacData',
60  '(^identifier$|renderables\.([\d]+)\.identifier$)',
61  GeneralUtility::makeInstance(
62  AddHmacDataConverter::class,
63  $converterDto,
64  $sessionToken
65  )
66  )
67  );
68 
69  return $converterDto->getFormDefinition();
70  }
71 
78  public function ‪removeHmacData(array $formDefinition): array
79  {
80  $converterDto = GeneralUtility::makeInstance(ConverterDto::class, $formDefinition);
81 
82  GeneralUtility::makeInstance(ArrayProcessor::class, $formDefinition)->forEach(
83  GeneralUtility::makeInstance(
84  ArrayProcessing::class,
85  'removeHmacData',
86  '(_orig_.*|.*\._orig_.*)\.hmac',
87  GeneralUtility::makeInstance(
88  RemoveHmacDataConverter::class,
89  $converterDto
90  )
91  )
92  );
93 
94  return $converterDto->getFormDefinition();
95  }
96 
103  public function ‪migrateFinisherConfiguration(array $formDefinition): array
104  {
105  $converterDto = GeneralUtility::makeInstance(ConverterDto::class, $formDefinition);
106 
107  GeneralUtility::makeInstance(ArrayProcessor::class, $formDefinition)->forEach(
108  GeneralUtility::makeInstance(
109  ArrayProcessing::class,
110  'migrateFinisherLanguageSettings',
111  '^finishers\.([\d]+)\.options.translation.language$',
112  GeneralUtility::makeInstance(
113  FinisherTranslationLanguageConverter::class,
114  $converterDto
115  )
116  )
117  );
118 
119  return $converterDto->getFormDefinition();
120  }
121 
125  protected function ‪persistSessionToken(string $sessionToken)
126  {
127  $this->‪getBackendUser()->‪setAndSaveSessionData('extFormProtectionSessionToken', $sessionToken);
128  }
129 
135  protected function ‪generateSessionToken()
136  {
137  return GeneralUtility::makeInstance(Random::class)->generateRandomHexString(64);
138  }
139 
144  {
145  return ‪$GLOBALS['BE_USER'];
146  }
147 }
‪TYPO3\CMS\Form\Domain\Configuration
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\FinisherTranslationLanguageConverter
Definition: FinisherTranslationLanguageConverter.php:26
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\ConverterDto
Definition: ConverterDto.php:24
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService
Definition: FormDefinitionConversionService.php:35
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService\generateSessionToken
‪string generateSessionToken()
Definition: FormDefinitionConversionService.php:135
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\RemoveHmacDataConverter
Definition: RemoveHmacDataConverter.php:26
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService\persistSessionToken
‪persistSessionToken(string $sessionToken)
Definition: FormDefinitionConversionService.php:125
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Converters\AddHmacDataConverter
Definition: AddHmacDataConverter.php:29
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessing
Definition: ArrayProcessing.php:27
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessor
Definition: ArrayProcessor.php:30
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService\addHmacData
‪array addHmacData(array $formDefinition)
Definition: FormDefinitionConversionService.php:48
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication\setAndSaveSessionData
‪setAndSaveSessionData($key, $data)
Definition: AbstractUserAuthentication.php:1233
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪$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:78
‪TYPO3\CMS\Core\Crypto\Random
Definition: Random.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService\migrateFinisherConfiguration
‪array migrateFinisherConfiguration(array $formDefinition)
Definition: FormDefinitionConversionService.php:103
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: FormDefinitionConversionService.php:143