예제 #1
0
 public function testMarshalling()
 {
     $indexedEndpointType = new IndexedEndpointType();
     $indexedEndpointType->Binding = 'TestBinding';
     $indexedEndpointType->Location = 'TestLocation';
     $indexedEndpointType->index = 42;
     $indexedEndpointType->isDefault = false;
     $document = DOMDocumentFactory::fromString('<root />');
     $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test');
     $indexedEndpointElements = Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test');
     $this->assertCount(1, $indexedEndpointElements);
     $indexedEndpointElement = $indexedEndpointElements[0];
     $this->assertEquals('TestBinding', $indexedEndpointElement->getAttribute('Binding'));
     $this->assertEquals('TestLocation', $indexedEndpointElement->getAttribute('Location'));
     $this->assertEquals('42', $indexedEndpointElement->getAttribute('index'));
     $this->assertEquals('false', $indexedEndpointElement->getAttribute('isDefault'));
     $indexedEndpointType->isDefault = true;
     $document->loadXML('<root />');
     $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test');
     $indexedEndpointTypeElement = Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test');
     $this->assertCount(1, $indexedEndpointTypeElement);
     $this->assertEquals('true', $indexedEndpointTypeElement[0]->getAttribute('isDefault'));
     $indexedEndpointType->isDefault = null;
     $document->loadXML('<root />');
     $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test');
     $indexedEndpointTypeElement = Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test');
     $this->assertCount(1, $indexedEndpointTypeElement);
     $this->assertTrue(!$indexedEndpointTypeElement[0]->hasAttribute('isDefault'));
 }
예제 #2
0
 /**
  * Constructor for SAML 2 logout request messages.
  *
  * @param \DOMElement|null $xml The input message.
  * @throws \Exception
  */
 public function __construct(\DOMElement $xml = null)
 {
     parent::__construct('LogoutRequest', $xml);
     $this->sessionIndexes = array();
     if ($xml === null) {
         return;
     }
     if ($xml->hasAttribute('NotOnOrAfter')) {
         $this->notOnOrAfter = Utils::xsDateTimeToTimestamp($xml->getAttribute('NotOnOrAfter'));
     }
     $nameId = Utils::xpQuery($xml, './saml_assertion:NameID | ./saml_assertion:EncryptedID/xenc:EncryptedData');
     if (empty($nameId)) {
         throw new \Exception('Missing <saml:NameID> or <saml:EncryptedID> in <samlp:LogoutRequest>.');
     } elseif (count($nameId) > 1) {
         throw new \Exception('More than one <saml:NameID> or <saml:EncryptedD> in <samlp:LogoutRequest>.');
     }
     $nameId = $nameId[0];
     if ($nameId->localName === 'EncryptedData') {
         /* The NameID element is encrypted. */
         $this->encryptedNameId = $nameId;
     } else {
         $this->nameId = Utils::parseNameId($nameId);
     }
     $sessionIndexes = Utils::xpQuery($xml, './saml_protocol:SessionIndex');
     foreach ($sessionIndexes as $sessionIndex) {
         $this->sessionIndexes[] = trim($sessionIndex->textContent);
     }
 }
예제 #3
0
    public function testUnmarshalling()
    {
        $mdNamespace = Constants::NS_MD;
        $document = DOMDocumentFactory::fromString(<<<XML
<md:Test xmlns:md="{$mdNamespace}" Binding="urn:something" Location="https://whatever/" xmlns:test="urn:test" test:attr="value" />
XML
);
        $endpointType = new 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 = 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'));
    }
예제 #4
0
 /**
  * Initialize an EntitiesDescriptor.
  *
  * @param \DOMElement|null $xml The XML element we should load.
  */
 public function __construct(\DOMElement $xml = null)
 {
     parent::__construct($xml);
     if ($xml === null) {
         return;
     }
     if ($xml->hasAttribute('ID')) {
         $this->ID = $xml->getAttribute('ID');
     }
     if ($xml->hasAttribute('validUntil')) {
         $this->validUntil = Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'));
     }
     if ($xml->hasAttribute('cacheDuration')) {
         $this->cacheDuration = $xml->getAttribute('cacheDuration');
     }
     if ($xml->hasAttribute('Name')) {
         $this->Name = $xml->getAttribute('Name');
     }
     $this->Extensions = Extensions::getList($xml);
     foreach (Utils::xpQuery($xml, './saml_metadata:EntityDescriptor|./saml_metadata:EntitiesDescriptor') as $node) {
         if ($node->localName === 'EntityDescriptor') {
             $this->children[] = new EntityDescriptor($node);
         } else {
             $this->children[] = new EntitiesDescriptor($node);
         }
     }
 }
예제 #5
0
 /**
  * Get a list of Extensions in the given element.
  *
  * @param  \DOMElement $parent The element that may contain the samlp:Extensions element.
  * @return array      Array of extensions.
  */
 public static function getList(\DOMElement $parent)
 {
     $ret = array();
     foreach (Utils::xpQuery($parent, './saml_protocol:Extensions/*') as $node) {
         $ret[] = new Chunk($node);
     }
     return $ret;
 }
예제 #6
0
 /**
  * Create a DiscoHints element.
  *
  * @param \DOMElement|null $xml The XML element we should load.
  */
 public function __construct(\DOMElement $xml = null)
 {
     if ($xml === null) {
         return;
     }
     $this->IPHint = Utils::extractStrings($xml, self::NS, 'IPHint');
     $this->DomainHint = Utils::extractStrings($xml, self::NS, 'DomainHint');
     $this->GeolocationHint = Utils::extractStrings($xml, self::NS, 'GeolocationHint');
     foreach (Utils::xpQuery($xml, "./*[namespace-uri()!='" . self::NS . "']") as $node) {
         $this->children[] = new Chunk($node);
     }
 }
예제 #7
0
 /**
  * Test that signatures no longer validate if the value has been tampered with.
  */
 public function testValidateWithValueTampering()
 {
     // Test modification of SignatureValue.
     $signedMockElementCopy = Utils::copyElement($this->signedMockElement);
     $signedMockElementCopy->ownerDocument->appendChild($signedMockElementCopy);
     $digestValueElements = Utils::xpQuery($signedMockElementCopy, '/root/ds:Signature/ds:SignatureValue');
     $this->assertCount(1, $digestValueElements);
     $digestValueElements[0]->firstChild->data = 'invalid';
     $tmp = new SignedElementHelperMock($signedMockElementCopy);
     $this->setExpectedException('Exception', 'Unable to validate Signature');
     $tmp->validate(CertificatesMock::getPublicKey());
 }
예제 #8
0
 /**
  * Constructor for SAML 2 encrypted assertions.
  *
  * @param \DOMElement|null $xml The encrypted assertion XML element.
  * @throws \Exception
  */
 public function __construct(\DOMElement $xml = null)
 {
     if ($xml === null) {
         return;
     }
     $data = Utils::xpQuery($xml, './xenc:EncryptedData');
     if (count($data) === 0) {
         throw new \Exception('Missing encrypted data in <saml:EncryptedAssertion>.');
     } elseif (count($data) > 1) {
         throw new \Exception('More than one encrypted data element in <saml:EncryptedAssertion>.');
     }
     $this->encryptedData = $data[0];
 }
예제 #9
0
 /**
  * Test creating a basic Keywords element.
  */
 public function testMarshalling()
 {
     $keywords = new Keywords();
     $keywords->lang = "en";
     $keywords->Keywords = array("KLM", "royal", "Dutch", "air lines");
     $document = DOMDocumentFactory::fromString('<root />');
     $xml = $keywords->toXML($document->firstChild);
     $keywordElements = Utils::xpQuery($xml, '/root/*[local-name()=\'Keywords\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:ui\']');
     $this->assertCount(1, $keywordElements);
     $keywordElement = $keywordElements[0];
     $this->assertEquals("KLM royal Dutch air+lines", $keywordElement->textContent);
     $this->assertEquals("en", $keywordElement->getAttribute('xml:lang'));
 }
 public function testMarshalling()
 {
     $document = DOMDocumentFactory::fromString('<root/>');
     $additionalMetadataLocation = new AdditionalMetadataLocation();
     $additionalMetadataLocation->namespace = 'NamespaceAttribute';
     $additionalMetadataLocation->location = 'TheLocation';
     $additionalMetadataLocationElement = $additionalMetadataLocation->toXML($document->firstChild);
     $additionalMetadataLocationElements = Utils::xpQuery($additionalMetadataLocationElement, '/root/saml_metadata:AdditionalMetadataLocation');
     $this->assertCount(1, $additionalMetadataLocationElements);
     $additionalMetadataLocationElement = $additionalMetadataLocationElements[0];
     $this->assertEquals('TheLocation', $additionalMetadataLocationElement->textContent);
     $this->assertEquals('NamespaceAttribute', $additionalMetadataLocationElement->getAttribute("namespace"));
 }
예제 #11
0
 /**
  * Create a EntityAttributes element.
  *
  * @param \DOMElement|null $xml The XML element we should load.
  */
 public function __construct(\DOMElement $xml = null)
 {
     if ($xml === null) {
         return;
     }
     foreach (Utils::xpQuery($xml, './saml_assertion:Attribute|./saml_assertion:Assertion') as $node) {
         if ($node->localName === 'Attribute') {
             $this->children[] = new Attribute($node);
         } else {
             $this->children[] = new Chunk($node);
         }
     }
 }
예제 #12
0
 /**
  * Marshalling a scope which is in regexp form.
  */
 public function testMarshallingRegexp()
 {
     $scope = new Scope();
     $scope->scope = "^(.*\\.)?example\\.edu\$";
     $scope->regexp = TRUE;
     $document = DOMDocumentFactory::fromString('<root />');
     $scopeElement = $scope->toXML($document->firstChild);
     $scopeElements = Utils::xpQuery($scopeElement, '/root/shibmd:Scope');
     $this->assertCount(1, $scopeElements);
     $scopeElement = $scopeElements[0];
     $this->assertEquals('^(.*\\.)?example\\.edu$', $scopeElement->nodeValue);
     $this->assertEquals('urn:mace:shibboleth:metadata:1.0', $scopeElement->namespaceURI);
     $this->assertEquals('true', $scopeElement->getAttribute('regexp'));
 }
예제 #13
0
 public function testUnmarshalling()
 {
     $authnRequest = new AuthnRequest();
     $authnRequest->setRequestedAuthnContext(array('AuthnContextClassRef' => array('accr1', 'accr2'), 'Comparison' => 'better'));
     $authnRequestElement = $authnRequest->toUnsignedXML();
     $requestedAuthnContextElements = Utils::xpQuery($authnRequestElement, './saml_protocol:RequestedAuthnContext');
     $this->assertCount(1, $requestedAuthnContextElements);
     $requestedAuthnConextElement = $requestedAuthnContextElements[0];
     $this->assertEquals('better', $requestedAuthnConextElement->getAttribute("Comparison"));
     $authnContextClassRefElements = Utils::xpQuery($requestedAuthnConextElement, './saml_assertion:AuthnContextClassRef');
     $this->assertCount(2, $authnContextClassRefElements);
     $this->assertEquals('accr1', $authnContextClassRefElements[0]->textContent);
     $this->assertEquals('accr2', $authnContextClassRefElements[1]->textContent);
 }
예제 #14
0
 /**
  * Initialize a SPSSODescriptor.
  *
  * @param \DOMElement|null $xml The XML element we should load.
  */
 public function __construct(\DOMElement $xml = null)
 {
     parent::__construct('md:SPSSODescriptor', $xml);
     if ($xml === null) {
         return;
     }
     $this->AuthnRequestsSigned = Utils::parseBoolean($xml, 'AuthnRequestsSigned', null);
     $this->WantAssertionsSigned = Utils::parseBoolean($xml, 'WantAssertionsSigned', null);
     foreach (Utils::xpQuery($xml, './saml_metadata:AssertionConsumerService') as $ep) {
         $this->AssertionConsumerService[] = new IndexedEndpointType($ep);
     }
     foreach (Utils::xpQuery($xml, './saml_metadata:AttributeConsumingService') as $acs) {
         $this->AttributeConsumingService[] = new AttributeConsumingService($acs);
     }
 }
예제 #15
0
 public function testMarshalling()
 {
     $attribute = new Attribute();
     $attribute->Name = 'TheName';
     $attribute->NameFormat = 'TheNameFormat';
     $attribute->FriendlyName = 'TheFriendlyName';
     $attribute->AttributeValue = array(new AttributeValue('FirstValue'), new AttributeValue('SecondValue'));
     $document = DOMDocumentFactory::fromString('<root />');
     $attributeElement = $attribute->toXML($document->firstChild);
     $attributeElements = Utils::xpQuery($attributeElement, '/root/saml_assertion:Attribute');
     $this->assertCount(1, $attributeElements);
     $attributeElement = $attributeElements[0];
     $this->assertEquals('TheName', $attributeElement->getAttribute('Name'));
     $this->assertEquals('TheNameFormat', $attributeElement->getAttribute('NameFormat'));
     $this->assertEquals('TheFriendlyName', $attributeElement->getAttribute('FriendlyName'));
 }
예제 #16
0
 public function testMarshalling()
 {
     $subjectConfirmation = new SubjectConfirmation();
     $subjectConfirmation->Method = 'SomeMethod';
     $subjectConfirmation->NameID = new NameID();
     $subjectConfirmation->NameID->value = 'SomeNameIDValue';
     $subjectConfirmation->SubjectConfirmationData = new SubjectConfirmationData();
     $document = DOMDocumentFactory::fromString('<root />');
     $subjectConfirmationElement = $subjectConfirmation->toXML($document->firstChild);
     $subjectConfirmationElements = Utils::xpQuery($subjectConfirmationElement, '//saml_assertion:SubjectConfirmation');
     $this->assertCount(1, $subjectConfirmationElements);
     $subjectConfirmationElement = $subjectConfirmationElements[0];
     $this->assertEquals('SomeMethod', $subjectConfirmationElement->getAttribute("Method"));
     $this->assertCount(1, Utils::xpQuery($subjectConfirmationElement, "./saml_assertion:NameID"));
     $this->assertCount(1, Utils::xpQuery($subjectConfirmationElement, "./saml_assertion:SubjectConfirmationData"));
 }
예제 #17
0
 /**
  * Test creating a basic Logo element.
  */
 public function testMarshalling()
 {
     $logo = new Logo();
     $logo->lang = "nl";
     $logo->width = 300;
     $logo->height = 200;
     $logo->url = "https://static.example.org/images/logos/logo300x200.png";
     $document = DOMDocumentFactory::fromString('<root />');
     $xml = $logo->toXML($document->firstChild);
     $logoElements = Utils::xpQuery($xml, '/root/*[local-name()=\'Logo\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:ui\']');
     $this->assertCount(1, $logoElements);
     $logoElement = $logoElements[0];
     $this->assertEquals("https://static.example.org/images/logos/logo300x200.png", $logoElement->textContent);
     $this->assertEquals("nl", $logoElement->getAttribute("xml:lang"));
     $this->assertEquals(300, $logoElement->getAttribute("width"));
     $this->assertEquals(200, $logoElement->getAttribute("height"));
 }
예제 #18
0
 /**
  * Initialize an IDPSSODescriptor.
  *
  * @param \DOMElement|null $xml The XML element we should load.
  * @throws \Exception
  */
 public function __construct(\DOMElement $xml = null)
 {
     parent::__construct('md:AuthnAuthorityDescriptor', $xml);
     if ($xml === null) {
         return;
     }
     foreach (Utils::xpQuery($xml, './saml_metadata:AuthnQueryService') as $ep) {
         $this->AuthnQueryService[] = new EndpointType($ep);
     }
     if (empty($this->AuthnQueryService)) {
         throw new \Exception('Must have at least one AuthnQueryService in AuthnAuthorityDescriptor.');
     }
     foreach (Utils::xpQuery($xml, './saml_metadata:AssertionIDRequestService') as $ep) {
         $this->AssertionIDRequestService[] = new EndpointType($ep);
     }
     $this->NameIDFormat = Utils::extractStrings($xml, Constants::NS_MD, 'NameIDFormat');
 }
예제 #19
0
 /**
  * Initialize a SSODescriptor.
  *
  * @param string          $elementName The name of this element.
  * @param \DOMElement|null $xml         The XML element we should load.
  */
 protected function __construct($elementName, \DOMElement $xml = null)
 {
     assert('is_string($elementName)');
     parent::__construct($elementName, $xml);
     if ($xml === null) {
         return;
     }
     foreach (Utils::xpQuery($xml, './saml_metadata:ArtifactResolutionService') as $ep) {
         $this->ArtifactResolutionService[] = new IndexedEndpointType($ep);
     }
     foreach (Utils::xpQuery($xml, './saml_metadata:SingleLogoutService') as $ep) {
         $this->SingleLogoutService[] = new EndpointType($ep);
     }
     foreach (Utils::xpQuery($xml, './saml_metadata:ManageNameIDService') as $ep) {
         $this->ManageNameIDService[] = new EndpointType($ep);
     }
     $this->NameIDFormat = Utils::extractStrings($xml, Constants::NS_MD, 'NameIDFormat');
 }
예제 #20
0
 public function testMarshalling()
 {
     $nameId = new NameID();
     $nameId->NameQualifier = 'TheNameQualifier';
     $nameId->SPNameQualifier = 'TheSPNameQualifier';
     $nameId->Format = 'TheFormat';
     $nameId->SPProvidedID = 'TheSPProvidedID';
     $nameId->value = 'TheNameIDValue';
     $nameIdElement = $nameId->toXML();
     $nameIdElements = Utils::xpQuery($nameIdElement, '/saml_assertion:NameID');
     $this->assertCount(1, $nameIdElements);
     $nameIdElement = $nameIdElements[0];
     $this->assertEquals('TheNameQualifier', $nameIdElement->getAttribute("NameQualifier"));
     $this->assertEquals('TheSPNameQualifier', $nameIdElement->getAttribute("SPNameQualifier"));
     $this->assertEquals('TheFormat', $nameIdElement->getAttribute("Format"));
     $this->assertEquals('TheSPProvidedID', $nameIdElement->getAttribute("SPProvidedID"));
     $this->assertEquals('TheNameIDValue', $nameIdElement->textContent);
 }
예제 #21
0
 /**
  * Initialize an KeyDescriptor.
  *
  * @param \DOMElement|null $xml The XML element we should load.
  * @throws \Exception
  */
 public function __construct(\DOMElement $xml = null)
 {
     if ($xml === null) {
         return;
     }
     if ($xml->hasAttribute('use')) {
         $this->use = $xml->getAttribute('use');
     }
     $keyInfo = Utils::xpQuery($xml, './ds:KeyInfo');
     if (count($keyInfo) > 1) {
         throw new \Exception('More than one ds:KeyInfo in the KeyDescriptor.');
     } elseif (empty($keyInfo)) {
         throw new \Exception('No ds:KeyInfo in the KeyDescriptor.');
     }
     $this->KeyInfo = new KeyInfo($keyInfo[0]);
     foreach (Utils::xpQuery($xml, './saml_metadata:EncryptionMethod') as $em) {
         $this->EncryptionMethod[] = new Chunk($em);
     }
 }
예제 #22
0
 /**
  * Initialize / parse an AttributeConsumingService.
  *
  * @param \DOMElement|null $xml The XML element we should load.
  * @throws \Exception
  */
 public function __construct(\DOMElement $xml = null)
 {
     if ($xml === null) {
         return;
     }
     if (!$xml->hasAttribute('index')) {
         throw new \Exception('Missing index on AttributeConsumingService.');
     }
     $this->index = (int) $xml->getAttribute('index');
     $this->isDefault = Utils::parseBoolean($xml, 'isDefault', null);
     $this->ServiceName = Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'ServiceName');
     if (empty($this->ServiceName)) {
         throw new \Exception('Missing ServiceName in AttributeConsumingService.');
     }
     $this->ServiceDescription = Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'ServiceDescription');
     foreach (Utils::xpQuery($xml, './saml_metadata:RequestedAttribute') as $ra) {
         $this->RequestedAttribute[] = new RequestedAttribute($ra);
     }
 }
예제 #23
0
 public function testMarshalling()
 {
     $subjectConfirmationData = new SubjectConfirmationData();
     $subjectConfirmationData->NotBefore = 987654321;
     $subjectConfirmationData->NotOnOrAfter = 1234567890;
     $subjectConfirmationData->Recipient = 'https://sp.example.org/asdf';
     $subjectConfirmationData->InResponseTo = 'SomeRequestID';
     $subjectConfirmationData->Address = '127.0.0.1';
     $document = DOMDocumentFactory::fromString('<root />');
     $subjectConfirmationDataElement = $subjectConfirmationData->toXML($document->firstChild);
     $subjectConfirmationDataElements = Utils::xpQuery($subjectConfirmationDataElement, '//saml_assertion:SubjectConfirmationData');
     $this->assertCount(1, $subjectConfirmationDataElements);
     $subjectConfirmationDataElement = $subjectConfirmationDataElements[0];
     $this->assertEquals('2001-04-19T04:25:21Z', $subjectConfirmationDataElement->getAttribute("NotBefore"));
     $this->assertEquals('2009-02-13T23:31:30Z', $subjectConfirmationDataElement->getAttribute("NotOnOrAfter"));
     $this->assertEquals('https://sp.example.org/asdf', $subjectConfirmationDataElement->getAttribute("Recipient"));
     $this->assertEquals('SomeRequestID', $subjectConfirmationDataElement->getAttribute("InResponseTo"));
     $this->assertEquals('127.0.0.1', $subjectConfirmationDataElement->getAttribute("Address"));
 }
예제 #24
0
파일: Attribute.php 프로젝트: SysBind/saml2
 /**
  * Initialize an Attribute.
  *
  * @param \DOMElement|null $xml The XML element we should load.
  * @throws \Exception
  */
 public function __construct(\DOMElement $xml = null)
 {
     if ($xml === null) {
         return;
     }
     if (!$xml->hasAttribute('Name')) {
         throw new \Exception('Missing Name on Attribute.');
     }
     $this->Name = $xml->getAttribute('Name');
     if ($xml->hasAttribute('NameFormat')) {
         $this->NameFormat = $xml->getAttribute('NameFormat');
     }
     if ($xml->hasAttribute('FriendlyName')) {
         $this->FriendlyName = $xml->getAttribute('FriendlyName');
     }
     foreach (Utils::xpQuery($xml, './saml_assertion:AttributeValue') as $av) {
         $this->AttributeValue[] = new AttributeValue($av);
     }
 }
예제 #25
0
 public function testMarshalling()
 {
     $roleDescriptor = new RoleDescriptorMock();
     $roleDescriptor->ID = 'SomeID';
     $roleDescriptor->validUntil = 1234567890;
     $roleDescriptor->cacheDuration = 'PT5000S';
     $roleDescriptor->protocolSupportEnumeration = array('protocol1', 'protocol2');
     $roleDescriptor->errorURL = 'https://example.org/error';
     $document = DOMDocumentFactory::fromString('<root />');
     $roleDescriptorElement = $roleDescriptor->toXML($document->firstChild);
     $roleDescriptorElement = Utils::xpQuery($roleDescriptorElement, '/root/md:RoleDescriptor');
     $this->assertCount(1, $roleDescriptorElement);
     $roleDescriptorElement = $roleDescriptorElement[0];
     $this->assertEquals('SomeID', $roleDescriptorElement->getAttribute("ID"));
     $this->assertEquals('2009-02-13T23:31:30Z', $roleDescriptorElement->getAttribute("validUntil"));
     $this->assertEquals('PT5000S', $roleDescriptorElement->getAttribute("cacheDuration"));
     $this->assertEquals('protocol1 protocol2', $roleDescriptorElement->getAttribute("protocolSupportEnumeration"));
     $this->assertEquals('myns:MyElement', $roleDescriptorElement->getAttributeNS(Constants::NS_XSI, "type"));
     $this->assertEquals('http://example.org/mynsdefinition', $roleDescriptorElement->lookupNamespaceURI("myns"));
 }
예제 #26
0
 public function testMarshalling()
 {
     $registrationInfo = new RegistrationInfo();
     $registrationInfo->registrationAuthority = 'https://ExampleAuthority';
     $registrationInfo->registrationInstant = 1234567890;
     $registrationInfo->RegistrationPolicy = array('en' => 'http://EnglishRegistrationPolicy', 'nl' => 'https://DutchRegistratiebeleid');
     $document = DOMDocumentFactory::fromString('<root />');
     $xml = $registrationInfo->toXML($document->firstChild);
     $registrationInfoElements = Utils::xpQuery($xml, '/root/*[local-name()=\'RegistrationInfo\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:rpi\']');
     $this->assertCount(1, $registrationInfoElements);
     $registrationInfoElement = $registrationInfoElements[0];
     $this->assertEquals('https://ExampleAuthority', $registrationInfoElement->getAttribute("registrationAuthority"));
     $this->assertEquals('2009-02-13T23:31:30Z', $registrationInfoElement->getAttribute("registrationInstant"));
     $usagePolicyElements = Utils::xpQuery($registrationInfoElement, './*[local-name()=\'RegistrationPolicy\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:rpi\']');
     $this->assertCount(2, $usagePolicyElements);
     $this->assertEquals('en', $usagePolicyElements[0]->getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang"));
     $this->assertEquals('http://EnglishRegistrationPolicy', $usagePolicyElements[0]->textContent);
     $this->assertEquals('nl', $usagePolicyElements[1]->getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang"));
     $this->assertEquals('https://DutchRegistratiebeleid', $usagePolicyElements[1]->textContent);
 }
예제 #27
0
 public function testMarshalling()
 {
     $attribute1 = new Attribute();
     $attribute1->Name = 'urn:simplesamlphp:v1:simplesamlphp';
     $attribute1->NameFormat = 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri';
     $attribute1->AttributeValue = array(new AttributeValue('FirstValue'), new AttributeValue('SecondValue'));
     $attribute2 = new Attribute();
     $attribute2->Name = 'foo';
     $attribute2->NameFormat = 'urn:simplesamlphp:v1';
     $attribute2->AttributeValue = array(new AttributeValue('bar'));
     $entityAttributes = new EntityAttributes();
     $entityAttributes->children[] = $attribute1;
     $entityAttributes->children[] = $attribute2;
     $document = DOMDocumentFactory::fromString('<root />');
     $xml = $entityAttributes->toXML($document->firstChild);
     $entityAttributesElements = Utils::xpQuery($xml, '/root/*[local-name()=\'EntityAttributes\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:attribute\']');
     $this->assertCount(1, $entityAttributesElements);
     $entityAttributesElement = $entityAttributesElements[0];
     $attributeElements = Utils::xpQuery($entityAttributesElement, './*[local-name()=\'Attribute\' and namespace-uri()=\'urn:oasis:names:tc:SAML:2.0:assertion\']');
     $this->assertCount(2, $attributeElements);
 }
예제 #28
0
 /**
  * Initialize an IDPSSODescriptor.
  *
  * @param \DOMElement|null $xml The XML element we should load.
  */
 public function __construct(\DOMElement $xml = null)
 {
     parent::__construct('md:IDPSSODescriptor', $xml);
     if ($xml === null) {
         return;
     }
     $this->WantAuthnRequestsSigned = Utils::parseBoolean($xml, 'WantAuthnRequestsSigned', null);
     foreach (Utils::xpQuery($xml, './saml_metadata:SingleSignOnService') as $ep) {
         $this->SingleSignOnService[] = new EndpointType($ep);
     }
     foreach (Utils::xpQuery($xml, './saml_metadata:NameIDMappingService') as $ep) {
         $this->NameIDMappingService[] = new EndpointType($ep);
     }
     foreach (Utils::xpQuery($xml, './saml_metadata:AssertionIDRequestService') as $ep) {
         $this->AssertionIDRequestService[] = new EndpointType($ep);
     }
     $this->AttributeProfile = Utils::extractStrings($xml, Constants::NS_MD, 'AttributeProfile');
     foreach (Utils::xpQuery($xml, './saml_assertion:Attribute') as $a) {
         $this->Attribute[] = new Attribute($a);
     }
 }
예제 #29
0
 public function testMarshalling()
 {
     $publicationInfo = new PublicationInfo();
     $publicationInfo->publisher = 'TestPublisher';
     $publicationInfo->creationInstant = 1234567890;
     $publicationInfo->publicationId = 'PublicationIdValue';
     $publicationInfo->UsagePolicy = array('en' => 'http://EnglishUsagePolicy', 'no' => 'http://NorwegianUsagePolicy');
     $document = DOMDocumentFactory::fromString('<root />');
     $xml = $publicationInfo->toXML($document->firstChild);
     $publicationInfoElements = Utils::xpQuery($xml, '/root/*[local-name()=\'PublicationInfo\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:rpi\']');
     $this->assertCount(1, $publicationInfoElements);
     $publicationInfoElement = $publicationInfoElements[0];
     $this->assertEquals('TestPublisher', $publicationInfoElement->getAttribute("publisher"));
     $this->assertEquals('2009-02-13T23:31:30Z', $publicationInfoElement->getAttribute("creationInstant"));
     $this->assertEquals('PublicationIdValue', $publicationInfoElement->getAttribute("publicationId"));
     $usagePolicyElements = Utils::xpQuery($publicationInfoElement, './*[local-name()=\'UsagePolicy\' and namespace-uri()=\'urn:oasis:names:tc:SAML:metadata:rpi\']');
     $this->assertCount(2, $usagePolicyElements);
     $this->assertEquals('en', $usagePolicyElements[0]->getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang"));
     $this->assertEquals('http://EnglishUsagePolicy', $usagePolicyElements[0]->textContent);
     $this->assertEquals('no', $usagePolicyElements[1]->getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang"));
     $this->assertEquals('http://NorwegianUsagePolicy', $usagePolicyElements[1]->textContent);
 }
예제 #30
0
 public function testMarshalling()
 {
     $document = DOMDocumentFactory::fromString('<root />');
     $affiliationDescriptorElement = new AffiliationDescriptor();
     $affiliationDescriptorElement->affiliationOwnerID = 'TheOwner';
     $affiliationDescriptorElement->ID = 'TheID';
     $affiliationDescriptorElement->validUntil = 1234567890;
     $affiliationDescriptorElement->cacheDuration = 'PT5000S';
     $affiliationDescriptorElement->AffiliateMember = array('Member1', 'Member2');
     $affiliationDescriptorElement = $affiliationDescriptorElement->toXML($document->firstChild);
     $affiliationDescriptorElements = Utils::xpQuery($affiliationDescriptorElement, '/root/saml_metadata:AffiliationDescriptor');
     $this->assertCount(1, $affiliationDescriptorElements);
     $affiliationDescriptorElement = $affiliationDescriptorElements[0];
     $this->assertEquals('TheOwner', $affiliationDescriptorElement->getAttribute("affiliationOwnerID"));
     $this->assertEquals('TheID', $affiliationDescriptorElement->getAttribute("ID"));
     $this->assertEquals('2009-02-13T23:31:30Z', $affiliationDescriptorElement->getAttribute("validUntil"));
     $this->assertEquals('PT5000S', $affiliationDescriptorElement->getAttribute("cacheDuration"));
     $affiliateMembers = Utils::xpQuery($affiliationDescriptorElement, './saml_metadata:AffiliateMember');
     $this->assertCount(2, $affiliateMembers);
     $this->assertEquals('Member1', $affiliateMembers[0]->textContent);
     $this->assertEquals('Member2', $affiliateMembers[1]->textContent);
 }