-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Cannot autowire custom LoginFormAuthenticator in a controller action #59091
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
Comments
Same for me. However, the error disappears if I remove the |
I have the same issue when upgrading to 7.2: I changed my controller to this: #[Route("/something", methods:["GET", "POST"])]
public function doSomethingAction(
#[Autowire(service: 'App\Security\AppCustomAuthentiatorAuthenticator')]
AuthenticatorInterface $appCustomAuthentiatorAuthenticator)
{
// .... And that seems to work? |
Had the same problem. To me, it looks like all authenticators are wrapped/decorated now (06f7876#diff-5eece14c3eaf711243f93091c28eb0a6e3dc4e0af44830f87ee0cb436dd39460R644). In my code I autowire my I changed it to Before : class ProgrammaticUserAuthenticator
{
public function __construct(private UserAuthenticatorInterface $authenticator, private CustomLoginFormAuthenticator $customFormAuthenticator, private TokenStorageInterface $tokenStorage) After (services.yaml) : class ProgrammaticUserAuthenticator
{
public function __construct(private UserAuthenticatorInterface $authenticator, private AuthenticatorInterface $customFormAuthenticator, private TokenStorageInterface $tokenStorage) services:
App\User\Security\ProgrammaticUserAuthenticator:
class: App\User\Security\ProgrammaticUserAuthenticator
arguments:
- '@security.authenticator.manager.main'
- '@App\User\Security\Authenticator\CustomLoginFormAuthenticator'
- '@security.token_storage' After (Autowire attribute) : class ProgrammaticUserAuthenticator
{
public function __construct(private UserAuthenticatorInterface $authenticator, #[Autowire(service: 'App\User\Security\Authenticator\CustomLoginFormAuthenticator')] private AuthenticatorInterface $customFormAuthenticator, private TokenStorageInterface $tokenStorage) Seems to work :) |
Although we should certainly try to fix this regression, using the interface as type and wiring the concrete authenticator’s service id explicitly e.g. using |
…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
Symfony version(s) affected
7.2
Description
This may be related to #59071.
I have a custom authenticator extending the builtin
AbstractLoginFormAuthenticator
. I autowire it into the register action of mySecurityController
, so I can authenticate newly registered users, so they can continue the process they are currently in without the need to verify their data at this point:After upgrading to
7.2
, this throws an exception:A quick debug of the service shows, that the
dev
environment seems to wrap it automatically into theTracableAuthenticator
class:Switching to the
prod
environment seems to "fix" the problem.How to reproduce
Create a new class
App\Security\LoginFormAuthenticator
extendingSymfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator
. Define the abstract methods and configure it in your configurations:Now, create a new class
App\Controller\SecurityController
with an methodregister
and try to autowire the newly created authenticator via a method parameter:Accessing the route (
https://127.0.0.1:8000/register
) throws the described exception.Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: