[TASK] Move default salt methods to factory function 69/23369/7
authorNicole Cordes <typo3@cordes.co>
Tue, 27 Aug 2013 15:25:24 +0000 (17:25 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 27 Aug 2013 17:31:39 +0000 (19:31 +0200)
To use saltedpasswords in the install tool it is necessary to move the
default salt methods registration from ext_localconf.php to the salt
factory. This patch adds an initialize function to set the default salt
methods.

Resolves: #51404
Releases: 6.2
Change-Id: Iaa4547255c8d6e3b0b0fd75c0aaadfa54109ba27
Reviewed-on: https://review.typo3.org/23369
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/saltedpasswords/Classes/Salt/SaltFactory.php
typo3/sysext/saltedpasswords/Classes/Utility/ExtensionManagerConfigurationUtility.php
typo3/sysext/saltedpasswords/Classes/Utility/SaltedPasswordsUtility.php
typo3/sysext/saltedpasswords/Documentation/DevelopersGuide/Index.rst
typo3/sysext/saltedpasswords/ext_localconf.php

index 13647a9..1d4e46e 100644 (file)
@@ -44,6 +44,33 @@ class SaltFactory {
        static protected $instance = NULL;
 
        /**
+        * Returns list of all registered hashing methods. Used eg. in
+        * extension configuration to select the default hashing method.
+        *
+        * @return array
+        */
+       static public function getRegisteredSaltedHashingMethods() {
+               return array_merge(
+                       static::getDefaultSaltMethods(),
+                       (array) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods']
+               );
+       }
+
+       /**
+        * Returns an array with default salt methods.
+        *
+        * @return array
+        */
+       static protected function getDefaultSaltMethods() {
+               return array(
+                       'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt',
+                       'TYPO3\\CMS\\Saltedpasswords\\Salt\\BlowfishSalt' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\BlowfishSalt',
+                       'TYPO3\\CMS\\Saltedpasswords\\Salt\\PhpassSalt' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\PhpassSalt'
+               );
+       }
+
+
+       /**
         * Obtains a salting hashing method instance.
         *
         * This function will return an instance of a class that implements
@@ -69,8 +96,8 @@ class SaltFactory {
                                }
                        } else {
                                $classNameToUse = \TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::getDefaultSaltingHashingMethod($mode);
-                               $availableClasses = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods'];
-                               self::$instance = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($availableClasses[$classNameToUse], 'tx_');
+                               $availableClasses = static::getRegisteredSaltedHashingMethods();
+                               self::$instance = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($availableClasses[$classNameToUse]);
                        }
                }
                return self::$instance;
@@ -86,9 +113,9 @@ class SaltFactory {
         */
        static public function determineSaltingHashingMethod($saltedHash) {
                $methodFound = FALSE;
-               $defaultMethods = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods'];
-               foreach ($defaultMethods as $method) {
-                       $objectInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($method, 'tx_');
+               $registeredMethods = static::getRegisteredSaltedHashingMethods();
+               foreach ($registeredMethods as $method) {
+                       $objectInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($method);
                        if ($objectInstance instanceof \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface) {
                                $methodFound = $objectInstance->isValidSaltedPW($saltedHash);
                                if ($methodFound) {
@@ -114,6 +141,5 @@ class SaltFactory {
                }
                return self::$instance;
        }
-
 }
 ?>
\ No newline at end of file
index b663ad2..d3373f2 100644 (file)
@@ -350,7 +350,8 @@ Please disable either one of them.';
                $propertyName = $params['propertyName'];
                $unknownVariablePleaseRenameMe = '\'' . substr(md5($propertyName), 0, 10) . '\'';
                $p_field = '';
-               foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods'] as $class => $reference) {
+               $registeredMethods = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getRegisteredSaltedHashingMethods();
+               foreach ($registeredMethods as $class => $reference) {
                        $classInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($reference, 'tx_');
                        if ($classInstance instanceof \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface && $classInstance->isAvailable()) {
                                $sel = $this->extConf[$disposal]['saltedPWHashingMethod'] == $class ? ' selected="selected" ' : '';
index 0cf80aa..969433b 100644 (file)
@@ -111,7 +111,7 @@ class SaltedPasswordsUtility {
        static public function getDefaultSaltingHashingMethod($mode = TYPO3_MODE) {
                $extConf = self::returnExtConf($mode);
                $classNameToUse = 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt';
-               if (in_array($extConf['saltedPWHashingMethod'], array_keys($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods']))) {
+               if (in_array($extConf['saltedPWHashingMethod'], array_keys(\TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getRegisteredSaltedHashingMethods()))) {
                        $classNameToUse = $extConf['saltedPWHashingMethod'];
                }
                return $classNameToUse;
index 2a84ae9..9a000eb 100644 (file)
@@ -105,5 +105,5 @@ Steps to be done:
 
 - register your salting method class
   (:code:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods']`)
-  to make it available for the salt factory (see :file:`ext_localconf.php` for an example)
+  to make it available for the salt factory (see :file:`Classes\Salt\SaltFactory.php` for an example)
 
index 673ed00..9288615 100644 (file)
@@ -11,12 +11,8 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals']['tx_saltedpassword
 // Hook for processing "forgotPassword" in felogin
 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['password_changed'][] = 'TYPO3\\CMS\\Saltedpasswords\\Utility\\SaltedPasswordsUtility->feloginForgotPasswordHook';
 
-// Registering all available hashes to factory
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods'] = array(
-       'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt',
-       'TYPO3\\CMS\\Saltedpasswords\\Salt\\BlowfishSalt' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\BlowfishSalt',
-       'TYPO3\\CMS\\Saltedpasswords\\Salt\\PhpassSalt' => 'TYPO3\\CMS\\Saltedpasswords\\Salt\\PhpassSalt'
-);
+// Extension may register additional salted hashing methods in this array
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods'] = array();
 
 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addService('saltedpasswords', 'auth', 'TYPO3\\CMS\\Saltedpasswords\\SaltedPasswordService', array(
        'title' => 'FE/BE Authentification salted',