protected function authenticate(Url $url)
    {
        if (
            !$url->getOption('role') ||
            !$url->getOption('firewall')
        ) {
            return $this;
        }

        $session = $this->session;
        $firewall = $url->getOption('firewall');
        $role = $url->getOption('role');
        $user = $this
            ->environmentBuilder
            ->getAuthenticationUser($url->getOption('role'));

        $token = new UsernamePasswordToken($user, null, $firewall, [$role]);
        $session->set('_security_' . $firewall, serialize($token));
        $session->save();

        $cookie = new Cookie(
            $session->getName(),
            $session->getId()
        );
        $this
            ->client
            ->getCookieJar()
            ->set($cookie);

        return $this;
    }
protected function authenticate(Url $url)
    {
        if (
            !$url->getOption('role') ||
            !$url->getOption('firewall')
        ) {
            return $this;
        }

        $session = $this->session;
        $firewall = $url->getOption('firewall');
        $role = $url->getOption('role');
        $user = $this
            ->environmentBuilder
            ->getAuthenticationUser($url->getOption('role'));

        $token = new UsernamePasswordToken($user, null, $firewall, [$role]);
        $session->set('_security_' . $firewall, serialize($token));
        $session->save();

        $cookie = new Cookie(
            $session->getName(),
            $session->getId()
        );
        $this
            ->client
            ->getCookieJar()
            ->set($cookie);

        return $this;
    }
protected function authenticate ( Url $ url ) { if ( ! $ url -> getOption ( 'role' ) || ! $ url -> getOption ( 'firewall' ) ) { return $ this ; } $ session = $ this -> session ; $ firewall = $ url -> getOption ( 'firewall' ) ; $ role = $ url -> getOption ( 'role' ) ; $ user = $ this -> environmentBuilder -> getAuthenticationUser ( $ url -> getOption ( 'role' ) ) ; $ token = new UsernamePasswordToken ( $ user , null , $ firewall , [ $ role ] ) ; $ session -> set ( '_security_' . $ firewall , serialize ( $ token ) ) ; $ session -> save ( ) ; $ cookie = new Cookie ( $ session -> getName ( ) , $ session -> getId ( ) ) ; $ this -> client -> getCookieJar ( ) -> set ( $ cookie ) ; return $ this ; }
Authenticates a user if is needed.

A user is needed to be authenticated if in the url a role and a firewall
is specified. Otherwise, the system will understand that is a public url

@param Url $url Url

@return $this Self object
Authenticates a user if is needed .