public function setAuthentication(Authentication $authentication)
    {
        $firstAuthentication = null === $this->authentication;

        $this->authentication = $authentication;

        if ($firstAuthentication && is_resource($this->resource)) {
            $this->authenticate();
        }
    }