]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Fix security.context deprecation
authorJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 6 Nov 2015 23:17:37 +0000 (00:17 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Fri, 6 Nov 2015 23:17:37 +0000 (00:17 +0100)
src/Wallabag/ApiBundle/Controller/WallabagRestController.php
src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php
src/Wallabag/CoreBundle/Helper/DetectActiveTheme.php
src/Wallabag/CoreBundle/Resources/config/services.yml

index 1fee56ad14693c812e8b0896a0693faf8dd41d14..74bfe4dcdb286a3337e00d889a80ffb3d1918b05 100644 (file)
@@ -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());
         }
index 119889b3869b468a6ff8bc0f95521ee195845f2f..09cde0f602766995b7c48b02a0e85c121390fa40 100644 (file)
@@ -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;
index 054a375227c0345c7712c660c2682e81161d050a..489f39d151e17213e8dcf6af6ee15e553f163637 100644 (file)
@@ -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;
index 3c479ff666607b0cce074c14c9c44f81c0b4e16a..debbf39e0eb4ab9672e5ccad38567afd18062018 100644 (file)
@@ -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