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

Shared firewall context listener isn't defined #1568

Closed boite closed 6 years ago

boite commented 6 years ago

I see the following exception having defined two firewalls (using the same, custom authentication provider) which have a shared context key in their config:-

'security.firewalls' => [
    'search' => [
        'context' => 'search_and_sharing',
        'stateless' => false,
        ...
    'sharing' => [
        'context' => 'search_and_sharing',
        'stateless' => false,
        ...
    ]
]

Exception:-

UnknownIdentifierException

Identifier "security.context_listener.search_and_sharing" is not defined.
in Container.php (line 101)
at Container->offsetGet('security.context_listener.search_and_sharing')in SecurityServiceProvider.php (line 322)
at SecurityServiceProvider->Silex\Provider\{closure}('security.context_listener.search_and_sharing')
at array_map(object(Closure), array('security.channel_listener', 'security.context_listener.search_and_sharing', 'security.authentication_listener.search.jwt_issuer', 'security.access_listener'))in SecurityServiceProvider.php (line 334)
at SecurityServiceProvider->Silex\Provider\{closure}(object(Application))in Container.php (line 118)
at Container->offsetGet('security.firewall_map')in SecurityServiceProvider.php (line 154)
at SecurityServiceProvider->Silex\Provider\{closure}(object(Application))in Container.php (line 118)
at Container->offsetGet('security.firewall')in SecurityServiceProvider.php (line 672)
at SecurityServiceProvider->subscribe(object(Application), object(TraceableEventDispatcher))in Application.php (line 111)
at Application->boot()in Application.php (line 491)

This is using Silex v2.2.0. What am I doing wrong?

boite commented 6 years ago

It seems to work as expected if the context is named, in both firewalls, the same name as the firewall defined first:-

'security.firewalls' => [
    'search' => [
        'context' => 'search',
        'stateless' => false,
        ...
    'sharing' => [
        'context' => 'search',
        'stateless' => false,
        ...
    ]
]
hkdobrev commented 6 years ago

@boite Please check out #1610. Thanks!