From 18f8f32f70a3f76b307f4255eee0f51187b07283 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 7 Nov 2015 00:17:37 +0100 Subject: [PATCH] Fix security.context deprecation --- .../ApiBundle/Controller/WallabagRestController.php | 4 ++-- .../ApiBundle/Tests/AbstractControllerTest.php | 6 +++--- src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php | 12 ++++++------ .../CoreBundle/Resources/config/services.yml | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 1fee56ad..74bfe4dc 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -40,7 +40,7 @@ class WallabagRestController extends FOSRestController private function validateAuthentication() { - if (false === $this->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')) { + if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { throw new AccessDeniedException(); } } @@ -347,7 +347,7 @@ class WallabagRestController extends FOSRestController */ private function validateUserAccess($requestUserId) { - $user = $this->get('security.context')->getToken()->getUser(); + $user = $this->get('security.token_storage')->getToken()->getUser(); if ($requestUserId != $user->getId()) { throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$requestUserId.', logged user id: '.$user->getId()); } diff --git a/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php b/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php index 119889b3..09cde0f6 100644 --- a/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php @@ -25,7 +25,6 @@ abstract class AbstractControllerTest extends WebTestCase $client = static::createClient(); $container = $client->getContainer(); - $session = $container->get('session'); /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ $userManager = $container->get('fos_user.user_manager'); /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ @@ -36,9 +35,10 @@ abstract class AbstractControllerTest extends WebTestCase $loginManager->loginUser($firewallName, $user); // save the login token into the session and put it in a cookie - $container->get('session')->set('_security_'.$firewallName, - serialize($container->get('security.context')->getToken())); + $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); $container->get('session')->save(); + + $session = $container->get('session'); $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId())); return $client; diff --git a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php index 054a3752..489f39d1 100644 --- a/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php +++ b/src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php @@ -3,7 +3,7 @@ namespace Wallabag\CoreBundle\Helper; use Liip\ThemeBundle\Helper\DeviceDetectionInterface; -use Symfony\Component\Security\Core\SecurityContextInterface; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Wallabag\UserBundle\Entity\User; /** @@ -14,16 +14,16 @@ use Wallabag\UserBundle\Entity\User; */ class DetectActiveTheme implements DeviceDetectionInterface { - protected $securityContext; + protected $tokenStorage; protected $defaultTheme; /** - * @param SecurityContextInterface $securityContext Needed to retrieve the current user + * @param TokenStorageInterface $tokenStorage Needed to retrieve the current user * @param string $defaultTheme Default theme when user isn't logged in */ - public function __construct(SecurityContextInterface $securityContext, $defaultTheme) + public function __construct(TokenStorageInterface $tokenStorage, $defaultTheme) { - $this->securityContext = $securityContext; + $this->tokenStorage = $tokenStorage; $this->defaultTheme = $defaultTheme; } @@ -42,7 +42,7 @@ class DetectActiveTheme implements DeviceDetectionInterface */ public function getType() { - $token = $this->securityContext->getToken(); + $token = $this->tokenStorage->getToken(); if (is_null($token)) { return $this->defaultTheme; diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 3c479ff6..debbf39e 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -2,7 +2,7 @@ services: wallabag_core.helper.detect_active_theme: class: Wallabag\CoreBundle\Helper\DetectActiveTheme arguments: - - @security.context + - @security.token_storage - %theme% # default theme from parameters.yml # custom form type -- 2.41.0