diff --git a/lib/SAML2/XML/md/Extensions.php b/lib/SAML2/XML/md/Extensions.php index 2f5e9ae915bfe967ec8c5f32ed760220e3da0fcf..0db18137945e40f2216bb49153711cc7df3ef961 100644 --- a/lib/SAML2/XML/md/Extensions.php +++ b/lib/SAML2/XML/md/Extensions.php @@ -22,6 +22,8 @@ class SAML2_XML_md_Extensions { $ret[] = new SAML2_XML_shibmd_Scope($node); } elseif ($node->namespaceURI === SAML2_XML_mdattr_EntityAttributes::NS && $node->localName === 'EntityAttributes') { $ret[] = new SAML2_XML_mdattr_EntityAttributes($node); + } elseif ($node->namespaceURL === SAML2_XML_mdrpi_Common::NS_MDRPI && $node->localName === 'PublicationInfo') { + $ret[] = new SAML2_XML_mdrpi_PublicationInfo($node); } else { $ret[] = new SAML2_XML_Chunk($node); } diff --git a/lib/SAML2/XML/mdrpi/Common.php b/lib/SAML2/XML/mdrpi/Common.php new file mode 100644 index 0000000000000000000000000000000000000000..f6a4dc3d3976955ec9f5609a28098e87e6affb03 --- /dev/null +++ b/lib/SAML2/XML/mdrpi/Common.php @@ -0,0 +1,14 @@ +<?php + +/** + * Common definitions for the mdrpi metadata extension. + * + * @link: http://docs.oasis-open.org/security/saml/Post2.0/saml-metadata-rpi/v1.0/saml-metadata-rpi-v1.0.pdf + * @package simpleSAMLphp + * @version $Id$ + */ +class SAML2_XML_mdrpi_Common { + + const NS_MDRPI = 'urn:oasis:names:tc:SAML:metadata:rpi'; + +} diff --git a/lib/SAML2/XML/mdrpi/PublicationInfo.php b/lib/SAML2/XML/mdrpi/PublicationInfo.php new file mode 100644 index 0000000000000000000000000000000000000000..3e1caeea8d25b89d93b79622c82f717d3678fd4d --- /dev/null +++ b/lib/SAML2/XML/mdrpi/PublicationInfo.php @@ -0,0 +1,103 @@ +<?php + +/** + * Class for handling the mdrpi:PublicationInfo element. + * + * @link: http://docs.oasis-open.org/security/saml/Post2.0/saml-metadata-rpi/v1.0/saml-metadata-rpi-v1.0.pdf + * @package simpleSAMLphp + * @version $Id$ + */ +class SAML2_XML_mdrpi_PublicationInfo { + + /** + * The identifier of the metadata publisher. + * + * @var string + */ + public $publisher; + + /** + * The creation timestamp for the metadata, as a UNIX timestamp. + * + * @var int|NULL + */ + public $creationInstant; + + /** + * Identifier for this metadata publication. + * + * @var string|NULL + */ + public $publicationId; + + /** + * Link to usage policy for this metadata. + * + * This is an associative array with language=>URL. + * + * @var array + */ + public $UsagePolicy = array(); + + + /** + * Create/parse a mdrpi:PublicationInfo element. + * + * @param DOMElement|NULL $xml The XML element we should load. + */ + public function __construct(DOMElement $xml = NULL) { + + if ($xml === NULL) { + return; + } + + if (!$xml->hasAttribute('publisher')) { + throw new Exception('Missing required attribute "publisher" in mdrpi:PublicationInfo element.'); + } + $this->publisher = $xml->getAttribute('publisher'); + + if ($xml->hasAttribute('creationInstant')) { + $this->creationInstant = SimpleSAML_Utilities::parseSAML2Time($xml->getAttribute('creationInstant')); + } + + if ($xml->hasAttribute('publicationId')) { + $this->publicationId = $xml->getAttribute('publicationId'); + } + + $query = './*[local-name()="UsagePolicy" and namespace-uri()="' . SAML2_XML_mdrpi_Common::NS_MDRPI . '"]'; + $this->UsagePolicy = SAML2_Utils::extractLocalizedStrings($xml, $query); + } + + + /** + * Convert this element to XML. + * + * @param DOMElement $parent The element we should append to. + */ + public function toXML(DOMElement $parent) { + assert('is_string($this->publisher)'); + assert('is_int($this->creationInstant) || is_null($this->creationInstant)'); + assert('is_string($this->publicationId) || is_null($this->publicationId)'); + assert('is_array($this->UsagePolicy)'); + + $doc = $parent->ownerDocument; + + $e = $doc->createElementNS(SAML2_XML_mdrpi_Common::NS_MDRPI, 'mdrpi:PublicationInfo'); + $parent->appendChild($e); + + $e->setAttribute('publisher', $this->publisher); + + if ($this->creationInstant !== NULL) { + $e->setAttribute('creationInstant', gmdate('Y-m-d\TH:i:s\Z', $this->creationInstant)); + } + + if ($this->publicationId !== NULL) { + $e->setAttribute('publicationId', $this->publicationId); + } + + SAML2_Utils::addStrings($e, SAML2_XML_mdrpi_Common::NS_MDRPI, 'mdrpi:UsagePolicy', TRUE, $this->UsagePolicy); + + return $e; + } + +}