diff --git a/.gitignore b/.gitignore index 71c73837aed5d58ab42ca1d5400002e2b7a88e7e..0a9f2384f360c630e8c61adcf8b4d13ec89d4b17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .gitignore log config -metadata +./metadata cert !config/.gitkeep diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php index ad725e8b22bb8aeffbbef9a926807ddba6d165af..2786fff5ae6a9a6b630485a8f21a9af401a9eeeb 100644 --- a/lib/SimpleSAML/Metadata/SAMLParser.php +++ b/lib/SimpleSAML/Metadata/SAMLParser.php @@ -124,6 +124,11 @@ class SimpleSAML_Metadata_SAMLParser */ private $entityAttributes; + /** + * An associative array of attributes from the RegistrationInfo element. + * @var array + */ + private $registrationInfo; /** * @var array @@ -180,6 +185,7 @@ class SimpleSAML_Metadata_SAMLParser $this->scopes = $ext['scope']; $this->tags = $ext['tags']; $this->entityAttributes = $ext['EntityAttributes']; + $this->registrationInfo = $ext['RegistrationInfo']; // look over the RoleDescriptors foreach ($entityElement->RoleDescriptor as $child) { @@ -486,6 +492,11 @@ class SimpleSAML_Metadata_SAMLParser $metadata['tags'] = $tags; } + + if (!empty($this->registrationInfo)) { + $metadata['RegistrationInfo'] = $this->registrationInfo; + } + if (!empty($this->entityAttributes)) { $metadata['EntityAttributes'] = $this->entityAttributes; @@ -993,6 +1004,7 @@ class SimpleSAML_Metadata_SAMLParser 'scope' => array(), 'tags' => array(), 'EntityAttributes' => array(), + 'RegistrationInfo' => array(), 'UIInfo' => array(), 'DiscoHints' => array(), ); @@ -1006,6 +1018,9 @@ class SimpleSAML_Metadata_SAMLParser // Entity Attributes are only allowed at entity level extensions and not at RoleDescriptor level if ($element instanceof SAML2_XML_md_EntityDescriptor) { + if ($e instanceof SAML2_XML_mdrpi_RegistrationInfo) { + $ret['RegistrationInfo']['registrationAuthority'] = $e->registrationAuthority; + } if ($e instanceof SAML2_XML_mdattr_EntityAttributes && !empty($e->children)) { foreach ($e->children as $attr) { // only saml:Attribute are currently supported here. The specifications also allows diff --git a/tests/lib/SimpleSAML/Metadata/SAMLBuilderTest.php b/tests/lib/SimpleSAML/Metadata/SAMLBuilderTest.php index 48caa5eafd6f0d62c86148f35fe0b16f95f599b9..8f0fdddb375468253e6fa4e1ed57d26a188a81d4 100644 --- a/tests/lib/SimpleSAML/Metadata/SAMLBuilderTest.php +++ b/tests/lib/SimpleSAML/Metadata/SAMLBuilderTest.php @@ -8,7 +8,7 @@ class SimpleSAML_Metadata_SAMLBuilderTest extends PHPUnit_Framework_TestCase { /** - * Test the requeste attributes are valued correctly. + * Test the requested attributes are valued correctly. */ public function testAttributes() { diff --git a/tests/lib/SimpleSAML/Metadata/SAMLParserTest.php b/tests/lib/SimpleSAML/Metadata/SAMLParserTest.php new file mode 100644 index 0000000000000000000000000000000000000000..95874317cf32753b2121acb813a9aedfe3c731e8 --- /dev/null +++ b/tests/lib/SimpleSAML/Metadata/SAMLParserTest.php @@ -0,0 +1,39 @@ +<?php +namespace SimpleSAML\Metadata; + +/** + * Test SAML parsing + */ +class SAMLParserTest extends \PHPUnit_Framework_TestCase +{ + + /** + * Test Registration Info is parsed + */ + public function testRegistrationInfo() + { + $expected = array( + 'registrationAuthority' => 'https://incommon.org', + ); + + $document = \SAML2_DOMDocumentFactory::fromString( + <<<XML +<EntityDescriptor entityID="theEntityID" + xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:mdrpi="urn:oasis:names:tc:SAML:metadata:rpi"> + <Extensions> + <mdrpi:RegistrationInfo registrationAuthority="https://incommon.org"/> + </Extensions> + <SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"> + </SPSSODescriptor> +</EntityDescriptor> +XML + ); + + + $entities = \SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement($document->documentElement); + $this->assertArrayHasKey('theEntityID', $entities); + // RegistrationInfo is accessible in the SP or IDP metadata accessors + $this->assertEquals($expected, $entities['theEntityID']->getMetadata20SP()['RegistrationInfo']); + + } +}