Exemplo n.º 1
0
    public function testMarshallingOfSimpleRequest()
    {
        $document = new DOMDocument();
        $document->loadXML(<<<AUTHNREQUEST
<samlp:AuthnRequest
  xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
  xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
  ID="_306f8ec5b618f361c70b6ffb1480eade"
  Version="2.0"
  IssueInstant="2004-12-05T09:21:59Z"
  Destination="https://idp.example.org/SAML2/SSO/Artifact"
  ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact"
  AssertionConsumerServiceURL="https://sp.example.com/SAML2/SSO/Artifact">
    <saml:Issuer>https://sp.example.com/SAML2</saml:Issuer>
</samlp:AuthnRequest>
AUTHNREQUEST
);
        $authnRequest = new SAML2_AuthnRequest($document->documentElement);
        $expectedIssueInstant = SAML2_Utils::xsDateTimeToTimestamp('2004-12-05T09:21:59Z');
        $this->assertEquals($expectedIssueInstant, $authnRequest->getIssueInstant());
        $this->assertEquals('https://idp.example.org/SAML2/SSO/Artifact', $authnRequest->getDestination());
        $this->assertEquals('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact', $authnRequest->getProtocolBinding());
        $this->assertEquals('https://sp.example.com/SAML2/SSO/Artifact', $authnRequest->getAssertionConsumerServiceURL());
        $this->assertEquals('https://sp.example.com/SAML2', $authnRequest->getIssuer());
    }
Exemplo n.º 2
0
 public function testMarshalling()
 {
     $indexedEndpointType = new SAML2_XML_md_IndexedEndpointType();
     $indexedEndpointType->Binding = 'TestBinding';
     $indexedEndpointType->Location = 'TestLocation';
     $indexedEndpointType->index = 42;
     $indexedEndpointType->isDefault = FALSE;
     $document = SAML2_DOMDocumentFactory::fromString('<root />');
     $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test');
     $indexedEndpointElements = SAML2_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 = SAML2_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 = SAML2_Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test');
     $this->assertCount(1, $indexedEndpointTypeElement);
     $this->assertTrue(!$indexedEndpointTypeElement[0]->hasAttribute('isDefault'));
 }
Exemplo n.º 3
0
 /**
  * Constructor for SAML 2 response messages.
  *
  * @param string $tagName  The tag name of the root element.
  * @param DOMElement|NULL $xml  The input message.
  */
 protected function __construct($tagName, DOMElement $xml = NULL)
 {
     parent::__construct($tagName, $xml);
     $this->status = array('Code' => SAML2_Const::STATUS_SUCCESS, 'SubCode' => NULL, 'Message' => NULL);
     if ($xml === NULL) {
         return;
     }
     if ($xml->hasAttribute('InResponseTo')) {
         $this->inResponseTo = $xml->getAttribute('InResponseTo');
     }
     $status = SAML2_Utils::xpQuery($xml, './saml_protocol:Status');
     if (empty($status)) {
         throw new Exception('Missing status code on response.');
     }
     $status = $status[0];
     $statusCode = SAML2_Utils::xpQuery($status, './saml_protocol:StatusCode');
     if (empty($statusCode)) {
         throw new Exception('Missing status code in status element.');
     }
     $statusCode = $statusCode[0];
     $this->status['Code'] = $statusCode->getAttribute('Value');
     $subCode = SAML2_Utils::xpQuery($statusCode, './saml_protocol:StatusCode');
     if (!empty($subCode)) {
         $this->status['SubCode'] = $subCode[0]->getAttribute('Value');
     }
     $message = SAML2_Utils::xpQuery($status, './saml_protocol:StatusMessage');
     if (!empty($message)) {
         $this->status['Message'] = trim($message[0]->textContent);
     }
 }
Exemplo n.º 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 = SAML2_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 = SAML2_XML_md_Extensions::getList($xml);
     foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:EntityDescriptor|./saml_metadata:EntitiesDescriptor') as $node) {
         if ($node->localName === 'EntityDescriptor') {
             $this->children[] = new SAML2_XML_md_EntityDescriptor($node);
         } else {
             $this->children[] = new SAML2_XML_md_EntitiesDescriptor($node);
         }
     }
 }
Exemplo n.º 5
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'));
    }
 public function testMarshalling()
 {
     $attributeQuery = new SAML2_AttributeQuery();
     $attributeQuery->setNameID(array('Value' => 'NameIDValue'));
     $attributeQuery->setAttributes(array('test1' => array('test1_attrv1', 'test1_attrv2'), 'test2' => array('test2_attrv1', 'test2_attrv2', 'test2_attrv3'), 'test3' => array()));
     $attributeQueryElement = $attributeQuery->toUnsignedXML();
     // Test Attribute Names
     $attributes = SAML2_Utils::xpQuery($attributeQueryElement, './saml_assertion:Attribute');
     $this->assertCount(3, $attributes);
     $this->assertEquals('test1', $attributes[0]->getAttribute('Name'));
     $this->assertEquals('test2', $attributes[1]->getAttribute('Name'));
     $this->assertEquals('test3', $attributes[2]->getAttribute('Name'));
     // Test Attribute Values for Attribute 1
     $av1 = SAML2_Utils::xpQuery($attributes[0], './saml_assertion:AttributeValue');
     $this->assertCount(2, $av1);
     $this->assertEquals('test1_attrv1', $av1[0]->textContent);
     $this->assertEquals('test1_attrv2', $av1[1]->textContent);
     // Test Attribute Values for Attribute 2
     $av2 = SAML2_Utils::xpQuery($attributes[1], './saml_assertion:AttributeValue');
     $this->assertCount(3, $av2);
     $this->assertEquals('test2_attrv1', $av2[0]->textContent);
     $this->assertEquals('test2_attrv2', $av2[1]->textContent);
     $this->assertEquals('test2_attrv3', $av2[2]->textContent);
     // Test Attribute Values for Attribute 3
     $av3 = SAML2_Utils::xpQuery($attributes[2], './saml_assertion:AttributeValue');
     $this->assertCount(0, $av3);
 }
Exemplo n.º 7
0
 /**
  * Append this attribute value to an element.
  *
  * @param  DOMElement $parent The element we should append this attribute value to.
  * @return DOMElement The generated AttributeValue element.
  */
 public function toXML(DOMElement $parent)
 {
     assert('$this->element instanceof DOMElement');
     assert('$this->element->namespaceURI === SAML2_Const::NS_SAML && $this->element->localName === "AttributeValue"');
     $v = SAML2_Utils::copyElement($this->element, $parent);
     return $v;
 }
Exemplo n.º 8
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 (SAML2_Utils::xpQuery($parent, './saml_protocol:Extensions/*') as $node) {
         $ret[] = new SAML2_XML_Chunk($node);
     }
     return $ret;
 }
Exemplo n.º 9
0
 public function __construct(DOMElement $xml = NULL)
 {
     parent::__construct('ArtifactResolve', $xml);
     if (!is_null($xml)) {
         $results = SAML2_Utils::xpQuery($xml, './saml_protocol:Artifact');
         $this->artifact = $results[0]->textContent;
     }
 }
 /**
  * Convert this AdditionalMetadataLocation to XML.
  *
  * @param  DOMElement $parent The element we should append to.
  * @return DOMElement This AdditionalMetadataLocation-element.
  */
 public function toXML(DOMElement $parent)
 {
     assert('is_string($this->namespace)');
     assert('is_string($this->location)');
     $e = SAML2_Utils::addString($parent, SAML2_Const::NS_MD, 'md:AdditionalMetadataLocation', $this->location);
     $e->setAttribute('namespace', $this->namespace);
     return $e;
 }
Exemplo n.º 11
0
 /**
  * Create a Scope.
  *
  * @param DOMElement|NULL $xml  The XML element we should load.
  */
 public function __construct(DOMElement $xml = NULL)
 {
     if ($xml === NULL) {
         return;
     }
     $this->scope = $xml->textContent;
     $this->regexp = SAML2_Utils::parseBoolean($xml, 'regexp', NULL);
 }
Exemplo n.º 12
0
 /**
  * Initialize an RequestedAttribute.
  *
  * @param DOMElement|NULL $xml The XML element we should load.
  */
 public function __construct(DOMElement $xml = NULL)
 {
     parent::__construct($xml);
     if ($xml === NULL) {
         return;
     }
     $this->isRequired = SAML2_Utils::parseBoolean($xml, 'isRequired', NULL);
 }
Exemplo n.º 13
0
 /**
  * Test retrieval of a localized string for a given node.
  */
 public function testExtractLocalizedString()
 {
     $document = new DOMDocument();
     $document->loadXML('<root xmlns="' . SAML2_Const::NS_MD . '">' . '<somenode xml:lang="en">value (en)</somenode>' . '<somenode xml:lang="no">value (no)</somenode>' . '</root>');
     $localizedStringValues = SAML2_Utils::extractLocalizedStrings($document->firstChild, SAML2_Const::NS_MD, 'somenode');
     $this->assertTrue(count($localizedStringValues) === 2);
     $this->assertEquals('value (en)', $localizedStringValues["en"]);
     $this->assertEquals('value (no)', $localizedStringValues["no"]);
 }
Exemplo n.º 14
0
 /**
  * Test xsDateTime format validity
  *
  * @dataProvider xsDateTimes
  */
 public function testXsDateTimeToTimestamp($shouldPass, $time, $expectedTs = null)
 {
     try {
         $ts = SAML2_Utils::xsDateTimeToTimestamp($time);
         $this->assertTrue($shouldPass);
         $this->assertEquals($expectedTs, $ts);
     } catch (Exception $e) {
         $this->assertFalse($shouldPass);
     }
 }
 /**
  * @param string $saml_response Base64 Encoded SAML
  *
  * @throws Exception When no assertions are found or signature in invalid
  */
 public function load_saml_response($saml_response)
 {
     $response_element = SAML2_DOMDocumentFactory::fromString(base64_decode($saml_response))->documentElement;
     $signature_info = SAML2_Utils::validateElement($response_element);
     SAML2_Utils::validateSignature($signature_info, $this->security_key);
     $response = SAML2_StatusResponse::fromXML($response_element);
     $this->destination = $response->getDestination();
     $assertions = $response->getAssertions();
     $this->assertions = $assertions;
 }
Exemplo n.º 16
0
 /**
  * Receive a SAML 2 message sent using the HTTP-Artifact binding.
  *
  * Throws an exception if it is unable receive the message.
  *
  * @return SAML2_Message The received message.
  * @throws Exception
  */
 public function receive()
 {
     if (array_key_exists('SAMLart', $_REQUEST)) {
         $artifact = base64_decode($_REQUEST['SAMLart']);
         $endpointIndex = bin2hex(substr($artifact, 2, 2));
         $sourceId = bin2hex(substr($artifact, 4, 20));
     } else {
         throw new Exception('Missing SAMLArt parameter.');
     }
     $metadataHandler = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
     $idpMetadata = $metadataHandler->getMetaDataConfigForSha1($sourceId, 'saml20-idp-remote');
     if ($idpMetadata === NULL) {
         throw new Exception('No metadata found for remote provider with SHA1 ID: ' . var_export($sourceId, TRUE));
     }
     $endpoint = NULL;
     foreach ($idpMetadata->getEndpoints('ArtifactResolutionService') as $ep) {
         if ($ep['index'] === hexdec($endpointIndex)) {
             $endpoint = $ep;
             break;
         }
     }
     if ($endpoint === NULL) {
         throw new Exception('No ArtifactResolutionService with the correct index.');
     }
     SAML2_Utils::getContainer()->getLogger()->debug("ArtifactResolutionService endpoint being used is := " . $endpoint['Location']);
     //Construct the ArtifactResolve Request
     $ar = new SAML2_ArtifactResolve();
     /* Set the request attributes */
     $ar->setIssuer($this->spMetadata->getString('entityid'));
     $ar->setArtifact($_REQUEST['SAMLart']);
     $ar->setDestination($endpoint['Location']);
     require_once realpath(__DIR__ . '/../../../simplesamlphp/modules/saml/lib/Message.php');
     /* Sign the request */
     sspmod_saml_Message::addSign($this->spMetadata, $idpMetadata, $ar);
     // Shoaib - moved from the SOAPClient.
     $soap = new SAML2_SOAPClient();
     // Send message through SoapClient
     /** @var SAML2_ArtifactResponse $artifactResponse */
     $artifactResponse = $soap->send($ar, $this->spMetadata);
     if (!$artifactResponse->isSuccess()) {
         return false;
     }
     $xml = $artifactResponse->getAny();
     if ($xml === NULL) {
         /* Empty ArtifactResponse - possibly because of Artifact replay? */
         return NULL;
     }
     $samlResponse = SAML2_Message::fromXML($xml);
     $samlResponse->addValidator(array(get_class($this), 'validateSignature'), $artifactResponse);
     if (isset($_REQUEST['RelayState'])) {
         $samlResponse->setRelayState($_REQUEST['RelayState']);
     }
     return $samlResponse;
 }
Exemplo n.º 17
0
 /**
  * Receive a SAML 2 message sent using the HTTP-POST binding.
  *
  * Throws an exception if it is unable receive the message.
  *
  * @return SAML2_Message  The received message.
  */
 public function receive()
 {
     $postText = file_get_contents('php://input');
     if (empty($postText)) {
         throw new SimpleSAML_Error_BadRequest('Invalid message received to AssertionConsumerService endpoint.');
     }
     $document = new DOMDocument();
     $document->loadXML($postText);
     $xml = $document->firstChild;
     $results = SAML2_Utils::xpQuery($xml, '/soap-env:Envelope/soap-env:Body/*[1]');
     return SAML2_Message::fromXML($results[0]);
 }
Exemplo n.º 18
0
 /**
  * Receive a SAML 2 message sent using the HTTP-POST binding.
  *
  * Throws an exception if it is unable receive the message.
  *
  * @return SAML2_Message The received message.
  * @throws Exception
  */
 public function receive()
 {
     $postText = file_get_contents('php://input');
     if (empty($postText)) {
         throw new Exception('Invalid message received to AssertionConsumerService endpoint.');
     }
     $document = SAML2_DOMDocumentFactory::fromString($postText);
     $xml = $document->firstChild;
     SAML2_Utils::getContainer()->debugMessage($xml, 'in');
     $results = SAML2_Utils::xpQuery($xml, '/soap-env:Envelope/soap-env:Body/*[1]');
     return SAML2_Message::fromXML($results[0]);
 }
Exemplo n.º 19
0
 public function testMarshalling()
 {
     $response = new SAML2_Response();
     $response->setConsent(SAML2_Const::CONSENT_EXPLICIT);
     $response->setIssuer('SomeIssuer');
     $responseElement = $response->toUnsignedXML();
     $this->assertTrue($responseElement->hasAttribute('Consent'));
     $this->assertEquals($responseElement->getAttribute('Consent'), SAML2_Const::CONSENT_EXPLICIT);
     $issuerElements = SAML2_Utils::xpQuery($responseElement, './saml_assertion:Issuer');
     $this->assertCount(1, $issuerElements);
     $this->assertEquals('SomeIssuer', $issuerElements[0]->textContent);
 }
Exemplo n.º 20
0
 /**
  * Initialize an IndexedEndpointType.
  *
  * @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('index')) {
         throw new Exception('Missing index on ' . $xml->tagName);
     }
     $this->index = (int) $xml->getAttribute('index');
     $this->isDefault = SAML2_Utils::parseBoolean($xml, 'isDefault', NULL);
 }
Exemplo n.º 21
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 (SAML2_Utils::xpQuery($xml, './saml_assertion:Attribute|./saml_assertion:Assertion') as $node) {
         if ($node->localName === 'Attribute') {
             $this->children[] = new SAML2_XML_saml_Attribute($node);
         } else {
             $this->children[] = new SAML2_XML_Chunk($node);
         }
     }
 }
 public function testMarshalling()
 {
     $document = SAML2_DOMDocumentFactory::fromString('<root/>');
     $additionalMetadataLocation = new SAML2_XML_md_AdditionalMetadataLocation();
     $additionalMetadataLocation->namespace = 'NamespaceAttribute';
     $additionalMetadataLocation->location = 'TheLocation';
     $additionalMetadataLocationElement = $additionalMetadataLocation->toXML($document->firstChild);
     $additionalMetadataLocationElements = SAML2_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"));
 }
Exemplo n.º 23
0
 /**
  * Get a list of Extensions in the given element.
  *
  * @param DOMElement $parent  The element that may contain the md:Extensions element.
  * @return array  Array of extensions.
  */
 public static function getList(DOMElement $parent)
 {
     $ret = array();
     foreach (SAML2_Utils::xpQuery($parent, './saml_metadata:Extensions/*') as $node) {
         if ($node->namespaceURI === SAML2_XML_shibmd_Scope::NS && $node->localName === 'Scope') {
             $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);
         } else {
             $ret[] = new SAML2_XML_Chunk($node);
         }
     }
     return $ret;
 }
 /**
  * Resolve the eduPersonTargetedId we should send.
  */
 public function execute()
 {
     // Note that we try to service the final destination SP, if we know them and are allowed to do so.
     $destinationMetadata = EngineBlock_SamlHelper::getDestinationSpMetadata($this->_serviceProvider, $this->_request, $this->_server->getRepository());
     // Resolve what NameID we should send the destination.
     $resolver = new EngineBlock_Saml2_NameIdResolver();
     $nameId = $resolver->resolve($this->_request, $this->_response, $destinationMetadata, $this->_collabPersonId);
     // EPTID requires us to embed the <saml:NameID> element instead of just the value, so we generate that here.
     $document = new DOMDocument();
     $document->loadXML('<base />');
     SAML2_Utils::addNameId($document->documentElement, $nameId);
     // Add the eduPersonTargetedId attribute.
     $this->_responseAttributes['urn:mace:dir:attribute-def:eduPersonTargetedID'] = array($document->documentElement->childNodes);
 }
 /**
  * @param string $saml_request Base64 Encoded SAML
  *
  * @throws Exception When signature in invalid
  */
 public function load_saml_request($saml_request)
 {
     $request_element = SAML2_DOMDocumentFactory::fromString(base64_decode($saml_request))->documentElement;
     $signature_info = SAML2_Utils::validateElement($request_element);
     SAML2_Utils::validateSignature($signature_info, $this->security_key);
     /** @var SAML2_LogoutRequest $request */
     $request = SAML2_LogoutRequest::fromXML($request_element);
     $request->decryptNameId($this->security_key);
     $name_id = $request->getNameId();
     $this->notOnOrAfter = $request->getNotOnOrAfter();
     $this->name = $name_id ? $name_id['Value'] : null;
     $this->session_index = $request->getSessionIndex();
     $this->destination = $request->getDestination();
 }
 public function testUnmarshalling()
 {
     $authnRequest = new SAML2_AuthnRequest();
     $authnRequest->setRequestedAuthnContext(array('AuthnContextClassRef' => array('accr1', 'accr2'), 'Comparison' => 'better'));
     $authnRequestElement = $authnRequest->toUnsignedXML();
     $requestedAuthnContextElements = SAML2_Utils::xpQuery($authnRequestElement, './saml_protocol:RequestedAuthnContext');
     $this->assertCount(1, $requestedAuthnContextElements);
     $requestedAuthnConextElement = $requestedAuthnContextElements[0];
     $this->assertEquals('better', $requestedAuthnConextElement->getAttribute("Comparison"));
     $authnContextClassRefElements = SAML2_Utils::xpQuery($requestedAuthnConextElement, './saml_assertion:AuthnContextClassRef');
     $this->assertCount(2, $authnContextClassRefElements);
     $this->assertEquals('accr1', $authnContextClassRefElements[0]->textContent);
     $this->assertEquals('accr2', $authnContextClassRefElements[1]->textContent);
 }
Exemplo n.º 27
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 = SAML2_Utils::parseBoolean($xml, 'AuthnRequestsSigned', NULL);
     $this->WantAssertionsSigned = SAML2_Utils::parseBoolean($xml, 'WantAssertionsSigned', NULL);
     foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:AssertionConsumerService') as $ep) {
         $this->AssertionConsumerService[] = new SAML2_XML_md_IndexedEndpointType($ep);
     }
     foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:AttributeConsumingService') as $acs) {
         $this->AttributeConsumingService[] = new SAML2_XML_md_AttributeConsumingService($acs);
     }
 }
Exemplo n.º 28
0
 /**
  * Convert this element to XML.
  *
  * @param DOMElement $parent  The element we should append to.
  */
 public function toXML(DOMElement $parent)
 {
     assert('is_string($this->registrationAuthority)');
     assert('is_int($this->registrationInstant) || is_null($this->registrationInstant)');
     assert('is_array($this->RegistrationPolicy)');
     $doc = $parent->ownerDocument;
     $e = $doc->createElementNS(SAML2_XML_mdrpi_Common::NS_MDRPI, 'mdrpi:RegistrationInfo');
     $parent->appendChild($e);
     $e->setAttribute('registrationAuthority', $this->registrationAuthority);
     if ($this->registrationInstant !== NULL) {
         $e->setAttribute('registrationInstant', gmdate('Y-m-d\\TH:i:s\\Z', $this->registrationInstant));
     }
     SAML2_Utils::addStrings($e, SAML2_XML_mdrpi_Common::NS_MDRPI, 'mdrpi:RegistrationPolicy', TRUE, $this->RegistrationPolicy);
     return $e;
 }
Exemplo n.º 29
0
 public function testMarshalling()
 {
     $subjectConfirmation = new SAML2_XML_saml_SubjectConfirmation();
     $subjectConfirmation->Method = 'SomeMethod';
     $subjectConfirmation->NameID = new SAML2_XML_saml_NameID();
     $subjectConfirmation->NameID->value = 'SomeNameIDValue';
     $subjectConfirmation->SubjectConfirmationData = new SAML2_XML_saml_SubjectConfirmationData();
     $document = SAML2_DOMDocumentFactory::fromString('<root />');
     $subjectConfirmationElement = $subjectConfirmation->toXML($document->firstChild);
     $subjectConfirmationElements = SAML2_Utils::xpQuery($subjectConfirmationElement, '//saml_assertion:SubjectConfirmation');
     $this->assertCount(1, $subjectConfirmationElements);
     $subjectConfirmationElement = $subjectConfirmationElements[0];
     $this->assertEquals('SomeMethod', $subjectConfirmationElement->getAttribute("Method"));
     $this->assertCount(1, SAML2_Utils::xpQuery($subjectConfirmationElement, "./saml_assertion:NameID"));
     $this->assertCount(1, SAML2_Utils::xpQuery($subjectConfirmationElement, "./saml_assertion:SubjectConfirmationData"));
 }
Exemplo n.º 30
0
 /**
  * Add this PDPDescriptor to an EntityDescriptor.
  *
  * @param DOMElement $parent The EntityDescriptor we should append this IDPSSODescriptor to.
  * @return DOMElement
  */
 public function toXML(DOMElement $parent)
 {
     assert('is_array($this->AuthzService)');
     assert('!empty($this->AuthzService)');
     assert('is_array($this->AssertionIDRequestService)');
     assert('is_array($this->NameIDFormat)');
     $e = parent::toXML($parent);
     foreach ($this->AuthzService as $ep) {
         $ep->toXML($e, 'md:AuthzService');
     }
     foreach ($this->AssertionIDRequestService as $ep) {
         $ep->toXML($e, 'md:AssertionIDRequestService');
     }
     SAML2_Utils::addStrings($e, SAML2_Const::NS_MD, 'md:NameIDFormat', FALSE, $this->NameIDFormat);
     return $e;
 }