8000 [FrameworkBundle] Use security.token_storage service in Controller::getUser() by xelaris · Pull Request #13214 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Use security.token_storage service in Controller::getUser() #13214

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
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load file 10000 s.
Loading
Diff view
Diff view
Next Next commit
[FrameworkBundle] Use security.token_storage service in Controller::g…
…etUser()
  • Loading branch information
xelaris committed Jan 3, 2015
commit 8c5bd20cb198cd1dbbe7d0d8fd2536f64977273f
7 changes: 4 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public function getDoctrine()
}

/**
* Get a user from the Security Context.
* Get a user from the Security Token Storage.
*
* @return mixed
*
Expand All @@ -303,15 +303,16 @@ public function getDoctrine()
*/
public function getUser()
{
if (!$this->container->has('security.context')) {
if (!$this->container->has('security.token_storage')) {
throw new \LogicException('The SecurityBundle is not registered in your application.');
}

if (null === $token = $this->container->get('security.context')->getToken()) {
if (null === $token = $this->container->get('security.token_storage')->getToken()) {
return;
}

if (!is_object($user = $token->getUser())) {
// e.g. anonymous authentication
return;
}

Expand Down
0