Пример #1
0
 /**
  * Add contact information.
  *
  * Accepts a contact type, and a contact array that must be previously sanitized.
  *
  * WARNING: This function will change its signature and no longer parse a 'name' element.
  *
  * @param string $type The type of contact. Deprecated.
  * @param array  $details The details about the contact.
  *
  * @todo Change the signature to remove $type.
  * @todo Remove the capability to pass a name and parse it inside the method.
  */
 public function addContact($type, $details)
 {
     assert('is_string($type)');
     assert('is_array($details)');
     assert('in_array($type, array("technical", "support", "administrative", "billing", "other"), TRUE)');
     // TODO: remove this check as soon as getContact() is called always before calling this function
     $details = \SimpleSAML\Utils\Config\Metadata::getContact($details);
     $e = new \SAML2\XML\md\ContactPerson();
     $e->contactType = $type;
     if (isset($details['company'])) {
         $e->Company = $details['company'];
     }
     if (isset($details['givenName'])) {
         $e->GivenName = $details['givenName'];
     }
     if (isset($details['surName'])) {
         $e->SurName = $details['surName'];
     }
     if (isset($details['emailAddress'])) {
         $eas = $details['emailAddress'];
         if (!is_array($eas)) {
             $eas = array($eas);
         }
         foreach ($eas as $ea) {
             $e->EmailAddress[] = $ea;
         }
     }
     if (isset($details['telephoneNumber'])) {
         $tlfNrs = $details['telephoneNumber'];
         if (!is_array($tlfNrs)) {
             $tlfNrs = array($tlfNrs);
         }
         foreach ($tlfNrs as $tlfNr) {
             $e->TelephoneNumber[] = $tlfNr;
         }
     }
     $this->entityDescriptor->ContactPerson[] = $e;
 }
Пример #2
0
 /**
  * Test contact configuration parsing and sanitizing.
  */
 public function testGetContact()
 {
     // test invalid argument
     try {
         Metadata::getContact('string');
     } catch (\InvalidArgumentException $e) {
         $this->assertEquals('Invalid input parameters', $e->getMessage());
     }
     // test missing type
     $contact = array('name' => 'John Doe');
     try {
         Metadata::getContact($contact);
     } catch (\InvalidArgumentException $e) {
         $this->assertStringStartsWith('"contactType" is mandatory and must be one of ', $e->getMessage());
     }
     // test invalid type
     $contact = array('contactType' => 'invalid');
     try {
         Metadata::getContact($contact);
     } catch (\InvalidArgumentException $e) {
         $this->assertStringStartsWith('"contactType" is mandatory and must be one of ', $e->getMessage());
     }
     // test all valid contact types
     foreach (Metadata::$VALID_CONTACT_TYPES as $type) {
         $contact = array('contactType' => $type);
         $parsed = Metadata::getContact($contact);
         $this->assertArrayHasKey('contactType', $parsed);
         $this->assertArrayNotHasKey('givenName', $parsed);
         $this->assertArrayNotHasKey('surName', $parsed);
     }
     // test basic name parsing
     $contact = array('contactType' => 'technical', 'name' => 'John Doe');
     $parsed = Metadata::getContact($contact);
     $this->assertArrayNotHasKey('name', $parsed);
     $this->assertArrayHasKey('givenName', $parsed);
     $this->assertArrayHasKey('surName', $parsed);
     $this->assertEquals('John', $parsed['givenName']);
     $this->assertEquals('Doe', $parsed['surName']);
     // test comma-separated names
     $contact = array('contactType' => 'technical', 'name' => 'Doe, John');
     $parsed = Metadata::getContact($contact);
     $this->assertArrayHasKey('givenName', $parsed);
     $this->assertArrayHasKey('surName', $parsed);
     $this->assertEquals('John', $parsed['givenName']);
     $this->assertEquals('Doe', $parsed['surName']);
     // test long names
     $contact = array('contactType' => 'technical', 'name' => 'John Fitzgerald Doe Smith');
     $parsed = Metadata::getContact($contact);
     $this->assertArrayNotHasKey('name', $parsed);
     $this->assertArrayHasKey('givenName', $parsed);
     $this->assertArrayNotHasKey('surName', $parsed);
     $this->assertEquals('John Fitzgerald Doe Smith', $parsed['givenName']);
     // test comma-separated long names
     $contact = array('contactType' => 'technical', 'name' => 'Doe Smith, John Fitzgerald');
     $parsed = Metadata::getContact($contact);
     $this->assertArrayNotHasKey('name', $parsed);
     $this->assertArrayHasKey('givenName', $parsed);
     $this->assertArrayHasKey('surName', $parsed);
     $this->assertEquals('John Fitzgerald', $parsed['givenName']);
     $this->assertEquals('Doe Smith', $parsed['surName']);
     // test givenName
     $contact = array('contactType' => 'technical');
     $invalid_types = array(0, array(0), 0.1, true, false);
     foreach ($invalid_types as $type) {
         $contact['givenName'] = $type;
         try {
             Metadata::getContact($contact);
         } catch (\InvalidArgumentException $e) {
             $this->assertEquals('"givenName" must be a string and cannot be empty.', $e->getMessage());
         }
     }
     // test surName
     $contact = array('contactType' => 'technical');
     $invalid_types = array(0, array(0), 0.1, true, false);
     foreach ($invalid_types as $type) {
         $contact['surName'] = $type;
         try {
             Metadata::getContact($contact);
         } catch (\InvalidArgumentException $e) {
             $this->assertEquals('"surName" must be a string and cannot be empty.', $e->getMessage());
         }
     }
     // test company
     $contact = array('contactType' => 'technical');
     $invalid_types = array(0, array(0), 0.1, true, false);
     foreach ($invalid_types as $type) {
         $contact['company'] = $type;
         try {
             Metadata::getContact($contact);
         } catch (\InvalidArgumentException $e) {
             $this->assertEquals('"company" must be a string and cannot be empty.', $e->getMessage());
         }
     }
     // test emailAddress
     $contact = array('contactType' => 'technical');
     $invalid_types = array(0, 0.1, true, false, array());
     foreach ($invalid_types as $type) {
         $contact['emailAddress'] = $type;
         try {
             Metadata::getContact($contact);
         } catch (\InvalidArgumentException $e) {
             $this->assertEquals('"emailAddress" must be a string or an array and cannot be empty.', $e->getMessage());
         }
     }
     $invalid_types = array(array("string", true), array("string", 0));
     foreach ($invalid_types as $type) {
         $contact['emailAddress'] = $type;
         try {
             Metadata::getContact($contact);
         } catch (\InvalidArgumentException $e) {
             $this->assertEquals('Email addresses must be a string and cannot be empty.', $e->getMessage());
         }
     }
     $valid_types = array('*****@*****.**', array('*****@*****.**', '*****@*****.**'));
     foreach ($valid_types as $type) {
         $contact['emailAddress'] = $type;
         $parsed = Metadata::getContact($contact);
         $this->assertEquals($type, $parsed['emailAddress']);
     }
     // test telephoneNumber
     $contact = array('contactType' => 'technical');
     $invalid_types = array(0, 0.1, true, false, array());
     foreach ($invalid_types as $type) {
         $contact['telephoneNumber'] = $type;
         try {
             Metadata::getContact($contact);
         } catch (\InvalidArgumentException $e) {
             $this->assertEquals('"telephoneNumber" must be a string or an array and cannot be empty.', $e->getMessage());
         }
     }
     $invalid_types = array(array("string", true), array("string", 0));
     foreach ($invalid_types as $type) {
         $contact['telephoneNumber'] = $type;
         try {
             Metadata::getContact($contact);
         } catch (\InvalidArgumentException $e) {
             $this->assertEquals('Telephone numbers must be a string and cannot be empty.', $e->getMessage());
         }
     }
     $valid_types = array('1234', array('1234', '5678'));
     foreach ($valid_types as $type) {
         $contact['telephoneNumber'] = $type;
         $parsed = Metadata::getContact($contact);
         $this->assertEquals($type, $parsed['telephoneNumber']);
     }
     // test completeness
     $contact = array();
     foreach (Metadata::$VALID_CONTACT_OPTIONS as $option) {
         $contact[$option] = 'string';
     }
     $contact['contactType'] = 'technical';
     $contact['name'] = 'to_be_removed';
     $parsed = Metadata::getContact($contact);
     foreach (array_keys($parsed) as $key) {
         $this->assertEquals($parsed[$key], $contact[$key]);
     }
     $this->assertArrayNotHasKey('name', $parsed);
 }
Пример #3
0
 }
 if ($idpmeta->hasValue('redirect.validate')) {
     $metaArray['redirect.sign'] = $idpmeta->getBoolean('redirect.validate');
 }
 if ($idpmeta->hasValue('contacts')) {
     $contacts = $idpmeta->getArray('contacts');
     foreach ($contacts as $contact) {
         $metaArray['contacts'][] = \SimpleSAML\Utils\Config\Metadata::getContact($contact);
     }
 }
 $technicalContactEmail = $config->getString('technicalcontact_email', false);
 if ($technicalContactEmail && $technicalContactEmail !== '*****@*****.**') {
     $techcontact['emailAddress'] = $technicalContactEmail;
     $techcontact['name'] = $config->getString('technicalcontact_name', null);
     $techcontact['contactType'] = 'technical';
     $metaArray['contacts'][] = \SimpleSAML\Utils\Config\Metadata::getContact($techcontact);
 }
 $metaBuilder = new SimpleSAML_Metadata_SAMLBuilder($idpentityid);
 $metaBuilder->addMetadataIdP20($metaArray);
 $metaBuilder->addOrganizationInfo($metaArray);
 $metaxml = $metaBuilder->getEntityDescriptorText();
 $metaflat = '$metadata[' . var_export($idpentityid, true) . '] = ' . var_export($metaArray, true) . ';';
 // sign the metadata if enabled
 $metaxml = SimpleSAML_Metadata_Signer::sign($metaxml, $idpmeta->toArray(), 'SAML 2 IdP');
 if (array_key_exists('output', $_GET) && $_GET['output'] == 'xhtml') {
     $defaultidp = $config->getString('default-saml20-idp', null);
     $t = new SimpleSAML_XHTML_Template($config, 'metadata.php', 'admin');
     $t->data['clipboard.js'] = true;
     $t->data['available_certs'] = $availableCerts;
     $t->data['header'] = 'saml20-idp';
     $t->data['metaurl'] = \SimpleSAML\Utils\HTTP::getSelfURLNoQuery();
Пример #4
0
 if ($idpmeta->hasValue('UIInfo')) {
     $metaArray['UIInfo'] = $idpmeta->getArray('UIInfo');
 }
 if ($idpmeta->hasValue('DiscoHints')) {
     $metaArray['DiscoHints'] = $idpmeta->getArray('DiscoHints');
 }
 if ($idpmeta->hasValue('RegistrationInfo')) {
     $metaArray['RegistrationInfo'] = $idpmeta->getArray('RegistrationInfo');
 }
 $metaflat = '$metadata[' . var_export($idpentityid, true) . '] = ' . var_export($metaArray, true) . ';';
 $metaBuilder = new SimpleSAML_Metadata_SAMLBuilder($idpentityid);
 $metaBuilder->addSecurityTokenServiceType($metaArray);
 $metaBuilder->addOrganizationInfo($metaArray);
 $technicalContactEmail = $config->getString('technicalcontact_email', null);
 if ($technicalContactEmail && $technicalContactEmail !== '*****@*****.**') {
     $metaBuilder->addContact('technical', \SimpleSAML\Utils\Config\Metadata::getContact(array('emailAddress' => $technicalContactEmail, 'name' => $config->getString('technicalcontact_name', null), 'contactType' => 'technical')));
 }
 $output_xhtml = array_key_exists('output', $_GET) && $_GET['output'] == 'xhtml';
 $metaxml = $metaBuilder->getEntityDescriptorText($output_xhtml);
 if (!$output_xhtml) {
     $metaxml = str_replace("\n", '', $metaxml);
 }
 // sign the metadata if enabled
 $metaxml = SimpleSAML_Metadata_Signer::sign($metaxml, $idpmeta->toArray(), 'ADFS IdP');
 if ($output_xhtml) {
     $defaultidp = $config->getString('default-adfs-idp', null);
     $t = new SimpleSAML_XHTML_Template($config, 'metadata.php', 'admin');
     $t->data['clipboard.js'] = true;
     $t->data['available_certs'] = $availableCerts;
     $t->data['header'] = 'adfs-idp';
     // TODO: Replace with headerString in 2.0
Пример #5
0
 }
 if ($idpmeta->hasValue('redirect.validate')) {
     $metaArray['redirect.sign'] = $idpmeta->getBoolean('redirect.validate');
 }
 if ($idpmeta->hasValue('contacts')) {
     $contacts = $idpmeta->getArray('contacts');
     foreach ($contacts as $contact) {
         $metaArray['contacts'][] = Metadata::getContact($contact);
     }
 }
 $technicalContactEmail = $config->getString('technicalcontact_email', false);
 if ($technicalContactEmail && $technicalContactEmail !== '*****@*****.**') {
     $techcontact['emailAddress'] = $technicalContactEmail;
     $techcontact['name'] = $config->getString('technicalcontact_name', null);
     $techcontact['contactType'] = 'technical';
     $metaArray['contacts'][] = Metadata::getContact($techcontact);
 }
 $metaBuilder = new SimpleSAML_Metadata_SAMLBuilder($idpentityid);
 $metaBuilder->addMetadataIdP20($metaArray);
 $metaBuilder->addOrganizationInfo($metaArray);
 $metaxml = $metaBuilder->getEntityDescriptorText();
 $metaflat = '$metadata[' . var_export($idpentityid, true) . '] = ' . var_export($metaArray, true) . ';';
 // sign the metadata if enabled
 $metaxml = SimpleSAML_Metadata_Signer::sign($metaxml, $idpmeta->toArray(), 'SAML 2 IdP');
 if (array_key_exists('output', $_GET) && $_GET['output'] == 'xhtml') {
     $defaultidp = $config->getString('default-saml20-idp', null);
     $t = new SimpleSAML_XHTML_Template($config, 'metadata.php', 'admin');
     $t->data['clipboard.js'] = true;
     $t->data['available_certs'] = $availableCerts;
     $t->data['header'] = 'saml20-idp';
     // TODO: Replace with headerString in 2.0