From c83546d268bd066a282f52c0129bb5823e20c1c1 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 25 Apr 2013 17:40:52 +0200 Subject: [PATCH] [Security] tweaked previous commit --- composer.json | 6 +-- .../DependencyInjection/SecurityExtension.php | 39 +++++++------------ .../SecurityExtensionTest.php | 5 +-- src/Symfony/Component/Routing/CHANGELOG.md | 2 + .../Core/Encoder/BCryptPasswordEncoder.php | 4 +- src/Symfony/Component/Security/composer.json | 9 +++-- 6 files changed, 27 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index bef084776e..504b48d92c 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,7 @@ "symfony/icu": "~1.0", "doctrine/common": "~2.2", "twig/twig": "~1.11", - "psr/log": "~1.0", - "ircmaxell/password-compat": "1.0.*" + "psr/log": "~1.0" }, "replace": { "symfony/browser-kit": "self.version", @@ -66,7 +65,8 @@ "doctrine/dbal": "~2.2", "doctrine/orm": "~2.2,>=2.2.3", "monolog/monolog": "~1.3", - "propel/propel1": "1.6.*" + "propel/propel1": "1.6.*", + "ircmaxell/password-compat": "1.0.*" }, "autoload": { "psr-0": { "Symfony\\": "src/" }, diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index d5de24433e..936552c4e9 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -452,42 +452,33 @@ class SecurityExtension extends Extension // pbkdf2 encoder if ('pbkdf2' === $config['algorithm']) { - $arguments = array( - $config['hash_algorithm'], - $config['encode_as_base64'], - $config['iterations'], - $config['key_length'], - ); - return array( - 'class' => new Parameter('security.encoder.pbkdf2.class'), - 'arguments' => $arguments, + 'class' => new Parameter('security.encoder.pbkdf2.class'), + 'arguments' => array( + $config['hash_algorithm'], + $config['encode_as_base64'], + $config['iterations'], + $config['key_length'], + ), ); } // bcrypt encoder if ('bcrypt' === $config['algorithm']) { - $arguments = array( - new Reference('security.secure_random'), - $config['cost'], - ); - return array( - 'class' => new Parameter('security.encoder.bcrypt.class'), - 'arguments' => $arguments, + 'class' => new Parameter('security.encoder.bcrypt.class'), + 'arguments' => array($config['cost']), ); } // message digest encoder - $arguments = array( - $config['algorithm'], - $config['encode_as_base64'], - $config['iterations'], - ); - return array( - 'class' => new Parameter('security.encoder.digest.class'), - 'arguments' => $arguments, + 'class' => new Parameter('security.encoder.digest.class'), + 'arguments' => array( + $config['algorithm'], + $config['encode_as_base64'], + $config['iterations'], + ), ); } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php index 948e272205..b85e850c23 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php @@ -160,10 +160,7 @@ abstract class SecurityExtensionTest extends \PHPUnit_Framework_TestCase ), 'JMS\FooBundle\Entity\User6' => array( 'class' => new Parameter('security.encoder.bcrypt.class'), - 'arguments' => array( - new Reference('security.secure_random'), - 15, - ) + 'arguments' => array(15), ), )), $container->getDefinition('security.encoder_factory.generic')->getArguments()); } diff --git a/src/Symfony/Component/Routing/CHANGELOG.md b/src/Symfony/Component/Routing/CHANGELOG.md index f0c616d080..05701440e1 100644 --- a/src/Symfony/Component/Routing/CHANGELOG.md +++ b/src/Symfony/Component/Routing/CHANGELOG.md @@ -4,11 +4,13 @@ CHANGELOG 2.3.0 ----- + * [BC BREAK] the BCrypt encoder constructor signature has changed (the first argument was removed) * added RequestContext::getQueryString() 2.2.0 ----- + * Added BCrypt password encoder * [DEPRECATION] Several route settings have been renamed (the old ones will be removed in 3.0): * The `pattern` setting for a route has been deprecated in favor of `path` diff --git a/src/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.php b/src/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.php index 3a9d03ee70..6a65fa521e 100644 --- a/src/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.php +++ b/src/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.php @@ -46,9 +46,7 @@ class BCryptPasswordEncoder extends BasePasswordEncoder */ public function encodePassword($raw, $salt) { - return password_hash($raw, PASSWORD_BCRYPT, array( - 'cost' => $this->cost, - )); + return password_hash($raw, PASSWORD_BCRYPT, array('cost' => $this->cost)); } /** diff --git a/src/Symfony/Component/Security/composer.json b/src/Symfony/Component/Security/composer.json index c66949c687..5ea71f38b8 100644 --- a/src/Symfony/Component/Security/composer.json +++ b/src/Symfony/Component/Security/composer.json @@ -19,8 +19,7 @@ "php": ">=5.3.3", "symfony/event-dispatcher": "~2.1", "symfony/http-foundation": ">=2.1,<2.4-dev", - "symfony/http-kernel": ">=2.1,<=2.3-dev", - "ircmaxell/password-compat": "1.0.*" + "symfony/http-kernel": ">=2.1,<=2.3-dev" }, "require-dev": { "symfony/form": "~2.0", @@ -28,7 +27,8 @@ "symfony/validator": ">=2.2,<2.4-dev", "doctrine/common": "~2.2", "doctrine/dbal": "~2.2", - "psr/log": "~1.0" + "psr/log": "~1.0", + "ircmaxell/password-compat": "1.0.*" }, "suggest": { "symfony/class-loader": "2.2.*", @@ -36,7 +36,8 @@ "symfony/form": "2.2.*", "symfony/validator": "2.2.*", "symfony/routing": "2.2.*", - "doctrine/dbal": "to use the built-in ACL implementation" + "doctrine/dbal": "to use the built-in ACL implementation", + "ircmaxell/password-compat": "1.0.*" }, "autoload": { "psr-0": { "Symfony\\Component\\Security\\": "" }