示例#1
0
 function testAuthnRequest()
 {
     $authnRequest = $this->getRequest();
     $id = $authnRequest->getID();
     $time = $authnRequest->getIssueInstant();
     $binding = new HttpPost();
     /** @var PostResponse $response */
     $response = $binding->send($authnRequest);
     $this->assertNotNull($response);
     $this->assertTrue($response instanceof PostResponse);
     $this->assertEquals($this->destination, $response->getDestination());
     /** @var $authnRequest AuthnRequest */
     $bindingRequest = new Request();
     $bindingRequest->setPost($response->getData());
     $authnRequest = $binding->receive($bindingRequest);
     $this->assertTrue($authnRequest instanceof AuthnRequest);
     $this->checkRequest($authnRequest, $id, $time);
 }
 /**
  * @param Request $request
  * @return null|string
  */
 private function processPOST(Request $request)
 {
     $post = $request->getPost();
     if (array_key_exists('SAMLRequest', $post) || array_key_exists('SAMLResponse', $post)) {
         return Bindings::SAML2_HTTP_POST;
     } elseif (array_key_exists('SAMLart', $post)) {
         return Bindings::SAML2_HTTP_ARTIFACT;
     } else {
         if ($request->getContentType()) {
             $contentType = explode(';', $request->getContentType());
             $contentType = $contentType[0];
             /* Remove charset. */
             if ($contentType === 'text/xml') {
                 return Bindings::SAML2_SOAP;
             }
         }
     }
     return null;
 }
示例#3
0
 /**
  * @param Request $request
  * @return Message
  * @throws \AerialShip\LightSaml\Error\BindingException
  */
 function receive(Request $request)
 {
     $post = $request->getPost();
     if (array_key_exists('SAMLRequest', $post)) {
         $msg = $post['SAMLRequest'];
     } elseif (array_key_exists('SAMLResponse', $post)) {
         $msg = $post['SAMLResponse'];
     } else {
         throw new BindingException('Missing SAMLRequest or SAMLResponse parameter');
     }
     $msg = base64_decode($msg);
     $this->dispatchReceive($msg);
     $doc = new \DOMDocument();
     $doc->loadXML($msg);
     $result = Message::fromXML($doc->firstChild);
     if (array_key_exists('RelayState', $post)) {
         $result->setRelayState($post['RelayState']);
     }
     return $result;
 }
 function testAuthnRequest()
 {
     $authnRequest = $this->getRequest();
     $id = $authnRequest->getID();
     $time = $authnRequest->getIssueInstant();
     $binding = new HttpRedirect();
     /** @var RedirectResponse $response */
     $response = $binding->send($authnRequest);
     $this->assertNotNull($response);
     $this->assertTrue($response instanceof RedirectResponse);
     $pos = strpos($response->getDestination(), '?');
     $destination = substr($response->getDestination(), 0, $pos);
     $queryString = substr($response->getDestination(), $pos + 1);
     $this->assertEquals($this->destination, $destination);
     $bindingRequest = new Request();
     $data = $bindingRequest->parseQueryString($queryString, true);
     $this->checkData($data);
     /** @var AuthnRequest $authnRequest */
     $authnRequest = $binding->receive($bindingRequest);
     $this->assertTrue($authnRequest instanceof AuthnRequest);
     $this->checkRequest($authnRequest, $id, $time);
 }
示例#5
0
 /**
  * @param Request $request
  * @return array
  */
 private function parseQuery(Request $request)
 {
     /*
      * Parse the query string. We need to do this ourself, so that we get access
      * to the raw (urlencoded) values. This is required because different software
      * can urlencode to different values.
      */
     $sigQuery = $relayState = $sigAlg = '';
     $data = $request->parseQueryString(null, false);
     $result = array();
     foreach ($data as $name => $value) {
         $result[$name] = urldecode($value);
         switch ($name) {
             case 'SAMLRequest':
             case 'SAMLResponse':
                 $sigQuery = $name . '=' . $value;
                 break;
             case 'RelayState':
                 $relayState = '&RelayState=' . $value;
                 break;
             case 'SigAlg':
                 $sigAlg = '&SigAlg=' . $value;
                 break;
         }
     }
     $result['SignedQuery'] = $sigQuery . $relayState . $sigAlg;
     return $result;
 }