Skip to content

Commit fc18ff8

Browse files
committed
PHPCAS-59 Fix warning when no attributes are submitted with the saml response
git-svn-id: https://source.jasig.org/cas-clients/phpcas/trunk@20631 f5dbab47-78f9-eb45-b975-e544023573eb
1 parent 6f30fbb commit fc18ff8

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

source/CAS/client.php

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ function validateSA($validate_url,&$text_response,&$tree_response)
15421542
* payload and put them into an array, then put the array into the session.
15431543
*
15441544
* @param $text_response the SAML payload.
1545-
* @return bool TRUE when successfull, halt otherwise by calling CASClient::authError().
1545+
* @return bool TRUE when successfull and FALSE if no attributes a found
15461546
*
15471547
* @private
15481548
*/
@@ -1563,30 +1563,34 @@ function setSessionAttributes($text_response)
15631563
$xPath->xpath_register_ns('samlp', 'urn:oasis:names:tc:SAML:1.0:protocol');
15641564
$xPath->xpath_register_ns('saml', 'urn:oasis:names:tc:SAML:1.0:assertion');
15651565
$nodelist = $xPath->xpath_eval("//saml:Attribute");
1566-
$attrs = $nodelist->nodeset;
1567-
phpCAS::trace($text_response);
1568-
foreach($attrs as $attr){
1569-
$xres = $xPath->xpath_eval("saml:AttributeValue", $attr);
1570-
$name = $attr->get_attribute("AttributeName");
1571-
$value_array = array();
1572-
foreach($xres->nodeset as $node){
1573-
$value_array[] = $node->get_content();
1574-
1575-
}
1576-
phpCAS::trace("* " . $name . "=" . $value_array);
1577-
$attr_array[$name] = $value_array;
1578-
}
1579-
$_SESSION[SAML_ATTRIBUTES] = $attr_array;
1580-
// UGent addition...
1581-
foreach($attr_array as $attr_key => $attr_value) {
1582-
if(count($attr_value) > 1) {
1583-
$this->_attributes[$attr_key] = $attr_value;
1566+
if($nodelist){
1567+
$attrs = $nodelist->nodeset;
1568+
phpCAS::trace($text_response);
1569+
foreach($attrs as $attr){
1570+
$xres = $xPath->xpath_eval("saml:AttributeValue", $attr);
1571+
$name = $attr->get_attribute("AttributeName");
1572+
$value_array = array();
1573+
foreach($xres->nodeset as $node){
1574+
$value_array[] = $node->get_content();
1575+
}
1576+
phpCAS::trace("* " . $name . "=" . $value_array);
1577+
$attr_array[$name] = $value_array;
15841578
}
1585-
else {
1586-
$this->_attributes[$attr_key] = $attr_value[0];
1579+
$_SESSION[SAML_ATTRIBUTES] = $attr_array;
1580+
// UGent addition...
1581+
foreach($attr_array as $attr_key => $attr_value) {
1582+
if(count($attr_value) > 1) {
1583+
$this->_attributes[$attr_key] = $attr_value;
1584+
}
1585+
else {
1586+
$this->_attributes[$attr_key] = $attr_value[0];
1587+
}
15871588
}
1589+
$result = TRUE;
1590+
}else{
1591+
phpCAS::trace("SAML Attributes are empty");
1592+
$result = FALSE;
15881593
}
1589-
$result = TRUE;
15901594
}
15911595
phpCAS::traceEnd($result);
15921596
return $result;

0 commit comments

Comments
 (0)