8000 [Security] Cannot have a custom authenticator which implements `EventSubscriberInterface` · Issue #59071 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security] Cannot have a custom authenticator which implements EventSubscriberInterface #59071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
misaert opened this issue Dec 2, 2024 · 5 comments

Comments

@misaert
Copy link
Contributor
misaert commented Dec 2, 2024

Symfony version(s) affected

7.2.0

Description

Hi,

When I try to update from Symfony 7.1 to 7.2. I have an error on cache clear:

$ bin/console cache:clear

In RegisterListenersPass.php line 129:
                                                                                                                                             
  Service "debug.App\Security\MyCustomAuthenticator" must implement interface "Symfony\Component\EventDispatcher\EventSubscriberInterface".  

It seems to be related to:

When I add this code on vendor/symfony/security-bundle/DependencyInjection/SecurityExtension.php line 646:

        if ($container->hasDefinition('debug.security.firewall')) {
            foreach ($authenticationProviders as $authenticatorId) {
                if ($authenticatorId === MyCustomAuthenticator::class) {
                    continue;
                }

                $container->register('debug.'.$authenticatorId, TraceableAuthenticator::class)
                    ->setDecoratedService($authenticatorId)
                    ->setArguments([new Reference('debug.'.$authenticatorId.'.inner')])
                ;
            }
        }

It works.

Is it an issue? Why I can't implement EventSubscriberInterface anymore?

Thanks,

Mickaël

How to reproduce

I created a repository: https://github.com/misaert/test-custom-authenticator/commits/main/.

The last commit is with Symfony 7.2. Before this, we can launch bin/console cache:clear but with this commit, we have this error:

$ bin/console cache:clear

In RegisterListenersPass.php line 129:
                                                                                                                                             
  Service "debug.App\Security\MyCustomAuthenticator" must implement interface "Symfony\Component\EventDispatcher\EventSubscriberInterface".  
                                                                                                                                             

Possible Solution

No response

Additional Context

No response

@roverwolf
Copy link

I ran into the same issue when trying to upgrade to 7.2.0.

My workaround was to pull the event subscriber portions into their own class.

@misaert
Copy link
Contributor Author
misaert commented Dec 3, 2024

Thanks for your reply.

It is a possibility. But I wonder if it is a bug. @MatTheCat, do you think it is?

Thanks

@MatTheCat
Copy link
Contributor

Looks like a bug yes 😅

I guess this is not the only case of a service decorated by two different Traceable, but no other comes to mind and I don't know how this is handled.

@MatTheCat
Copy link
Contributor

@misaert could you check #59278 fixes your issue? 🙏

@misaert
Copy link
Contributor Author
misaert commented Dec 23, 2024

Hi @MatTheCat,

Yes, it works with this fix 👍

Thank you 🙂

fabpot added a commit that referenced this issue Dec 30, 2024
…their traceable version (MatTheCat)

This PR was squashed before being merged into the 7.2 branch.

Discussion
----------

[SecurityBundle] Do not replace authenticators service by their traceable version

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #59071, fix #59091
| License       | MIT

Commits
-------

d44b7af [SecurityBundle] Do not replace authenticators service by their traceable version
@fabpot fabpot closed this as completed Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0