symfony-2.6

SecurityContext is deprected in symfony 2.6


The service SecurityContext is deprectaed in SF 2.6 What is the right service should be used instead of securityContext in Symfony 2.6


Solution

  • As of Symfony 2.6, the SecurityContext class was split in the AuthorizationChecker and TokenStorage classes.

    To retreive the user you can use:

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

    To check authorization you can use:

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

    More deatils