1

According to Symfony begining with version 3.0 The Symfony\Component\Security\Core\SecurityContext will be removed. This was already discussed here: Symfony 2 SecurityContext class deprecated

My symfony reports the following error:

Error: The Symfony\Component\Security\Core\SecurityContext class is deprecated since version 2.6 and will be removed in 3.0. Use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage or Symfony\Component\Security\Core\Authorization\AuthorizationChecker instead.

I am using annotations to manage my security roles in symfony e.g.

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; // Security annotation bundle

    /**
 * @Route("/account/list", name="Account_list")
 * @Security("has_role('ROLE_USER')")
 */

How should I switch into non-depreciated class?

Using either of the classes listed in error results in:

[Semantical Error] The annotation "@Security" in method AppBundle\Controller\AccountController::listAction() was never imported. Did you maybe forget to add a "use" statement for this annotation? in /var/www/gra.investmentopportunities.pl/src/AppBundle/Controller/ (which is being imported from "/var/www/gra.investmentopportunities.pl/app/config/routing.yml").

Community
  • 1
  • 1
Abdel5
  • 1,112
  • 3
  • 16
  • 39
  • 1
    You should still use the `Sensio\Bundle\FrameworkExtraBundle\Configuration\Security` annotation. Are you sure that this deprecation warning is due to the annotation? There should be no warning just from using the `@Security` tag on it's own since this commit - https://github.com/sensiolabs/SensioFrameworkExtraBundle/commit/675a6ea953c46721e57d692d17bb8d4a734b92f8 – qooplmao Aug 09 '15 at 16:09

1 Answers1

2

From looking at the code it looks like the @security.context was used up until v3.0.4. From then on @security.token_storage and @security.authorization_checker were also injected so that, if they were present, they would be used instead of the @security.context.

Taken from those facts I can only assume that are using a version of the SensioFrameworkExtraBundle previous to v3.0.5.

If you have sensio/framework-extra-bundle: ~3.0 in your composer.json then you can just run composer.phar update sensio/framework-extra-bundle and it should bring it up to date and get rid of the deprecation warnings.

qooplmao
  • 17,622
  • 2
  • 44
  • 69
  • Thanks for advice. I have checked the composer and I am currently using v. 3.0.9 of sensio/framework-extra-bundle. The question is what command should I "use" at the script header for annotations to work? (see updated code above). – Abdel5 Aug 09 '15 at 16:00