getEntityDescriptorText() public method

This function serializes this EntityDescriptor, and returns it as text.
public getEntityDescriptorText ( boolean $formatted = true ) : string
$formatted boolean Whether the returned EntityDescriptor should be formatted first.
return string The serialized EntityDescriptor.
Beispiel #1
0
 public function getMetadata()
 {
     $idpentityid = SimpleSAML_Utilities::getBaseURL() . 'module.php/fedlab/metadata.php';
     $metaArray = array('metadata-set' => 'saml20-idp-remote', 'entityid' => $idpentityid, 'SingleSignOnService' => SimpleSAML_Utilities::getBaseURL() . 'module.php/fedlab/SingleSignOnService.php', 'SingleLogoutService' => SimpleSAML_Utilities::getBaseURL() . 'module.php/fedlab/SingleLogoutService.php', 'certificate' => 'server.crt');
     $metaArrayConfig = SimpleSAML_Configuration::loadFromArray($metaArray);
     $certInfo = SimpleSAML_Utilities::loadPublicKey($metaArrayConfig, TRUE);
     $metaBuilder = new SimpleSAML_Metadata_SAMLBuilder($idpentityid);
     $metaBuilder->addMetadataIdP20($metaArray);
     $metaBuilder->addOrganizationInfo($metaArray);
     $metaBuilder->addContact('technical', array('emailAddress' => $this->config->getString('technicalcontact_email', NULL), 'name' => $this->config->getString('technicalcontact_name', NULL)));
     $metaxml = $metaBuilder->getEntityDescriptorText();
     return $metaxml;
 }
Beispiel #2
0
$metaArray20 = array('AssertionConsumerService' => SimpleSAML_Module::getModuleURL('saml/sp/saml2-acs.php/' . $sourceId), 'SingleLogoutService' => SimpleSAML_Module::getModuleURL('saml/sp/saml2-logout.php/' . $sourceId));
if ($spconfig->getBoolean('saml20.binding.artifact.enable', FALSE)) {
    $metaArray20['AssertionConsumerService.artifact'] = SimpleSAML_Module::getModuleURL('saml/sp/saml2-acs.php/' . $sourceId);
}
$certInfo = SimpleSAML_Utilities::loadPublicKey($spconfig->toArray());
if ($certInfo !== NULL && array_key_exists('certData', $certInfo)) {
    $certData = $certInfo['certData'];
    $metaArray11['certData'] = $certData;
    $metaArray20['certData'] = $certData;
}
$metaBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId);
$metaBuilder->addMetadataSP11($metaArray11);
$metaBuilder->addMetadataSP20($metaArray20);
$config = SimpleSAML_Configuration::getInstance();
$metaBuilder->addContact('technical', array('emailAddress' => $config->getString('technicalcontact_email', NULL), 'name' => $config->getString('technicalcontact_name', NULL)));
$xml = $metaBuilder->getEntityDescriptorText();
if (array_key_exists('output', $_REQUEST) && $_REQUEST['output'] == 'xhtml') {
    $t = new SimpleSAML_XHTML_Template($config, 'metadata.php', 'admin');
    $t->data['header'] = 'saml20-sp';
    $t->data['metadata'] = htmlspecialchars($xml);
    $t->data['metadataflat'] = '$metadata[' . var_export($entityId, TRUE) . '] = ' . var_export($metaArray20, TRUE) . ';';
    $t->data['metaurl'] = $source->getMetadataURL();
    $t->data['idpsend'] = array();
    $t->data['sentok'] = FALSE;
    $t->data['adminok'] = FALSE;
    $t->data['adminlogin'] = NULL;
    $t->data['techemail'] = $config->getString('technicalcontact_email', NULL);
    $t->show();
} else {
    header('Content-Type: application/samlmetadata+xml');
    echo $xml;
 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
     $t->data['headerString'] = $t->noop('metadata_adfs-idp');
     $t->data['metaurl'] = \SimpleSAML\Utils\HTTP::getSelfURLNoQuery();
     $t->data['metadata'] = htmlspecialchars($metaxml);
Beispiel #4
0
 private static function getMetadata($eid, $revision, $type = null, array $option = null)
 {
     assert('ctype_digit($eid)');
     assert('ctype_digit($revision)');
     $janus_config = sspmod_janus_DiContainer::getInstance()->getConfig();
     $entityController = sspmod_janus_DiContainer::getInstance()->getEntityController();
     if (!($entity = $entityController->setEntity($eid, $revision))) {
         self::$_error = array('Entity could not be loaded - Eid: ' . $eid . ' Revisionid: ' . $revision);
         return false;
     }
     $metadata_raw = $entityController->getMetadata();
     // Get metadata fields
     $nm_mb = new sspmod_janus_MetadataFieldBuilder($janus_config->getArray('metadatafields.' . $entity->getType()));
     $metadatafields_required = $nm_mb->getMetadataFields();
     // Get required metadata fields
     $required = array();
     foreach ($metadatafields_required as $mf) {
         if (isset($mf->required) && $mf->required === true) {
             $required[] = $mf->name;
         }
     }
     // Get metadata to me tested
     $metadata = array();
     foreach ($metadata_raw as $k => $v) {
         // Metadata field not defined
         if (!isset($metadatafields_required[$v->getKey()])) {
             continue;
         }
         // Value not set for metadata
         if (is_string($v->getValue()) && $v->getValue() == '') {
             continue;
         }
         // Compute is the default values is allowed
         $default_allow = false;
         if (isset($metadatafields_required[$v->getKey()]->default_allow) && is_bool($metadatafields_required[$v->getKey()]->default_allow)) {
             $default_allow = $metadatafields_required[$v->getKey()]->default_allow;
         }
         /*
          * Do not include metadata if value is set to default and default
          * is not allowed.
          */
         if (!$default_allow && (isset($metadatafields_required[$v->getKey()]->default) && $v->getValue() == $metadatafields_required[$v->getKey()]->default)) {
             continue;
         }
         $metadata[] = $v->getKey();
     }
     // Compute missing metadata that is required
     $missing_required = array_diff($required, $metadata);
     $entityId = $entity->getEntityid();
     if (!empty($missing_required)) {
         SimpleSAML_Logger::error('JANUS - Missing required metadata fields. Entity_id:' . $entityId);
         self::$_error = $missing_required;
         return false;
     }
     try {
         $metaArray = $entityController->getMetaArray();
         $metaArray['eid'] = $eid;
         $blockedEntities = $entityController->getBlockedEntities();
         $allowedEntities = $entityController->getAllowedEntities();
         $disabledConsent = $entityController->getDisableConsent();
         $metaFlat = '// Revision: ' . $entity->getRevisionid() . "\n";
         $metaFlat .= var_export($entityId, TRUE) . ' => ' . var_export($metaArray, TRUE) . ',';
         // Add authproc filter to block blocked entities
         if (!empty($blockedEntities) || !empty($allowedEntities)) {
             $metaFlat = substr($metaFlat, 0, -2);
             if (!empty($allowedEntities)) {
                 $metaFlat .= "  'allowed' => array(\n";
                 $metaArray['allowed'] = array();
                 foreach ($allowedEntities as $allowedEntity) {
                     $metaFlat .= "      '" . $allowedEntity['remoteentityid'] . "',\n";
                     $metaArray['allowed'][] = $allowedEntity['remoteentityid'];
                 }
                 $metaFlat .= "  ),\n";
             }
             if (!empty($blockedEntities)) {
                 $metaFlat .= "  'blocked' => array(\n";
                 $metaArray['blocked'] = array();
                 foreach ($blockedEntities as $blockedEntity) {
                     $metaFlat .= "    '" . $blockedEntity['remoteentityid'] . "',\n";
                     $metaArray['blocked'][] = $blockedEntity['remoteentityid'];
                 }
                 $metaFlat .= "  ),\n";
             }
             $metaFlat .= '),';
         }
         // Add disable consent
         if (!empty($disabledConsent)) {
             $metaFlat = substr($metaFlat, 0, -2);
             $metaFlat .= "  'consent.disable' => array(\n";
             foreach ($disabledConsent as $key => $value) {
                 $metaFlat .= "    '" . $key . "',\n";
             }
             $metaFlat .= "  ),\n";
             $metaFlat .= '),';
         }
         $maxCache = isset($option['maxCache']) ? $option['maxCache'] : null;
         $maxDuration = isset($option['maxDuration']) ? $option['maxDuration'] : null;
         try {
             $metaBuilder = new SimpleSAML_Metadata_SAMLBuilder($entityId, $maxCache, $maxDuration);
             $metaBuilder->addMetadata($metaArray['metadata-set'], $metaArray);
         } catch (Exception $e) {
             SimpleSAML_Logger::error('JANUS - Entity_id:' . $entityId . ' - Error generating XML metadata - ' . var_export($e, true));
             self::$_error = array('Error generating XML metadata - ' . $e->getMessage());
             return false;
         }
         // Add organization info
         if (!empty($metaArray['OrganizationName']) && !empty($metaArray['OrganizationDisplayName']) && !empty($metaArray['OrganizationURL'])) {
             $metaBuilder->addOrganizationInfo(array('OrganizationName' => $metaArray['OrganizationName'], 'OrganizationDisplayName' => $metaArray['OrganizationDisplayName'], 'OrganizationURL' => $metaArray['OrganizationURL']));
         }
         // Add contact info
         if (!empty($metaArray['contact'])) {
             $metaBuilder->addContact('technical', $metaArray['contact']);
         }
         switch ($type) {
             case self::XML:
                 return $metaBuilder->getEntityDescriptor();
             case self::XMLREADABLE:
                 return $metaBuilder->getEntityDescriptorText();
             case self::PHPARRAY:
                 return $metaArray;
             case self::FLATFILE:
             default:
                 return $metaFlat;
         }
     } catch (Exception $exception) {
         $session = SimpleSAML_Session::getInstance();
         SimpleSAML_Utilities::fatalError($session->getTrackID(), 'JANUS - Metadatageneration', $exception);
         return false;
     }
 }