示例#1
0
 /**
  * Add this endpoint to an XML element.
  *
  * @param DOMElement $parent  The element we should append this endpoint to.
  * @param string $name  The name of the element we should create.
  */
 public function toXML(DOMElement $parent, $name)
 {
     assert('is_string($name)');
     assert('is_int($this->index)');
     assert('is_null($this->isDefault) || is_bool($this->isDefault)');
     $e = parent::toXML($parent, $name);
     $e->setAttribute('index', (string) $this->index);
     if ($this->isDefault === TRUE) {
         $e->setAttribute('isDefault', 'true');
     } elseif ($this->isDefault === FALSE) {
         $e->setAttribute('isDefault', 'false');
     }
     return $e;
 }
示例#2
0
    public function testUnmarshalling()
    {
        $mdNamespace = SAML2_Const::NS_MD;
        $document = SAML2_DOMDocumentFactory::fromString(<<<XML
<md:Test xmlns:md="{$mdNamespace}" Binding="urn:something" Location="https://whatever/" xmlns:test="urn:test" test:attr="value" />
XML
);
        $endpointType = new SAML2_XML_md_EndpointType($document->firstChild);
        $this->assertEquals(TRUE, $endpointType->hasAttributeNS('urn:test', 'attr'));
        $this->assertEquals('value', $endpointType->getAttributeNS('urn:test', 'attr'));
        $this->assertEquals(FALSE, $endpointType->hasAttributeNS('urn:test', 'invalid'));
        $this->assertEquals('', $endpointType->getAttributeNS('urn:test', 'invalid'));
        $endpointType->removeAttributeNS('urn:test', 'attr');
        $this->assertEquals(FALSE, $endpointType->hasAttributeNS('urn:test', 'attr'));
        $this->assertEquals('', $endpointType->getAttributeNS('urn:test', 'attr'));
        $endpointType->setAttributeNS('urn:test2', 'test2:attr2', 'value2');
        $this->assertEquals('value2', $endpointType->getAttributeNS('urn:test2', 'attr2'));
        $document->loadXML('<root />');
        $endpointTypeElement = $endpointType->toXML($document->firstChild, 'md:Test');
        $endpointTypeElements = SAML2_Utils::xpQuery($endpointTypeElement, '/root/saml_metadata:Test');
        $this->assertCount(1, $endpointTypeElements);
        $endpointTypeElement = $endpointTypeElements[0];
        $this->assertEquals('value2', $endpointTypeElement->getAttributeNS('urn:test2', 'attr2'));
        $this->assertEquals(FALSE, $endpointTypeElement->hasAttributeNS('urn:test', 'attr'));
    }
 /**
  * Add endpoint list to metadata.
  *
  * @param array $endpoints  The endpoints.
  * @param bool $indexed  Whether the endpoints should be indexed.
  * @return array  Array of endpoint objects.
  */
 private static function createEndpoints(array $endpoints, $indexed)
 {
     assert('is_bool($indexed)');
     $ret = array();
     foreach ($endpoints as &$ep) {
         if ($indexed) {
             $t = new SAML2_XML_md_IndexedEndpointType();
         } else {
             $t = new SAML2_XML_md_EndpointType();
         }
         $t->Binding = $ep['Binding'];
         $t->Location = $ep['Location'];
         if (isset($ep['ResponseLocation'])) {
             $t->ResponseLocation = $ep['ResponseLocation'];
         }
         if (isset($ep['hoksso:ProtocolBinding'])) {
             $t->setAttributeNS(SAML2_Const::NS_HOK, 'hoksso:ProtocolBinding', SAML2_Const::BINDING_HTTP_REDIRECT);
         }
         if ($indexed) {
             if (!isset($ep['index'])) {
                 /* Find the maximum index. */
                 $maxIndex = -1;
                 foreach ($endpoints as $ep) {
                     if (!isset($ep['index'])) {
                         continue;
                     }
                     if ($ep['index'] > $maxIndex) {
                         $maxIndex = $ep['index'];
                     }
                 }
                 $ep['index'] = $maxIndex + 1;
             }
             $t->index = $ep['index'];
         }
         $ret[] = $t;
     }
     return $ret;
 }