【问题标题】:SecurityContext is deprected in symfony 2.6SecurityContext 在 symfony 2.6 中被弃用
【发布时间】:2023-03-28 23:43:01
【问题描述】:

SF 2.6 中已弃用服务 SecurityContext 在 Symfony 2.6 中应该使用什么正确的服务而不是 securityContext

【问题讨论】:

    标签: symfony-2.6


    【解决方案1】:

    从 Symfony 2.6 开始,SecurityContext 类被拆分为 AuthorizationChecker 和 TokenStorage 类。

    要检索您可以使用的用户:

    $user = $this->get('security.token_storage')->getToken()->getUser();
    

    要检查授权,您可以使用:

    if (false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) { ... }
    

    More deatils

    【讨论】:

      猜你喜欢
      • 2015-06-18
      • 1970-01-01
      • 1970-01-01
      • 2015-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多