src/ApiV3Bundle/Security/Firewall/BaseAuthenticationListener.php line 36

Open in your IDE?
  1. <?php
  2. namespace ApiV3Bundle\Security\Firewall;
  3. use ApiV3Bundle\Security\Authentication\Token\ApiToken;
  4. use Biz\Role\Util\PermissionBuilder;
  5. use Biz\User\CurrentUser;
  6. use Biz\User\Service\UserService;
  7. use Symfony\Component\DependencyInjection\ContainerInterface;
  8. use Symfony\Component\HttpFoundation\Request;
  9. abstract class BaseAuthenticationListener implements ListenerInterface
  10. {
  11.     protected $container;
  12.     public function __construct(ContainerInterface $container)
  13.     {
  14.         $this->container $container;
  15.     }
  16.     protected function createTokenFromRequest(Request $request$userId)
  17.     {
  18.         $user $this->getUserService()->getUserWithOrgScopes($userId);
  19.         $user['currentIp'] = $request->getClientIp();
  20.         $currentUser = new CurrentUser();
  21.         $currentUser->fromArray($user);
  22.         $currentUser->setPermissions(PermissionBuilder::instance()->findPermissionsByRoles($currentUser->getRoles()));
  23.         $this->container->get('biz')['user'] = $currentUser;
  24.         
  25.         return new ApiToken($currentUser$currentUser->getRoles());
  26.     }
  27.     protected function getTokenStorage()
  28.     {
  29.         return $this->container->get('security.token_storage');
  30.     }
  31.     /**
  32.      * @return UserService
  33.      */
  34.     protected function getUserService()
  35.     {
  36.         return $this->container->get('biz')->service('User:UserService');
  37.     }
  38. }