silexphp / Silex

[DEPRECATED -- Use Symfony instead] The PHP micro-framework based on the Symfony Components
https://silex.symfony.com
MIT License
3.58k stars 718 forks source link

Silex 2 & SecurityServiceProvider #1146

Closed J7mbo closed 9 years ago

J7mbo commented 9 years ago

Preface: This is about 2 which is in Dev and of course not stable yet. I just enjoy using the latest :-)

I register the SecurityServiceProvider like I did in Silex v1.2:

    $firewalls   = $config['firewalls'];
    $hierarchy   = $config['hierarchy'];
    $accessRules = $config['access_rules'];

    $firewalls['default']['users'] = function($app) {
        /** @var EntityManager $orm */
        $orm = $app['orm.em'];
        return $orm->getRepository(self::USER_ENTITY);
    };

    $app->register(new SecurityServiceProvider, [
        'security.firewalls'           => $firewalls,
        'security.role_hierarchy' => $hierarchy,
        'security.access_rules'   => $accessRules
    ]);

Please assume $config is correct - it worked fine in 1.2 :) I know 2.0 is in dev, but when running the application I get the following error:

Catchable fatal error: Argument 1 passed to Symfony\Component\Security\Http\Firewall\ContextListener::__construct() must be an instance of Symfony\Component\Security\Core\SecurityContextInterface, instance of Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage given, called in /Users/james/Dev/app/vendor/silex/silex/src/Silex/Provider/SecurityServiceProvider.php on line 359 and defined in /Users/james/Dev/app/vendor/symfony/security/Symfony/Component/Security/Http/Firewall/ContextListener.php on line 42

I know that's not particularly helpful but I'm not sure if there's anything else I can provide. Is this simply because SecurityServiceProvider isn't doing what it's supposed to be doing just yet and I should be uncharacteristically patient or is there something different I need to be doing?

I traced the code through to this in SecurityServiceProvider:

$app['security.exception_listener._proto'] = $app->protect(function ($entryPoint, $name) use ($app) {
        return $app->share(function () use ($app, $entryPoint, $name) {
            return new ExceptionListener(
                $app['security'], // I BELIEVE THIS IS WHERE THE ERROR LIES?
                $app['security.trust_resolver'],
                $app['security.http_utils'],
                $name,
                $app[$entryPoint],
                null, // errorPage
                null, // AccessDeniedHandlerInterface
                $app['logger']
            );
        });
    });

Looking at 1.3, there seem to be some changes like: $app['security.token_storage'].

TLDR, any idea on the ETA to get what is in 1.3 up-to-date with Silex 2.0 and Symfony Components (2.6) and make SecurityServiceProvider work as expected?

J7mbo commented 9 years ago

Thanks a lot @fabpot :+1: