DDC-3163: security.context getToken() return null #3920

Closed
opened 2026-01-22 14:31:30 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 11, 2014).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user clavat:

On my entity listener i have this part of code on preUpdate()

L48 : $secuContext = $this->container->get('security.context');
L49 : $actualUser = $secuContext->getToken()->getUser();

container are injected, this code worked on v2.4.2, but after update 2.4.3 when i run doctrine:fixtures:load i got this error on the console :
PHP Fatal error: Call to a member function getUser() on a non-object in C:\wamp
\www\project\src\acme\EntityBundle\Service\AcmeListener.php on line
49

Originally created by @doctrinebot on GitHub (Jun 11, 2014). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user clavat: On my entity listener i have this part of code on preUpdate() L48 : $secuContext = $this->container->get('security.context'); L49 : $actualUser = $secuContext->getToken()->getUser(); container are injected, this code worked on v2.4.2, but after update 2.4.3 when i run doctrine:fixtures:load i got this error on the console : PHP Fatal error: Call to a member function getUser() on a non-object in C:\wamp \www\project\src\acme\EntityBundle\Service\AcmeListener.php on line 49
admin added the Bug label 2026-01-22 14:31:30 +01:00
admin closed this issue 2026-01-22 14:31:31 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 11, 2014):

Comment created by stof:

This is not a Doctrine bug at all. It is a bug in your own code, and related to a place using Symfony code, not Doctrine code.

Btw, getToken is documented as returning TokenInterface|null. If you are not behind a firewall, or if you run your logic before the authentication is completed by the security layer, it will be null

@doctrinebot commented on GitHub (Jun 11, 2014): Comment created by stof: This is not a Doctrine bug at all. It is a bug in your own code, and related to a place using Symfony code, not Doctrine code. Btw, `getToken` is documented as returning `TokenInterface|null`. If you are not behind a firewall, or if you run your logic before the authentication is completed by the security layer, it will be `null`
Author
Owner

@doctrinebot commented on GitHub (Jun 11, 2014):

Comment created by clavat:

I can understand this, but can you explain why in older version the same code works perfectly ?

2.4.3 change the position of listener inside firewall ? Or how authentication is completed.

@doctrinebot commented on GitHub (Jun 11, 2014): Comment created by clavat: I can understand this, but can you explain why in older version the same code works perfectly ? 2.4.3 change the position of listener inside firewall ? Or how authentication is completed.
Author
Owner

@doctrinebot commented on GitHub (Jun 12, 2014):

Comment created by stof:

Doctrine does not register anything in the firewall. Knowing why a PreUpdate event is triggered depends of hwat your app is doing, not of what Doctrine is using. This is not something controlled by Doctrine, so we cannot help you

@doctrinebot commented on GitHub (Jun 12, 2014): Comment created by stof: Doctrine does not register anything in the firewall. Knowing why a PreUpdate event is triggered depends of hwat your app is doing, not of what Doctrine is using. This is not something controlled by Doctrine, so we cannot help you
Author
Owner

@doctrinebot commented on GitHub (Jun 12, 2014):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Jun 12, 2014): Issue was closed with resolution "Invalid"
Author
Owner

@doctrinebot commented on GitHub (Jun 12, 2014):

Comment created by @ocramius:

Not in the scope of the project.

@doctrinebot commented on GitHub (Jun 12, 2014): Comment created by @ocramius: Not in the scope of the project.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3920