Bug #46210
securityContext->getParty() in the initializeObject() method of a session-Scope object throws exception on second request
Status: | Needs Feedback | Start date: | 2013-03-12 | |
---|---|---|---|---|
Priority: | Should have | Due date: | ||
Assigned To: | - | % Done: | 0% |
|
Category: | Session | |||
Target version: | - | |||
PHP Version: | Complexity: | |||
Has patch: | No | Affected Flow version: | Git master |
Description
When i put the following code in a session-scope object and am logged in it works on the first request. But after reloading the same page this code throws an exception.
/** * @Flow\Inject * @var \TYPO3\Flow\Security\Context */ protected $securityContext; public function initializeObject() { $loginUser = $this->securityContext->getParty(); }
The exceoption thrown:
#1358513802: The security Context cannot be initialized yet. Please check if it can be initialized with $securityContext->canBeInitialized() before trying to do so.
Related issues
History
#1 Updated by Sebastian Kurfuerst over 2 years ago
- Status changed from New to Needs Feedback
Hey Benno,
in order to properly debug your problem, I need some more input, more namely about what kind of session-scoped object it is, and
where it is needed from:
Is it a dependency of a controller, of a model class, of a Route Part Handler, ...?
Greets,
Sebastian
#2 Updated by Sebastian Kurfuerst over 2 years ago
The Security Context is only initialized inside the MVC Dispatcher, as it needs the Web Request.
Thus, you should try to initialize the $loginUser lazily, when you try to access it for the first time. I think this would already solve the issue.
Greets, Sebastian
#3 Updated by Adrian Föder over 2 years ago
Maybe I even ran into a similar issue, where in my case a Widget gets woken up, leading into trouble with the DependencyProxy.
In \TYPO3\Flow\Security\Aspect\PersistenceQueryRewritingAspect::Flow_Proxy_injectProperties, the securityContext is created the following way:
1 $this->securityContext = \TYPO3\Flow\Core\Bootstrap::$staticObjectManager->getLazyDependencyByHash('48836470c14129ade5f39e28c4816673', $securityContext_reference);
2 if ($this->securityContext === NULL) {
3 $this->securityContext = \TYPO3\Flow\Core\Bootstrap::$staticObjectManager->createLazyDependency('48836470c14129ade5f39e28c4816673', $securityContext_reference, 'TYPO3\Flow\Security\Context', function() { return \TYPO3\Flow\Core\Bootstrap::$staticObjectManager->get('TYPO3\Flow\Security\Context'); });
4 }
but it looks like the closure's return again returns a Dependency Proxy.