public function loginAsUser(User $user)
    {
        if (null !== ($current_token = $this->app['security']->getToken())) {
            $providerKey = method_exists($current_token, 'getProviderKey') ? $current_token->getProviderKey() : $current_token->getKey();
            $token = new UsernamePasswordToken($user, null, $providerKey);
            $this->app['security']->setToken($token);

            $this->app['user'] = $user;
        }
    }
public function loginAsUser(User $user)
    {
        if (null !== ($current_token = $this->app['security']->getToken())) {
            $providerKey = method_exists($current_token, 'getProviderKey') ? $current_token->getProviderKey() : $current_token->getKey();
            $token = new UsernamePasswordToken($user, null, $providerKey);
            $this->app['security']->setToken($token);

            $this->app['user'] = $user;
        }
    }
public function loginAsUser ( User $ user ) { if ( null !== ( $ current_token = $ this -> app [ 'security' ] -> getToken ( ) ) ) { $ providerKey = method_exists ( $ current_token , 'getProviderKey' ) ? $ current_token -> getProviderKey ( ) : $ current_token -> getKey ( ) ; $ token = new UsernamePasswordToken ( $ user , null , $ providerKey ) ; $ this -> app [ 'security' ] -> setToken ( $ token ) ; $ this -> app [ 'user' ] = $ user ; } }
Log in as the given user.

Sets the security token for the current request so it will be logged in as the given user.

@param User $user
Log in as the given user .