From b572acb4a3cf937f7a4698170b873e103d9657c1 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Thu, 6 Mar 2008 14:11:33 +0000 Subject: [PATCH] Added SAML2 metadata to simpleSAMLphp metadata converter page. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@364 44740490-163a-0410-bde0-09ae8108e29a --- templates/default/en/metadata-converter.php | 43 +++++++++++++ www/admin/metadata-converter.php | 70 +++++++++++++++++++++ www/index.php | 6 +- 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 templates/default/en/metadata-converter.php create mode 100644 www/admin/metadata-converter.php diff --git a/templates/default/en/metadata-converter.php b/templates/default/en/metadata-converter.php new file mode 100644 index 000000000..efc809a53 --- /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 000000000..ff882012e --- /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 c4bccb2a0..731b24259 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(); -- GitLab