Receive a SAML 2 message sent using the HTTP-POST binding.

@throws \Exception If unable to receive the message
@return \SAML2\Message The received message.
172448
public function receive() : Message
    {
        $postText = $this->getInputStream();

        if ($postText === false) {
            throw new \Exception('Invalid message received to AssertionConsumerService endpoint.');
        }

        $document = DOMDocumentFactory::fromString($postText);
        $xml = $document->firstChild;
        Utils::getContainer()->debugMessage($document->documentElement, 'in');
        /** @var \DOMElement[] $results */
        $results = Utils::xpQuery($xml, '/soap-env:Envelope/soap-env:Body/*[1]');

        return Message::fromXML($results[0]);
    }
44651
public function handle_message()
    {
        $selected = $this->socket->select($this->keepalive / 2);

        if ($selected === false) {
            # Error
            throw new Exception\NetworkError('Connection lost???');
        } else if ($selected) {
            return $this->handle_incoming();
        } else {
            # no incoming packet
            return 0;
        }
    }
311870
public function receive() : ?Message
    {
        if (array_key_exists('SAMLart', $_REQUEST)) {
            $artifact = base64_decode($_REQUEST['SAMLart']);
            $endpointIndex = bin2hex(substr($artifact, 2, 2));
            $sourceId = bin2hex(substr($artifact, 4, 20));
        } else {
            throw new \Exception('Missing SAMLart parameter.');
        }

        /** @psalm-suppress UndefinedClass */
        $metadataHandler = MetaDataStorageHandler::getMetadataHandler();

        $idpMetadata = $metadataHandler->getMetaDataConfigForSha1($sourceId, 'saml20-idp-remote');

        if ($idpMetadata === null) {
            throw new \Exception('No metadata found for remote provider with SHA1 ID: '.var_export($sourceId, true));
        }

        $endpoint = null;
        foreach ($idpMetadata->getEndpoints('ArtifactResolutionService') as $ep) {
            if ($ep['index'] === hexdec($endpointIndex)) {
                $endpoint = $ep;
                break;
            }
        }

        if ($endpoint === null) {
            throw new \Exception('No ArtifactResolutionService with the correct index.');
        }

        Utils::getContainer()->getLogger()->debug("ArtifactResolutionService endpoint being used is := ".$endpoint['Location']);

        //Construct the ArtifactResolve Request
        $ar = new ArtifactResolve();

        /* Set the request attributes */

        /** @psalm-suppress UndefinedClass */
        $ar->setIssuer($this->spMetadata->getString('entityid'));
        $ar->setArtifact($_REQUEST['SAMLart']);
        $ar->setDestination($endpoint['Location']);

        // sign the request
        /** @psalm-suppress UndefinedClass */
        MSG::addSign($this->spMetadata, $idpMetadata, $ar); // Shoaib - moved from the SOAPClient.

        $soap = new SOAPClient();

        // Send message through SoapClient
        /** @var \SAML2\ArtifactResponse $artifactResponse */
        $artifactResponse = $soap->send($ar, $this->spMetadata);

        if (!$artifactResponse->isSuccess()) {
            throw new \Exception('Received error from ArtifactResolutionService.');
        }

        $xml = $artifactResponse->getAny();
        if ($xml === null) {
            /* Empty ArtifactResponse - possibly because of Artifact replay? */

            throw new \Exception('Empty ArtifactResponse received, maybe a replay?');
        }

        $samlResponse = Message::fromXML($xml);
        $samlResponse->addValidator([get_class($this), 'validateSignature'], $artifactResponse);

        if (isset($_REQUEST['RelayState'])) {
            $samlResponse->setRelayState($_REQUEST['RelayState']);
        }

        return $samlResponse;
    }
1190167
public function send()
	{
		if( $this->method === 'POST' )
			$this->addHeaderPair( 'Content-Length', mb_strlen( $this->data ) );
		if( !$this->headers->getFieldsByName( 'connection' ) )
			$this->addHeaderPair( 'Connection', 'close' );

		$result	= "";
		$fp = fsockopen( $this->host, $this->port, $errno, $errstr, 2 );
		if( !$fp )
			throw new RuntimeException( $errstr.' ('.$errno.')' );

		$uri	= $this->uri/*.( $this->port ? ':'.$this->port : "" )*/;
		$lines	= array(
			$this->method." ".$uri." HTTP/".$this->version,
			$this->headers->render(),
		);
		if( $this->method === 'POST' )
			$lines[]	= $this->data;
		$lines	= join( "\r\n", $lines );
		fwrite( $fp, $lines );																		//  send Request
		while( !feof( $fp ) )																		//  receive Response
			$result .= fgets( $fp, 1024 );															//  collect Response chunks
		fclose( $fp );																				//  close Connection
		$response	= Net_HTTP_Response_Parser::fromString( $result );
		if( count( $response->getHeader( 'Location' ) ) ){
			$location	= array_shift( $response->getHeader( 'Location' ) );
			$this->host	= parse_url( $location->getValue(), PHP_URL_HOST );
			$this->setPort( parse_url( $location->getValue(), PHP_URL_PORT ) );
			$this->setUri( parse_url( $location->getValue(), PHP_URL_PATH ) );
			return $this->send();
		}
		return $response;
	}
133503
public function getStatus()
    {
        if (null === $this->username || null === $this->password) {
            throw new Exception\InvalidCredentialsException('No API credentials provided');
        }

        $res = $this->getAdapter()->getContent(self::SMS_STATUS_URL, 'POST', $headers = array(), $this->getParameters());

        return $this->parseStatusResults($res);
    }
370428
public function post()
    {
        $request = $this->getDI()->get('request');
        // supply everything the request object could possibly need to fulfill the request
        $post = $request->getJson($this->getControllerName('singular'), $this->getModel());

        if (!$post) {
            throw new HTTPException('There was an error adding new record.  Missing POST data.', 400, [
                'dev' => 'Invalid data posted to the server',
                'code' => '568136818916816555'
            ]);
        }

        if(method_exists($this->model, "getBlockColumns")) {
            // filter out any block columns from the posted data
            $blockFields = $this->model->getBlockColumns();
            foreach ($blockFields as $key => $value) {
                unset($post->$value);
            }
        }

        $post = $this->beforeSave($post);
        // This record only must be created
        $id = $this->entity->save($post);
        $this->afterSave($post, $id);

        // now fetch the record so we can return it
        $result = $this->entity->findFirst($id);

        if ($result->countResults() == 0) {
            // This is bad. Throw a 500. Responses should always be objects.
            throw new HTTPException('There was an error retrieving the newly created record.', 500, [
                'dev' => 'The resource you requested is not available after it was just created',
                'code' => '1238510381861'
            ]);
        } else {
            return $result;
        }
    }
800827
public function sendRequest()
    {
        try {
            if (mb_strlen($this->url) >= 9) {
                $response       = $this->useFileGetContents();
                $this->response = $response;

                return $response;
            }
        }
        catch (Exception $e) {
            $message = "Error: " . __CLASS__ . ": Please make sure to set a URL to fetch - Line: " . $e->getLine() . ' - Msg: ' . $e->getMessage();
            $this->debug->error(__FUNCTION__, $message);

            return $message;
        }

        return NULL;
    }
233075
protected function postMessages()
    {
      $url = URIResource::Make($this->path);

      $messages = $this->client->post($url, $this->messages);
    
      return $messages;
    }
768169
protected function prepareRST2Request($samlAssertion)
    {

      $fileName = __DIR__ . '/xml/RST2.xml';
      if (!file_exists($fileName)) {
        throw new \Exception("The file $fileName does not exist");
      }
      $template = file_get_contents($fileName);

      $xml = new \DOMDocument();
      $xml->loadXML($template);
      $xpath = new \DOMXPath($xml);

      $samlAssertion = $xml->importNode($samlAssertion, true);
      if ($xpath->query("//*[name()='wsse:Security']")->length > 0) {
          $parentNode = $xpath->query("//wsse:Security")->item(0);
          //append "saml assertion" node to <wsse:Security> node
          $parentNode->appendChild($samlAssertion);
          return $xml->saveXML();
      }

      return NULL;
    }
894532
public function create() {
		$ssoClient = new \Flowpack\SingleSignOn\Client\Domain\Model\SsoClient();
		if ((string)$this->clientServiceBaseUri === '') {
			throw new Exception('Missing Flowpack.SingleSignOn.Client.client.serviceBaseUri setting', 1351075078);
		}
		$ssoClient->setServiceBaseUri($this->clientServiceBaseUri);
		if ((string)$this->clientPublicKeyFingerprint === '') {
			throw new Exception('Missing Flowpack.SingleSignOn.Client.client.publicKeyFingerprint setting', 1351075159);
		}
		$ssoClient->setPublicKeyFingerprint($this->clientPublicKeyFingerprint);
		return $ssoClient;
	}
261608
public function send()
    {
        if (!$this->from) {
            throw new \Exception('Message sender has not been set');
        }

        if (!$this->body) {
            throw new \Exception('Message body has not been set');
        }

        if (!$this->to) {
            throw new \Exception('Message receiver has not been set');
        }

        $command = new SendMessageCommand($this->to, $this->body, $this->from, $this->type);

        return $this->commandBus->execute($command);
    }
1290729
public function send() {

            if(!extension_loaded('curl')) throw new Exception('CURL library not loaded!');

            // cleanup any response
            $this->response = array();
 
            // array of curl handles
            $curly = array();
            
            // data to be returned
            $result = array();
            
            // multi handle
            $mh = curl_multi_init();
            
            // make sure request is array
            if (is_string($this->request)) $this->request = array($this->request);
           
            // loop through data request and create curl handles then add them to the multi-handle
            foreach ($this->request as $id => $d) {
                $curly[$id] = curl_init();
                $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
                curl_setopt($curly[$id], CURLOPT_URL, $url);
                if ($this->httpStatusOnly) curl_setopt($curly[$id], CURLOPT_NOBODY, 1);
           
                // contains data to post?
                if (is_array($d)) {
                    if (!empty($d['post'])) {
                        curl_setopt($curly[$id], CURLOPT_POST,       1);
                        if ($this->encoded && is_array($d['post'])) {
                            curl_setopt($curly[$id], CURLOPT_POSTFIELDS, http_build_query($d['post']));
                        } else {
                            curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
                        }
                    }
                }
           
                // set options?
                if (!empty($this->options)) {
                    curl_setopt_array($curly[$id], $this->options);
                } else {
                    curl_setopt($curly[$id], CURLOPT_HEADER,         0);
                    curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
                }

                // activate curl response message
                if($this->httpInfo === 'detail'){
                    if (empty($this->options[CURLOPT_FAILONERROR]) || (!empty($this->options[CURLOPT_FAILONERROR]) && $this->options[CURLOPT_FAILONERROR] == false)){
                        curl_setopt($curly[$id], CURLOPT_FAILONERROR, 1);
                    }
                }
           
                curl_multi_add_handle($mh, $curly[$id]);
            }
           
            // execute the handles
            $running = null;
            do {
                $mrc =curl_multi_exec($mh, $running);
            } while($mrc == CURLM_CALL_MULTI_PERFORM);

            // perform multi select
            while ($running && $mrc == CURLM_OK) {
                if (curl_multi_select($mh) == -1) {
                    // delay time for cpu take a rest in every 10ms
                    usleep($this->delayTime);
                }
            
                do {
                    $mrc = curl_multi_exec($mh, $running);
                } while ($mrc == CURLM_CALL_MULTI_PERFORM);
            }
           
            // get content and remove handles
            foreach($curly as $id => $c) {
                if ($this->httpStatusOnly){
                    $result[$id] = curl_getinfo($c, CURLINFO_HTTP_CODE);
                } else {
                    if ($this->httpInfo){
                        $curl_errno = curl_errno($c);
                        if($this->httpInfo === 'detail'){
                            $http_code = curl_getinfo($c, CURLINFO_HTTP_CODE);
                            $curl_error = curl_error($c);
                            $result[$id] = [
                                'code' => $http_code,
                                'info' => [
                                    'url' => curl_getinfo($c, CURLINFO_EFFECTIVE_URL),
                                    'content_type' => curl_getinfo($c, CURLINFO_CONTENT_TYPE),
                                    'content_length' => curl_getinfo($c, CURLINFO_CONTENT_LENGTH_DOWNLOAD),
                                    'total_time' => curl_getinfo($c, CURLINFO_TOTAL_TIME),
                                    'debug' => 'CURLcode ['.$curl_errno.']: '.$this->getCurlCode($curl_errno),
                                    'message' => (($curl_error)?$curl_error:(($http_code == 0)?'The requested URL returned error: Unknown':'Request URL finished'))
                                ],
                                'response' => curl_multi_getcontent($c)
                            ];
                        } else {
                            $result[$id] = [
                                'code' => curl_getinfo($c, CURLINFO_HTTP_CODE),
                                'debug' => $this->getCurlCode($curl_errno),
                                'response' => curl_multi_getcontent($c)
                            ];
                        }
                    } else {
                        $result[$id] = curl_multi_getcontent($c);
                    }
                }
                curl_multi_remove_handle($mh, $c);
            }
           
            // close when all is done
            curl_multi_close($mh);
            if (count($result) <= 1) {
                $this->response = $result[0];
            } else {
                $this->response = $result;
            }
            return $this;
        }
288109
public function sls()
    {
        $error = $this->saml2Auth->sls(config('saml2_settings.retrieveParametersFromServer'));
        if (!empty($error)) {
            throw new \Exception("Could not log out");
        }

        return redirect(config('saml2_settings.logoutRoute')); //may be set a configurable default
    }
663305
public function validateAndParseWebhookNotificationFromCurrentRequest() {
        // read the JSON input
        $json_string = file_get_contents('php://input');

        $json_data = json_decode($json_string, true);

        // make sure the message is signed properly
        //   throws an exception if invalid
        $this->validateWebhookNotification($json_data);

        // return the payload
        return $this->parseWebhookNotificationData($json_data);
    }
44560
private function makeHttpRequest()
    {
        try {
            return $this->client->post($this->apiUrl, [
                'json'    => $this->post->toArray(),
                'headers' => $this->setHeaders(),
            ])->getBody();
        } catch (\GuzzleHttp\Exception\ClientException $e) {
            throw new \Exception(collect($e->getTrace())->implode('\n'));
        } catch (\GuzzleHttp\Exception\ServerException $e) {
            throw new \Exception(collect($e->getTrace())->implode('\n'));
        } catch (\GuzzleHttp\Exception\BadResponseException $e) {
            throw new \Exception(collect($e->getTrace())->implode('\n'));
        }
    }
562624
public function sendPerformance()
    {
        $headers = [
            'token' => $this->token,
        ];

        if (is_null($this->token)) {
            throw new Exception("Missing token", 1);
        }

        $query = $this->getPerformance();

        $response = $this->curl::post($this->missionControlUrl, $headers, $query);

        if ($response->code != 200) {
            $this->error('Unable to message Mission Control, please confirm your token');
        }

        return true;
    }
1172434
protected function getRequest()
    {
        $url = $this->buildUrl($this->getBody());

        $response = $this->client->get($url, [
            'auth'    => $this->getAuth(),
            'headers' => [
                'Accept' => 'application/json',
            ],
        ]);

        if ($response->getStatusCode() != 201 && $response->getStatusCode() != 200) {
            throw new \Exception('Unable to request from API.');
        }

        return $response;
    }