Revision: 1747
Author: olavmrk
Date: Mon Sep  7 02:25:30 2009
Log: SAML: Work around namespace prefix limitation/bug in DOMXPath.

If a message contains a namespace prefix on the root node that conflicts
with the prefix used by simpleSAMLphp, XPath will use the original prefix.

This can be a problem if we receive a message with a namespace prefix
of 'saml' instead of 'samlp'.

See: http://bugs.php.net/bug.php?id=49490
http://code.google.com/p/simplesamlphp/source/detail?r=1747

Modified:
  /trunk/lib/SAML2/Assertion.php
  /trunk/lib/SAML2/AttributeQuery.php
  /trunk/lib/SAML2/AuthnRequest.php
  /trunk/lib/SAML2/LogoutRequest.php
  /trunk/lib/SAML2/Message.php
  /trunk/lib/SAML2/StatusResponse.php
  /trunk/lib/SAML2/SubjectQuery.php
  /trunk/lib/SAML2/Utils.php

=======================================
--- /trunk/lib/SAML2/Assertion.php      Thu Aug 20 07:09:21 2009
+++ /trunk/lib/SAML2/Assertion.php      Mon Sep  7 02:25:30 2009
@@ -190,7 +190,7 @@

                $this->issueInstant =  
SimpleSAML_Utilities::parseSAML2Time($xml->getAttribute('IssueInstant'));

-               $issuer = SAML2_Utils::xpQuery($xml, './saml:Issuer');
+               $issuer = SAML2_Utils::xpQuery($xml, './saml_assertion:Issuer');
                if (empty($issuer)) {
                        throw new Exception('Missing <saml:Issuer> in 
assertion.');
                }
@@ -211,7 +211,7 @@
         */
        private function parseSubject(DOMElement $xml) {

-               $subject = SAML2_Utils::xpQuery($xml, './saml:Subject');
+               $subject = SAML2_Utils::xpQuery($xml, 
'./saml_assertion:Subject');
                if (empty($subject)) {
                        /* No Subject node. */
                        return;
@@ -220,7 +220,7 @@
                }
                $subject = $subject[0];

-               $nameId = SAML2_Utils::xpQuery($subject, './saml:NameID');
+               $nameId = SAML2_Utils::xpQuery($subject, 
'./saml_assertion:NameID');
                if (empty($nameId)) {
                        throw new Exception('Missing <saml:NameID> in 
<saml:Subject>.');
                } elseif (count($nameId) > 1) {
@@ -229,7 +229,7 @@
                $nameId = $nameId[0];
                $this->nameId = SAML2_Utils::parseNameId($nameId);

-               $subjectConfirmation =  
SAML2_Utils::xpQuery($subject, './saml:SubjectConfirmation');
+               $subjectConfirmation =  
SAML2_Utils::xpQuery($subject, './saml_assertion:SubjectConfirmation');
                if (empty($subjectConfirmation)) {
                        throw new Exception('Missing <saml:SubjectConfirmation> 
in  
<saml:Subject>.');
                } elseif (count($subjectConfirmation) > 1) {
@@ -246,7 +246,7 @@
                        throw new Exception('Unsupported subject confirmation 
method: ' .  
var_export($method, TRUE));
                }

-               $confirmationData =  
SAML2_Utils::xpQuery($subjectConfirmation, './saml:SubjectConfirmationData');
+               $confirmationData =  
SAML2_Utils::xpQuery($subjectConfirmation, 
'./saml_assertion:SubjectConfirmationData');
                if (empty($confirmationData)) {
                        return;
                } elseif (count($confirmationData) > 1) {
@@ -282,7 +282,7 @@
         */
        private function parseConditions(DOMElement $xml) {

-               $conditions = SAML2_Utils::xpQuery($xml, './saml:Conditions');
+               $conditions = SAML2_Utils::xpQuery($xml, 
'./saml_assertion:Conditions');
                if (empty($conditions)) {
                        /* No <saml:Conditions> node. */
                        return;
@@ -314,7 +314,7 @@
                        }
                        switch ($node->localName) {
                        case 'AudienceRestriction':
-                               $audiences = SAML2_Utils::xpQuery($node, 
'./saml:Audience');
+                               $audiences = SAML2_Utils::xpQuery($node, 
'./saml_assertion:Audience');
                                foreach ($audiences as &$audience) {
                                        $audience = 
trim($audience->textContent);
                                }
@@ -351,7 +351,7 @@
         */
        private function parseAuthnStatement(DOMElement $xml) {

-               $as = SAML2_Utils::xpQuery($xml, './saml:AuthnStatement');
+               $as = SAML2_Utils::xpQuery($xml, 
'./saml_assertion:AuthnStatement');
                if (empty($as)) {
                        return;
                } elseif (count($as) > 1) {
@@ -372,7 +372,7 @@
                        $this->sessionIndex = $as->getAttribute('SessionIndex');
                }

-               $ac = SAML2_Utils::xpQuery($as, './saml:AuthnContext');
+               $ac = SAML2_Utils::xpQuery($as, 
'./saml_assertion:AuthnContext');
                if (empty($ac)) {
                        throw new Exception('Missing required 
<saml:AuthnContext> in  
<saml:AuthnStatement>.');
                } elseif (count($ac) > 1) {
@@ -380,9 +380,9 @@
                }
                $ac = $ac[0];

-               $accr = SAML2_Utils::xpQuery($ac, 
'./saml:AuthnContextClassRef');
+               $accr =  
SAML2_Utils::xpQuery($ac, './saml_assertion:AuthnContextClassRef');
                if (empty($accr)) {
-                       $acdr = SAML2_Utils::xpQuery($ac, 
'./saml:AuthnContextDeclRef');
+                       $acdr =  
SAML2_Utils::xpQuery($ac, './saml_assertion:AuthnContextDeclRef');
                        if (empty($acdr)) {
                                throw new Exception('Neither 
<saml:AuthnContextClassRef> nor  
<saml:AuthnContextDeclRef> found in <saml:AuthnContext>.');
                        } elseif (count($accr) > 1) {
@@ -405,7 +405,7 @@
        private function parseAttributes(DOMElement $xml) {

                $firstAttribute = TRUE;
-               $attributes =  
SAML2_Utils::xpQuery($xml, './saml:AttributeStatement/saml:Attribute');
+               $attributes =  
SAML2_Utils::xpQuery($xml, 
'./saml_assertion:AttributeStatement/saml_assertion:Attribute');
                foreach ($attributes as $attribute) {
                        if (!$attribute->hasAttribute('Name')) {
                                throw new Exception('Missing name on 
<saml:Attribute> element.');
@@ -431,7 +431,7 @@
                                $this->attributes[$name] = array();
                        }

-                       $values = SAML2_Utils::xpQuery($attribute, 
'./saml:AttributeValue');
+                       $values =  
SAML2_Utils::xpQuery($attribute, './saml_assertion:AttributeValue');
                        foreach ($values as $value) {
                                $this->attributes[$name][] = 
trim($value->textContent);
                        }
=======================================
--- /trunk/lib/SAML2/AttributeQuery.php Thu Aug 13 05:00:19 2009
+++ /trunk/lib/SAML2/AttributeQuery.php Mon Sep  7 02:25:30 2009
@@ -54,7 +54,7 @@
                }

                $firstAttribute = TRUE;
-               $attributes = SAML2_Utils::xpQuery($xml, './saml:Attribute');
+               $attributes = SAML2_Utils::xpQuery($xml, 
'./saml_assertion:Attribute');
                foreach ($attributes as $attribute) {
                        if (!$attribute->hasAttribute('Name')) {
                                throw new Exception('Missing name on 
<saml:Attribute> element.');
@@ -80,7 +80,7 @@
                                $this->attributes[$name] = array();
                        }

-                       $values = SAML2_Utils::xpQuery($attribute, 
'./saml:AttributeValue');
+                       $values =  
SAML2_Utils::xpQuery($attribute, './saml_assertion:AttributeValue');
                        foreach ($values as $value) {
                                $this->attributes[$name][] = 
trim($value->textContent);
                        }
=======================================
--- /trunk/lib/SAML2/AuthnRequest.php   Mon Aug  3 05:46:28 2009
+++ /trunk/lib/SAML2/AuthnRequest.php   Mon Sep  7 02:25:30 2009
@@ -74,7 +74,7 @@
                        $this->protocolBinding = 
$xml->getAttribute('ProtocolBinding');
                }

-               $nameIdPolicy = SAML2_Utils::xpQuery($xml, 
'./samlp:NameIDPolicy');
+               $nameIdPolicy =  
SAML2_Utils::xpQuery($xml, './saml_protocol:NameIDPolicy');
                if (!empty($nameIdPolicy)) {
                        $nameIdPolicy = $nameIdPolicy[0];
                        if ($nameIdPolicy->hasAttribute('Format')) {
=======================================
--- /trunk/lib/SAML2/LogoutRequest.php  Thu Aug 13 05:00:19 2009
+++ /trunk/lib/SAML2/LogoutRequest.php  Mon Sep  7 02:25:30 2009
@@ -37,13 +37,13 @@
                        return;
                }

-               $nameId = SAML2_Utils::xpQuery($xml, './saml:NameID');
+               $nameId = SAML2_Utils::xpQuery($xml, './saml_assertion:NameID');
                if (empty($nameId)) {
                        throw new Exception('Missing NameID in logout 
request.');
                }
                $this->nameId = SAML2_Utils::parseNameId($nameId[0]);

-               $sessionIndex = SAML2_Utils::xpQuery($xml, 
'./samlp:SessionIndex');
+               $sessionIndex =  
SAML2_Utils::xpQuery($xml, './saml_protocol:SessionIndex');
                if (!empty($sessionIndex)) {
                        $this->sessionIndex = 
trim($sessionIndex[0]->textContent);
                }
=======================================
--- /trunk/lib/SAML2/Message.php        Thu Aug 13 05:00:19 2009
+++ /trunk/lib/SAML2/Message.php        Mon Sep  7 02:25:30 2009
@@ -140,7 +140,7 @@
                        $this->destination = $xml->getAttribute('Destination');
                }

-               $issuer = SAML2_Utils::xpQuery($xml, './saml:Issuer');
+               $issuer = SAML2_Utils::xpQuery($xml, './saml_assertion:Issuer');
                if (!empty($issuer)) {
                        $this->issuer = trim($issuer[0]->textContent);
                }
=======================================
--- /trunk/lib/SAML2/StatusResponse.php Thu Aug 13 05:00:19 2009
+++ /trunk/lib/SAML2/StatusResponse.php Mon Sep  7 02:25:30 2009
@@ -62,13 +62,13 @@
                        $this->inResponseTo = 
$xml->getAttribute('InResponseTo');
                }

-               $status = SAML2_Utils::xpQuery($xml, './samlp:Status');
+               $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, 
'./samlp:StatusCode');
+               $statusCode =  
SAML2_Utils::xpQuery($status, './saml_protocol:StatusCode');
                if (empty($statusCode)) {
                        throw new Exception('Missing status code in status 
element.');
                }
@@ -76,12 +76,12 @@

                $this->status['Code'] = $statusCode->getAttribute('Value');

-               $subCode = SAML2_Utils::xpQuery($statusCode, 
'./samlp:StatusCode');
+               $subCode =  
SAML2_Utils::xpQuery($statusCode, './saml_protocol:StatusCode');
                if (!empty($subCode)) {
                        $this->status['SubCode'] = 
$subCode[0]->getAttribute('Value');
                }

-               $message = SAML2_Utils::xpQuery($status, 
'./samlp:StatusMessage');
+               $message =  
SAML2_Utils::xpQuery($status, './saml_protocol:StatusMessage');
                if (!empty($message)) {
                        $this->status['Message'] = 
trim($message[0]->textContent);
                }
=======================================
--- /trunk/lib/SAML2/SubjectQuery.php   Tue Aug  4 01:08:10 2009
+++ /trunk/lib/SAML2/SubjectQuery.php   Mon Sep  7 02:25:30 2009
@@ -48,7 +48,7 @@
         */
        private function parseSubject(DOMElement $xml) {

-               $subject = SAML2_Utils::xpQuery($xml, './saml:Subject');
+               $subject = SAML2_Utils::xpQuery($xml, 
'./saml_assertion:Subject');
                if (empty($subject)) {
                        /* No Subject node. */
                        throw new Exception('Missing subject in subject 
query.');
@@ -57,7 +57,7 @@
                }
                $subject = $subject[0];

-               $nameId = SAML2_Utils::xpQuery($subject, './saml:NameID');
+               $nameId = SAML2_Utils::xpQuery($subject, 
'./saml_assertion:NameID');
                if (empty($nameId)) {
                        throw new Exception('Missing <saml:NameID> in 
<saml:Subject>.');
                } elseif (count($nameId) > 1) {
=======================================
--- /trunk/lib/SAML2/Utils.php  Thu Aug 13 05:00:19 2009
+++ /trunk/lib/SAML2/Utils.php  Mon Sep  7 02:25:30 2009
@@ -115,8 +115,8 @@

                if ($xpCache === NULL | 
| !$xpCache->document->isSameNode($node->ownerDocument)) {
                        $xpCache = new DOMXPath($node->ownerDocument);
-                       $xpCache->registerNamespace('samlp', 
SAML2_Const::NS_SAMLP);
-                       $xpCache->registerNamespace('saml', 
SAML2_Const::NS_SAML);
+                       $xpCache->registerNamespace('saml_protocol', 
SAML2_Const::NS_SAMLP);
+                       $xpCache->registerNamespace('saml_assertion', 
SAML2_Const::NS_SAML);
                        $xpCache->registerNamespace('ds', 
XMLSecurityDSig::XMLDSIGNS);
                        $xpCache->registerNamespace('xenc', 
XMLSecEnc::XMLENCNS);
                }
@@ -173,7 +173,7 @@
        public static function addNameId(DOMElement $node, array $nameId) {
                assert('array_key_exists("Value", $nameId)');

-               $xml =  
$node->ownerDocument->createElementNS(SAML2_Const::NS_SAML, 'saml:NameID');
+               $xml =  
$node->ownerDocument->createElementNS(SAML2_Const::NS_SAML, 
'saml_assertion:NameID');
                $node->appendChild($xml);

                if (array_key_exists('NameQualifier', $nameId) &&  
$nameId['NameQualifier'] !== NULL) {

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"simpleSAMLphp commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/simplesamlphp-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to