/**
  * @dataProvider provider
  */
 public function testAuthnRequestBuilder($name, array $idpData, array $spData, array $spMetaData, $expectedSendUrl, $expectedResponseType, $expectedReceiveUrl, $expectedReceiveBinding, $expectedException = null, $expectedExceptionMessage = '')
 {
     if ($expectedException) {
         $this->setExpectedException($expectedException, $expectedExceptionMessage);
     }
     $idp = new IdpSsoDescriptor();
     foreach ($idpData as $data) {
         $idp->addService(new SingleSignOnService($data['binding'], $data['url']));
     }
     $edIDP = new EntityDescriptor('idp');
     $edIDP->addItem($idp);
     $sp = new SpSsoDescriptor();
     foreach ($spData as $data) {
         $sp->addService(new AssertionConsumerService($data['binding'], $data['url']));
     }
     $edSP = new EntityDescriptor('sp');
     $edSP->addItem($sp);
     $spMeta = new SpMeta();
     foreach ($spMetaData as $name => $value) {
         $spMeta->{$name}($value);
     }
     $builder = new AuthnRequestBuilder($edSP, $edIDP, $spMeta);
     $message = $builder->build();
     $response = $builder->send($message);
     $this->assertStringStartsWith($expectedSendUrl, $response->getDestination(), $name);
     $this->assertInstanceOf($expectedResponseType, $response, $name);
     $this->assertEquals($expectedReceiveUrl, $message->getAssertionConsumerServiceURL(), $name);
     $this->assertEquals($expectedReceiveBinding, $message->getProtocolBinding(), $name);
 }
 protected function askForCertificate(DialogHelper $dialog, OutputInterface $output, EntityDescriptor $ed)
 {
     $certificatePath = $this->askFile($dialog, $output, 'Signing Certificate path', false);
     if ($certificatePath) {
         $certificate = new X509Certificate();
         $certificate->loadFromFile($certificatePath);
         $keyDescriptor = new KeyDescriptor('signing', $certificate);
         $ed->addItem($keyDescriptor);
     }
 }
 protected function build()
 {
     $this->entityDescriptor = new EntityDescriptor($this->config['entity_id']);
     $sp = new SpSsoDescriptor();
     $this->entityDescriptor->addItem($sp);
     $sp->setWantAssertionsSigned($this->config['want_assertions_signed']);
     if ($this->signingProvider->isEnabled()) {
         $sp->addKeyDescriptor(new KeyDescriptor('signing', $this->signingProvider->getCertificate()));
     }
     $slo = new SingleLogoutService();
     $sp->addService($slo);
     $slo->setBinding(Bindings::SAML2_HTTP_REDIRECT);
     $slo->setLocation($this->buildPath($this->logoutPath));
     $slo = new SingleLogoutService();
     $sp->addService($slo);
     $slo->setBinding(Bindings::SAML2_HTTP_POST);
     $slo->setLocation($this->buildPath($this->logoutPath));
     $sp->addService(new AssertionConsumerService(Bindings::SAML2_HTTP_POST, $this->buildPath($this->checkPath), 0));
     $sp->addService(new AssertionConsumerService(Bindings::SAML2_HTTP_REDIRECT, $this->buildPath($this->checkPath), 1));
 }
 /**
  * @dataProvider provider
  */
 public function testAuthnRequestBuilder($name, array $idpData, array $spData, array $spMetaData, $expectedSendUrl, $expectedResponseType, $expectedReceiveUrl, $expectedReceiveBinding, $expectedException = null, $expectedExceptionMessage = '')
 {
     if ($expectedException) {
         $this->setExpectedException($expectedException, $expectedExceptionMessage);
     }
     $idp = new IdpSsoDescriptor();
     foreach ($idpData as $data) {
         $idp->addService(new SingleSignOnService($data['binding'], $data['url']));
     }
     $edIDP = new EntityDescriptor('idp');
     $edIDP->addItem($idp);
     $sp = new SpSsoDescriptor();
     foreach ($spData as $data) {
         $sp->addService(new AssertionConsumerService($data['binding'], $data['url']));
     }
     $edSP = new EntityDescriptor('sp');
     $edSP->addItem($sp);
     $spMeta = new SpMeta();
     foreach ($spMetaData as $name => $value) {
         $spMeta->{$name}($value);
     }
     // without signing
     $builder = new AuthnRequestBuilder($edSP, $edIDP, $spMeta);
     $message = $builder->build();
     $response = $builder->send($message);
     $this->assertStringStartsWith($expectedSendUrl, $response->getDestination(), $name);
     $this->assertInstanceOf($expectedResponseType, $response, $name);
     $this->assertEquals($expectedReceiveUrl, $message->getAssertionConsumerServiceURL(), $name);
     $this->assertEquals($expectedReceiveBinding, $message->getProtocolBinding(), $name);
     // with signing
     $signature = new SignatureCreator();
     $certificate = new X509Certificate();
     $certificate->loadFromFile(__DIR__ . '/../../../../../resources/sample/Certificate/saml.crt');
     $key = new \XMLSecurityKey(\XMLSecurityKey::RSA_SHA1, array('type' => 'private'));
     $key->loadKey(__DIR__ . '/../../../../../resources/sample/Certificate/saml.pem', true);
     $signature->setCertificate($certificate);
     $signature->setXmlSecurityKey($key);
     $builder = new AuthnRequestBuilder($edSP, $edIDP, $spMeta, $signature);
     $message = $builder->build();
     $response = $builder->send($message);
     $this->assertStringStartsWith($expectedSendUrl, $response->getDestination(), $name);
     $this->assertInstanceOf($expectedResponseType, $response, $name);
     $this->assertEquals($expectedReceiveUrl, $message->getAssertionConsumerServiceURL(), $name);
     $this->assertEquals($expectedReceiveBinding, $message->getProtocolBinding(), $name);
 }