Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[BC Break] Removed the custom encoder factory

See the Upgrade file for needed changes if you don't used different
algorithms per user instance.
If you were using this feature, use FOSAdvancedEncoderBundle instead.

Closes #395
Closes #388
Closes #319
  • Loading branch information...
commit 7f00820488b0853ad3794f1c8735e40363daf899 1 parent 2c1cf4d
@stof stof authored
View
4 Changelog.md
@@ -1,6 +1,10 @@
Changelog
=========
+### 1.2.0
+
+* Removed the user-level algorithm. Use FOSAdvancedEncoderBundle instead if you need such feature.
+
### 1.1.0 (2011-12-15)
* Added "custom" as valid driver
View
41 DependencyInjection/Compiler/SecurityEncoderFactoryPass.php
@@ -1,41 +0,0 @@
-<?php
-
-/*
- * This file is part of the FOSUserBundle package.
- *
- * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace FOS\UserBundle\DependencyInjection\Compiler;
-
-use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Alias;
-
-/**
- * Overwrites the existing encoder factory and injects the old one in the FOSUserBundle implementation
- *
- * @author Christophe Coevoet <stof@notk.org>
- */
-class SecurityEncoderFactoryPass implements CompilerPassInterface
-{
- public function process(ContainerBuilder $container)
- {
- if ($container->hasAlias('security.encoder_factory')) {
- // security.encoder_factory is an alias.
- // Register a private alias for this service to inject it as the parent
- $container->setAlias('fos_user.encoder_factory.parent', new Alias((string) $container->getAlias('security.encoder_factory'), false));
- } else {
- // security.encoder_factory is a definition.
- // Register it again as a private service to inject it as the parent
- $definition = $container->getDefinition('security.encoder_factory');
- $definition->setPublic(false);
- $container->setDefinition('fos_user.encoder_factory.parent', $definition);
- }
-
- $container->setAlias('security.encoder_factory', 'fos_user.encoder_factory');
- }
-}
View
16 DependencyInjection/Configuration.php
@@ -81,7 +81,6 @@ public function getConfigTreeBuilder()
$this->addRegistrationSection($rootNode);
$this->addResettingSection($rootNode);
$this->addServiceSection($rootNode);
- $this->addEncoderSection($rootNode);
$this->addTemplateSection($rootNode);
$this->addGroupSection($rootNode);
@@ -234,21 +233,6 @@ private function addServiceSection(ArrayNodeDefinition $node)
->end();
}
- private function addEncoderSection(ArrayNodeDefinition $node)
- {
- $node
- ->children()
- ->arrayNode('encoder')
- ->addDefaultsIfNotSet()
- ->children()
- ->scalarNode('algorithm')->defaultValue('sha512')->end()
- ->booleanNode('encode_as_base64')->defaultFalse()->end()
- ->scalarNode('iterations')->defaultValue(1)->end()
- ->end()
- ->end()
- ->end();
- }
-
private function addTemplateSection(ArrayNodeDefinition $node)
{
$node
View
1  DependencyInjection/FOSUserExtension.php
@@ -74,7 +74,6 @@ public function load(array $configs, ContainerBuilder $container)
'user_class' => 'fos_user.model.user.class',
'propel_user_class' => 'fos_user.model.user.propel_class',
),
- 'encoder' => 'fos_user.encoder.%s',
'template' => 'fos_user.template.%s',
));
View
10 FOSUserBundle.php
@@ -13,7 +13,6 @@
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
-use FOS\UserBundle\DependencyInjection\Compiler\SecurityEncoderFactoryPass;
/**
* @author Matthieu Bontemps <matthieu@knplabs.com>
@@ -21,13 +20,4 @@
*/
class FOSUserBundle extends Bundle
{
- /**
- * {@inheritdoc}
- */
- public function build(ContainerBuilder $container)
- {
- parent::build($container);
-
- $container->addCompilerPass(new SecurityEncoderFactoryPass());
- }
}
View
8 Resources/config/security.xml
@@ -5,18 +5,10 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
- <parameter key="fos_user.encoder_factory.class">FOS\UserBundle\Security\Encoder\EncoderFactory</parameter>
<parameter key="fos_user.security.interactive_login_listener.class">FOS\UserBundle\Security\InteractiveLoginListener</parameter>
</parameters>
<services>
- <service id="fos_user.encoder_factory" class="%fos_user.encoder_factory.class%" public="false">
- <argument>%security.encoder.digest.class%</argument>
- <argument>%fos_user.encoder.encode_as_base64%</argument>
- <argument>%fos_user.encoder.iterations%</argument>
- <argument type="service" id="fos_user.encoder_factory.parent" />
- </service>
-
<service id="fos_user.security.interactive_login_listener" class="%fos_user.security.interactive_login_listener.class%">
<argument type="service" id="fos_user.user_manager" />
<tag name="kernel.event_listener" event="security.interactive_login" method="onSecurityInteractiveLogin" />
View
4 Resources/doc/configuration_reference.md
@@ -57,10 +57,6 @@ fos_user:
email_canonicalizer: fos_user.util.canonicalizer.default
username_canonicalizer: fos_user.util.canonicalizer.default
user_manager: fos_user.user_manager.default
- encoder:
- algorithm: sha512
- encode_as_base64: false
- iterations: 1
template:
engine: twig
theme: FOSUserBundle::form.html.twig
View
3  Resources/doc/index.md
@@ -273,6 +273,9 @@ security:
fos_userbundle:
id: fos_user.user_manager
+ encoders:
+ "FOS\UserBundle\Model\UserInterface": sha512
+
firewalls:
main:
pattern: ^/
View
82 Security/Encoder/EncoderFactory.php
@@ -1,82 +0,0 @@
-<?php
-
-/*
- * This file is part of the FOSUserBundle package.
- *
- * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace FOS\UserBundle\Security\Encoder;
-
-use FOS\UserBundle\Model\UserInterface;
-use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
-use Symfony\Component\Security\Core\User\UserInterface as SecurityUserInterface;
-
-/**
- * This factory assumes MessageDigestPasswordEncoder's constructor.
- *
- * @author Johannes M. Schmitt <schmittjoh@gmail.com>
- * @author Jeremy Mikola <jmikola@gmail.com>
- */
-class EncoderFactory implements EncoderFactoryInterface
-{
- protected $encoders;
- protected $encoderClass;
- protected $encodeHashAsBase64;
- protected $iterations;
- protected $genericFactory;
-
- /**
- * Constructor.
- *
- * @param string $encoderClass Encoder class
- * @param Boolean $encodeHashAsBase64
- * @param integer $iterations
- * @param EncoderFactoryInterface $genericFactory
- */
- public function __construct($encoderClass, $encodeHashAsBase64, $iterations, EncoderFactoryInterface $genericFactory)
- {
- $this->encoders = array();
- $this->encoderClass = $encoderClass;
- $this->encodeHashAsBase64 = $encodeHashAsBase64;
- $this->iterations = $iterations;
- $this->genericFactory = $genericFactory;
- }
-
- /**
- * @see Symfony\Component\Security\Core\Encoder\EncoderFactory::getEncoder()
- */
- public function getEncoder(SecurityUserInterface $user)
- {
- if (!$user instanceof UserInterface) {
- return $this->genericFactory->getEncoder($user);
- }
-
- if (isset($this->encoders[$algorithm = $user->getAlgorithm()])) {
- return $this->encoders[$algorithm];
- }
-
- return $this->encoders[$algorithm] = $this->createEncoder($algorithm);
- }
-
- /**
- * Creates an encoder for the given algorithm.
- *
- * @param string $algorithm
- *
- * @return PasswordEncoderInterface
- */
- protected function createEncoder($algorithm)
- {
- $class = $this->encoderClass;
-
- return new $class(
- $algorithm,
- $this->encodeHashAsBase64,
- $this->iterations
- );
- }
-}
View
58 Tests/DependencyInjection/Compiler/SecurityEncoderFactoryPassTest.php
@@ -1,58 +0,0 @@
-<?php
-
-/*
- * This file is part of the FOSUserBundle package.
- *
- * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace FOS\UserBundle\Tests\DependencyInjection\Compiler;
-
-use FOS\UserBundle\DependencyInjection\Compiler\SecurityEncoderFactoryPass;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Definition;
-
-class SecurityEncoderFactoryPassTest extends \PHPUnit_Framework_TestCase
-{
- private $container;
- private $pass;
-
- public function setUp()
- {
- $this->container = new ContainerBuilder();
- $this->pass = new SecurityEncoderFactoryPass();
- }
-
- public function testShouldComposeAlias()
- {
- $this->container->setDefinition('security.encoder_factory.real', new Definition());
- $this->container->setAlias('security.encoder_factory', 'security.encoder_factory.real');
-
- $this->pass->process($this->container);
-
- $this->assertServiceHasAlias('security.encoder_factory.real', 'fos_user.encoder_factory.parent');
- $this->assertFalse($this->container->getAlias('fos_user.encoder_factory.parent')->isPublic());
- $this->assertServiceHasAlias('fos_user.encoder_factory', 'security.encoder_factory');
- }
-
- public function testShouldComposeDefinition()
- {
- $this->container->setDefinition('security.encoder_factory', $originalDefinition = new Definition());
-
- $this->pass->process($this->container);
-
- $newDefinition = $this->container->getDefinition('fos_user.encoder_factory.parent');
- $this->assertFalse($newDefinition->isPublic());
- $this->assertSame($originalDefinition, $newDefinition);
-
- $this->assertServiceHasAlias('fos_user.encoder_factory', 'security.encoder_factory');
- }
-
- private function assertServiceHasAlias($serviceId, $aliasId)
- {
- $this->assertEquals($serviceId, (string) $this->container->getAlias($aliasId), sprintf('Service "%s" has alias "%s"', $serviceId, $aliasId));
- }
-}
View
22 Tests/DependencyInjection/FOSUserExtensionTest.php
@@ -274,24 +274,6 @@ public function testUserLoadTemplateConfig()
$this->assertParameter('AcmeMyBundle:Form:theme.html.twig', 'fos_user.template.theme');
}
- public function testUserLoadEncoderConfigWithDefaults()
- {
- $this->createEmptyConfiguration();
-
- $this->assertParameter('sha512', 'fos_user.encoder.algorithm');
- $this->assertParameter(false, 'fos_user.encoder.encode_as_base64');
- $this->assertParameter(1, 'fos_user.encoder.iterations');
- }
-
- public function testUserLoadEncoderConfig()
- {
- $this->createFullConfiguration();
-
- $this->assertParameter('sha1', 'fos_user.encoder.algorithm');
- $this->assertParameter(true, 'fos_user.encoder.encode_as_base64');
- $this->assertParameter(3, 'fos_user.encoder.iterations');
- }
-
public function testUserLoadUtilServiceWithDefaults()
{
$this->createEmptyConfiguration();
@@ -403,10 +385,6 @@ protected function getFullConfig()
email_canonicalizer: acme_my.email_canonicalizer
username_canonicalizer: acme_my.username_canonicalizer
user_manager: acme_my.user_manager
-encoder:
- algorithm: sha1
- encode_as_base64: true
- iterations: 3
template:
engine: php
theme: AcmeMyBundle:Form:theme.html.twig
View
60 Tests/Security/Encoder/EncoderFactoryTest.php
@@ -1,60 +0,0 @@
-<?php
-
-/*
- * This file is part of the FOSUserBundle package.
- *
- * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace FOS\UserBundle\Tests\Security\Encoder;
-
-use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
-use FOS\UserBundle\Security\Encoder\EncoderFactory;
-
-class EncoderFactoryTest extends \PHPUnit_Framework_TestCase
-{
- /**
- * @covers FOS\UserBundle\Security\Encoder\EncoderFactory::getEncoder
- * @covers FOS\UserBundle\Security\Encoder\EncoderFactory::createEncoder
- */
- public function testGetEncoderWithUserAccount()
- {
- $factory = new EncoderFactory(
- 'Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder',
- false,
- 1,
- $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface')
- );
-
- $userAccount = $this->getMock('FOS\UserBundle\Model\UserInterface');
-
- $userAccount->expects($this->once())
- ->method('getAlgorithm')
- ->will($this->returnValue('sha512'));
-
- $encoder = $factory->getEncoder($userAccount);
-
- $expectedEncoder = new MessageDigestPasswordEncoder('sha512', false, 1);
-
- $this->assertEquals($expectedEncoder->encodePassword('foo', 'bar'), $encoder->encodePassword('foo', 'bar'));
- }
-
- public function testGetEncoderWithGenericAccount()
- {
- $genericFactory = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface');
- $encoder = $this->getMock('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface');
-
- $genericFactory
- ->expects($this->once())
- ->method('getEncoder')
- ->will($this->returnValue($encoder))
- ;
-
- $factory = new EncoderFactory(null , false, 1, $genericFactory);
-
- $this->assertSame($encoder, $factory->getEncoder($this->getMock('Symfony\Component\Security\Core\User\UserInterface')));
- }
-}
View
20 Upgrade_to_1_2.md
@@ -0,0 +1,20 @@
+Upgrading from 1.1 tp 1.2
+=========================
+
+This file describes the needed changes when upgrading from 1.1 to 1.2
+
+### Removed the user-level algorithm.
+
+The encoder now need to be configured in the SecurityBundle configuration
+as described in the official documentation. If you were using the default
+value of the bundle, the config should look like this to reuse the same settings:
+
+```yaml
+#app/config/security.yml
+security:
+ encoders:
+ "FOS\UserBundle\Model\UserInterface":
+ algorithm: sha512
+ encode_as_base64: false
+ iterations: 1
+```
Please sign in to comment.
Something went wrong with that request. Please try again.