@@ -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