@@ -190,7 +190,12 @@ function ADFS_PostResponse($url, $wresult, $wctx) {
190190
191191 $ spentityid = $ requestcache ['Issuer ' ];
192192 $ spmetadata = SimpleSAML_Configuration::getConfig ('adfs-sp-remote.php ' );
193- $ spmetadata = SimpleSAML_Configuration::loadFromArray ($ spmetadata ->getValue ($ spentityid ));
193+
194+ $ arr = $ spmetadata ->getValue ($ spentityid );
195+ if (!isset ($ arr )) {
196+ throw new Exception ('Metadata for ADFS SP " ' . $ spentityid . '" could not be found in adfs-sp-remote.php! ' );
197+ }
198+ $ spmetadata = SimpleSAML_Configuration::loadFromArray ($ arr );
194199
195200 $ sp_name = $ spmetadata ->getValue ('name ' , $ spentityid );
196201
@@ -241,8 +246,17 @@ function ADFS_PostResponse($url, $wresult, $wctx) {
241246 if (array_key_exists ('RelayState ' , $ requestcache )) $ relayState = $ requestcache ['RelayState ' ];
242247
243248 $ nameid = $ session ->getNameID ();
249+ $ nameid = $ nameid ['value ' ];
250+
251+ $ nameidattribute = $ spmetadata ->getValue ('simplesaml.nameidattribute ' );
252+ if (isset ($ nameidattribute )) {
253+ if (!array_key_exists ($ nameidattribute , $ attributes )) {
254+ throw new Exception ('simplesaml.nameidattribute does not exist in resulting attribute set ' );
255+ }
256+ $ nameid = $ attributes [$ nameidattribute ][0 ];
257+ }
244258
245- $ response = ADFS_GenerateResponse ($ idpentityid , $ spentityid , $ nameid[ ' value ' ] , $ attributes );
259+ $ response = ADFS_GenerateResponse ($ idpentityid , $ spentityid , $ nameid , $ attributes );
246260 $ wresult = ADFS_SignResponse ($ response , $ config ->getPathValue ('certdir ' ) . $ adfsconfig ->getValue ('key ' ), $ config ->getPathValue ('certdir ' ) . $ adfsconfig ->getValue ('cert ' ));
247261
248262 ADFS_PostResponse ($ spmetadata ->getValue ('prp ' ), $ wresult , $ relayState );
0 commit comments