[TASK] Drop salted passwords configuration options
[Packages/TYPO3.CMS.git] / typo3 / sysext / saltedpasswords / Classes / Utility / ExtensionManagerConfigurationUtility.php
1 <?php
2 namespace TYPO3\CMS\Saltedpasswords\Utility;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * class providing configuration checks for saltedpasswords.
22 */
23 class ExtensionManagerConfigurationUtility
24 {
25 /**
26 * @var array
27 */
28 protected $extConf = [];
29
30 /**
31 * Initializes this object.
32 */
33 private function init()
34 {
35 $requestSetup = $this->processPostData((array)$_REQUEST['data']);
36 $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('saltedpasswords');
37 $this->extConf['BE'] = array_merge((array)$extConf['BE'], (array)$requestSetup['BE']);
38 $this->extConf['FE'] = array_merge((array)$extConf['FE'], (array)$requestSetup['FE']);
39 $this->getLanguageService()->includeLLFile('EXT:saltedpasswords/Resources/Private/Language/locallang.xlf');
40 }
41
42 /**
43 * Renders a selector element that allows to select the hash method to be used.
44 *
45 * @param array $params Field information to be rendered
46 * @param string $disposal The configuration disposal ('FE' or 'BE')
47 * @return string The HTML selector
48 */
49 protected function buildHashMethodSelector(array $params, $disposal)
50 {
51 $this->init();
52 $propertyName = $params['propertyName'];
53 $unknownVariablePleaseRenameMe = '\'' . substr(md5($propertyName), 0, 10) . '\'';
54 $pField = '';
55 $registeredMethods = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getRegisteredSaltedHashingMethods();
56 foreach ($registeredMethods as $class => $reference) {
57 $classInstance = GeneralUtility::makeInstance($reference);
58 if ($classInstance instanceof \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface && $classInstance->isAvailable()) {
59 $sel = $this->extConf[$disposal]['saltedPWHashingMethod'] == $class ? ' selected="selected" ' : '';
60 $label = 'ext.saltedpasswords.title.' . strtolower(end(explode('\\', $class)));
61 $pField .= '<option value="' . htmlspecialchars($class) . '"' . $sel . '>' . $GLOBALS['LANG']->getLL($label) . '</option>';
62 }
63 }
64 $pField = '<select class="form-control" id="' . $propertyName . '" name="' . $params['fieldName'] .
65 '" onChange="uFormUrl(' . $unknownVariablePleaseRenameMe . ')">' . $pField . '</select>';
66 return $pField;
67 }
68
69 /**
70 * Renders a selector element that allows to select the hash method to be
71 * used (frontend disposal).
72 *
73 * @param array $params Field information to be rendered
74 * @return string The HTML selector
75 */
76 public function buildHashMethodSelectorFE(array $params)
77 {
78 return $this->buildHashMethodSelector($params, 'FE');
79 }
80
81 /**
82 * Renders a selector element that allows to select the hash method to
83 * be used (backend disposal)
84 *
85 * @param array $params Field information to be rendered
86 * @return string The HTML selector
87 */
88 public function buildHashMethodSelectorBE(array $params)
89 {
90 return $this->buildHashMethodSelector($params, 'BE');
91 }
92
93 /**
94 * Processes the information submitted by the user using a POST request and
95 * transforms it to a TypoScript node notation.
96 *
97 * @param array $postArray Incoming POST information
98 * @return array Processed and transformed POST information
99 */
100 protected function processPostData(array $postArray = [])
101 {
102 foreach ($postArray as $key => $value) {
103 // @todo Explain
104 $parts = explode('.', $key, 2);
105 if (count($parts) == 2) {
106 // @todo Explain
107 $value = $this->processPostData([$parts[1] => $value]);
108 $postArray[$parts[0] . '.'] = array_merge((array)$postArray[$parts[0] . '.'], $value);
109 } else {
110 // @todo Explain
111 $postArray[$parts[0]] = $value;
112 }
113 }
114 return $postArray;
115 }
116
117 /**
118 * @return \TYPO3\CMS\Core\Localization\LanguageService
119 */
120 protected function getLanguageService()
121 {
122 return $GLOBALS['LANG'];
123 }
124 }