【问题标题】:Security annotations and The Symfony\Component\Security\Core\SecurityContext class is deprecated安全注释和 Symfony\Component\Security\Core\SecurityContext 类已弃用
【发布时间】:2015-08-09 08:55:03
【问题描述】:

根据 Symfony 从 3.0 版开始,The Symfony\Component\Security\Core\SecurityContext 将被删除。这已经在这里讨论过:Symfony 2 SecurityContext class deprecated

我的 symfony 报如下错误:

错误:Symfony\Component\Security\Core\SecurityContext 类是 自 2.6 版起已弃用,并将在 3.0 版中删除。采用 Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage 或 Symfony\Component\Security\Core\Authorization\AuthorizationChecker 而是。

我正在使用annotations 来管理我在 symfony 中的安全角色,例如

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

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

我应该如何切换到非折旧类?

使用错误中列出的任何一个类都会导致:

[语义错误] 方法中的注解“@Security” AppBundle\Controller\AccountController::listAction() 从来没有 进口的。您是否可能忘记为此添加“使用”声明 注解?在 /var/www/gra.investmentopportunities.pl/src/AppBundle/Controller/ (这是从 “/var/www/gra.investmentopportunities.pl/app/config/routing.yml”)。

【问题讨论】:

标签: symfony


【解决方案1】:

the code 看来,@security.context 似乎在 v3.0.4 之前已用完。从那时起,@security.token_storage@security.authorization_checker 也被注入,如果它们存在,它们将被使用而不是 @security.context

从这些事实来看,我只能假设使用的是 SensioFrameworkExtraBundle 之前的 v3.0.5 版本。

如果您的composer.json 中有sensio/framework-extra-bundle: ~3.0,那么您只需运行composer.phar update sensio/framework-extra-bundle,它应该会更新它并消除弃用警告。

【讨论】:

  • 感谢您的建议。我已经检查了作曲家,我目前正在使用 sensio/framework-extra-bundle 的 v. 3.0.9。问题是我应该在脚本头“使用”什么命令才能使注释起作用? (见上面更新的代码)。
猜你喜欢
  • 2015-06-18
  • 2018-02-22
  • 2015-03-13
  • 2023-03-28
  • 2021-02-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-21
  • 2012-01-04
相关资源
最近更新 更多