public function handle(GetResponseEvent $event)
    {
        if (!$this->registered && null !== $this->dispatcher && $event->isMasterRequest()) {
            $this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
            $this->registered = true;
        }

        $request = $event->getRequest();
        $session = $request->getSession();
        /*$sessionId = $session->getId();
        if(empty($sessionId))
        {
            $session = null;
        }*/

        if (null === $session || null === $token = $session->get('_security_'.$this->contextKey)) {
            $this->context->setToken(null);

            return;
        }

        $token = unserialize($token);

        if (null !== $this->logger) {
            $this->logger->debug('Read SecurityContext from the session');
        }

        if ($token instanceof TokenInterface) {
            $token = $this->refreshUser($token);
        } elseif (null !== $token) {
            if (null !== $this->logger) {
                $this->logger->warning(sprintf('Session includes a "%s" where a security token is expected', is_object($token) ? get_class($token) : gettype($token)));
            }

            $token = null;
        }

        $this->context->setToken($token);
    }
public function handle(GetResponseEvent $event)
    {
        if (!$this->registered && null !== $this->dispatcher && $event->isMasterRequest()) {
            $this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
            $this->registered = true;
        }

        $request = $event->getRequest();
        $session = $request->getSession();
        /*$sessionId = $session->getId();
        if(empty($sessionId))
        {
            $session = null;
        }*/

        if (null === $session || null === $token = $session->get('_security_'.$this->contextKey)) {
            $this->context->setToken(null);

            return;
        }

        $token = unserialize($token);

        if (null !== $this->logger) {
            $this->logger->debug('Read SecurityContext from the session');
        }

        if ($token instanceof TokenInterface) {
            $token = $this->refreshUser($token);
        } elseif (null !== $token) {
            if (null !== $this->logger) {
                $this->logger->warning(sprintf('Session includes a "%s" where a security token is expected', is_object($token) ? get_class($token) : gettype($token)));
            }

            $token = null;
        }

        $this->context->setToken($token);
    }
public function handle ( GetResponseEvent $ event ) { if ( ! $ this -> registered && null !== $ this -> dispatcher && $ event -> isMasterRequest ( ) ) { $ this -> dispatcher -> addListener ( KernelEvents :: RESPONSE , array ( $ this , 'onKernelResponse' ) ) ; $ this -> registered = true ; } $ request = $ event -> getRequest ( ) ; $ session = $ request -> getSession ( ) ; /*$sessionId = $session->getId();
        if(empty($sessionId))
        {
            $session = null;
        }*/ if ( null === $ session || null === $ token = $ session -> get ( '_security_' . $ this -> contextKey ) ) { $ this -> context -> setToken ( null ) ; return ; } $ token = unserialize ( $ token ) ; if ( null !== $ this -> logger ) { $ this -> logger -> debug ( 'Read SecurityContext from the session' ) ; } if ( $ token instanceof TokenInterface ) { $ token = $ this -> refreshUser ( $ token ) ; } elseif ( null !== $ token ) { if ( null !== $ this -> logger ) { $ this -> logger -> warning ( sprintf ( 'Session includes a "%s" where a security token is expected' , is_object ( $ token ) ? get_class ( $ token ) : gettype ( $ token ) ) ) ; } $ token = null ; } $ this -> context -> setToken ( $ token ) ; }
Reads the SecurityContext from the session.

@param GetResponseEvent $event A GetResponseEvent instance
Reads the SecurityContext from the session .