TYPO3 CMS  TYPO3_8-7
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 
27 
32 {
33 
45  public function addHmacData(array $formDefinition): array
46  {
47  // Extend the hmac hashing key with a "per form editor session" unique key.
48  $sessionToken = $this->generateSessionToken();
49  $this->persistSessionToken($sessionToken);
50 
51  $converterDto = GeneralUtility::makeInstance(ConverterDto::class, $formDefinition);
52 
53  GeneralUtility::makeInstance(ArrayProcessor::class, $formDefinition)->forEach(
55  ArrayProcessing::class,
56  'addHmacData',
57  '(^identifier$|renderables\.([\d]+).\identifier$)',
59  AddHmacDataConverter::class,
60  $converterDto,
61  $sessionToken
62  )
63  )
64  );
65 
66  return $converterDto->getFormDefinition();
67  }
68 
75  public function removeHmacData(array $formDefinition): array
76  {
77  $converterDto = GeneralUtility::makeInstance(ConverterDto::class, $formDefinition);
78 
79  GeneralUtility::makeInstance(ArrayProcessor::class, $formDefinition)->forEach(
81  ArrayProcessing::class,
82  'removeHmacData',
83  '(_orig_.*|.*\._orig_.*)\.hmac',
85  RemoveHmacDataConverter::class,
86  $converterDto
87  )
88  )
89  );
90 
91  return $converterDto->getFormDefinition();
92  }
93 
96  protected function persistSessionToken(string $sessionToken)
97  {
98  $this->getBackendUser()->setAndSaveSessionData('extFormProtectionSessionToken', $sessionToken);
99  }
100 
106  protected function generateSessionToken()
107  {
108  return GeneralUtility::makeInstance(Random::class)->generateRandomHexString(64);
109  }
110 
115  {
116  return $GLOBALS['BE_USER'];
117  }
118 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']