diff --git a/templates/default/en/metadata-converter.php b/templates/default/en/metadata-converter.php new file mode 100644 index 0000000000000000000000000000000000000000..efc809a5351caeb598d3bba836e530a42451021f --- /dev/null +++ b/templates/default/en/metadata-converter.php @@ -0,0 +1,43 @@ +<?php +$this->data['header'] = 'Metadata parser'; +$this->includeAtTemplateBase('includes/header.php'); +?> + +<div id="content"> + +<h2>Metadata parser</h2> + +<form action="?" method="post"> + +<p>XML metadata</p> +<p> +<textarea rows="20" cols="75" name="xmldata"><?php echo htmlspecialchars($this->data['xmldata']); ?></textarea> +</p> +<p> +<input type="submit" value="Parse" /> +</p> +</form> + +<?php + +$output = $this->data['output']; + +if($output !== NULL) { + + echo('<h2>Converted metadata</h2>' . "\n"); + + foreach($output as $type => $text) { + if($text === '') { + continue; + } + + echo('<h3>' . htmlspecialchars($type) . '</h3>' . "\n"); + echo('<pre>' . htmlspecialchars($text) . '</pre>' . "\n"); + } +} + +?> + +<?php +$this->includeAtTemplateBase('includes/footer.php'); +?> \ No newline at end of file diff --git a/www/admin/metadata-converter.php b/www/admin/metadata-converter.php new file mode 100644 index 0000000000000000000000000000000000000000..ff882012ec88ccc7eb5454f283b023b0bab1a9ef --- /dev/null +++ b/www/admin/metadata-converter.php @@ -0,0 +1,70 @@ +<?php + +require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . '../_include.php'); + +require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/Configuration.php'); +require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/Metadata/SAMLParser.php'); +require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/XHTML/Template.php'); +require_once((isset($SIMPLESAML_INCPREFIX)?$SIMPLESAML_INCPREFIX:'') . 'SimpleSAML/Utilities.php'); + +try { + + $config = SimpleSAML_Configuration::getInstance(); + + if(array_key_exists('xmldata', $_POST)) { + $xmldata = $_POST['xmldata']; + + $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsString($xmldata); + + /* Get all metadata for the entities. */ + foreach($entities as &$entity) { + $entity = array( + 'shib13-sp-remote' => $entity->getMetadata1xSP(), + 'shib13-idp-remote' => $entity->getMetadata1xIdP(), + 'saml20-sp-remote' => $entity->getMetadata20SP(), + 'saml20-idp-remote' => $entity->getMetadata20IdP(), + ); + + } + + /* Transpose from $entities[entityid][type] to $output[type][entityid]. */ + $output = SimpleSAML_Utilities::transposeArray($entities); + + /* Merge all metadata of each type to a single string which should be + * added to the corresponding file. + */ + foreach($output as $type => &$entities) { + + $text = ''; + + foreach($entities as $entityId => $entityMetadata) { + + if($entityMetadata === NULL) { + continue; + } + + $text .= '$metadata[\'' . addslashes($entityId) . '\'] = ' . + var_export($entityMetadata, TRUE) . ';' . "\n"; + } + + $entities = $text; + } + + } else { + $xmldata = ''; + $output = array(); + } + + + $template = new SimpleSAML_XHTML_Template($config, 'metadata-converter.php'); + + $template->data['xmldata'] = $xmldata; + $template->data['output'] = $output; + + $template->show(); + +} catch(Exception $exception) { + SimpleSAML_Utilities::fatalError('', 'METADATA_PARSER', $exception); +} + +?> \ No newline at end of file diff --git a/www/index.php b/www/index.php index c4bccb2a0e469bebf97c4bc1291e8b01279b199e..731b242593978628f4a53fc512d3a314fef9c81d 100644 --- a/www/index.php +++ b/www/index.php @@ -81,9 +81,13 @@ if ($config->getValue('enable.shib13-idp') === true) $linksmeta[] = array( 'href' => 'shib13/idp/metadata.php', 'text' => 'Hosted Shibboleth 1.3 Identity Provider Metadata (automatically generated)'); - +$linksmeta[] = array( + 'href' => 'admin/metadata-converter.php', + 'text' => 'XML to simpleSAMLphp metadata converter', + ); + $linksdoc = array();