From 9637d8b853b97b4b24e0a90b0c49793949f2745c Mon Sep 17 00:00:00 2001 From: Alejandro Blanco Date: Mon, 16 Sep 2013 12:25:48 +0200 Subject: [PATCH 1/2] Fix parsing the mdUI Info - Fix mdUI info parsing. It assumed that the mdUI info can only appears in SP entities, and it tried to get the fields from there without checking if the SP variable actually exists. Now it tries to use a SP, and if it doesn't exist it falls back to an IdP. - Improve location parsing. It tries to split the location using ',' and if it can't then tries using '/'. If it still can't get the location data then it gives up and assume there is no location data instead of entering an infinite recursion loop that produced an error. --- samlmetajs/mdreader.js | 2 -- samlmetajs/samlmeta.plugin.info.js | 31 +++++++++++++++----------- samlmetajs/samlmeta.plugin.location.js | 12 +++++++++- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/samlmetajs/mdreader.js b/samlmetajs/mdreader.js index 5a34fac..4071a49 100644 --- a/samlmetajs/mdreader.js +++ b/samlmetajs/mdreader.js @@ -551,7 +551,6 @@ isHTTPS = function(string) { parseFromString = function(xmlstring) { - var doc = null; var result = {}; var entitydescriptor = null; @@ -1317,7 +1316,6 @@ parseFromString = function(xmlstring) { if (xmlstring) { try { validateXML(xmlstring); - doc = getDoc(xmlstring); entitydescriptor = parseEntityDescriptor(getDoc(xmlstring)); } catch (e) { console.log(e.message); diff --git a/samlmetajs/samlmeta.plugin.info.js b/samlmetajs/samlmeta.plugin.info.js index 007a56f..3a634fb 100644 --- a/samlmetajs/samlmeta.plugin.info.js +++ b/samlmetajs/samlmeta.plugin.info.js @@ -324,7 +324,12 @@ }, fromXML: function (entitydescriptor) { - var l; + var entityNode = entitydescriptor.saml2sp, + l; + + if (entityNode === undefined) { + entityNode = entitydescriptor.saml2idp; + } UI.clearInfoname(); if (entitydescriptor.name) { @@ -346,36 +351,36 @@ UI.clearInfologo(); if (entitydescriptor.hasLogo()) { - for (l in entitydescriptor.saml2sp.mdui.logo) { - if (entitydescriptor.saml2sp.mdui.logo.hasOwnProperty(l)) { - UI.addInfologo(l, entitydescriptor.saml2sp.mdui.logo[l]); + for (l in entityNode.mdui.logo) { + if (entityNode.mdui.logo.hasOwnProperty(l)) { + UI.addInfologo(l, entityNode.mdui.logo[l]); } } } UI.clearInfokeywords(); if (entitydescriptor.hasKeywords()) { - for (l in entitydescriptor.saml2sp.mdui.keywords) { - if (entitydescriptor.saml2sp.mdui.keywords.hasOwnProperty(l)) { - UI.addInfokeywords(l, entitydescriptor.saml2sp.mdui.keywords[l]); + for (l in entityNode.mdui.keywords) { + if (entityNode.mdui.keywords.hasOwnProperty(l)) { + UI.addInfokeywords(l, entityNode.mdui.keywords[l]); } } } UI.clearInformationURL(); if (entitydescriptor.hasInformationURL()) { - for (l in entitydescriptor.saml2sp.mdui.informationURL) { - if (entitydescriptor.saml2sp.mdui.informationURL.hasOwnProperty(l)) { - UI.addInformationURL(l, entitydescriptor.saml2sp.mdui.informationURL[l]); + for (l in entityNode.mdui.informationURL) { + if (entityNode.mdui.informationURL.hasOwnProperty(l)) { + UI.addInformationURL(l, entityNode.mdui.informationURL[l]); } } } UI.clearPrivacyStatementURL(); if (entitydescriptor.hasPrivacyStatementURL()) { - for (l in entitydescriptor.saml2sp.mdui.privacyStatementURL) { - if (entitydescriptor.saml2sp.mdui.privacyStatementURL.hasOwnProperty(l)) { - UI.addPrivacyStatementURL(l, entitydescriptor.saml2sp.mdui.privacyStatementURL[l]); + for (l in entityNode.mdui.privacyStatementURL) { + if (entityNode.mdui.privacyStatementURL.hasOwnProperty(l)) { + UI.addPrivacyStatementURL(l, entityNode.mdui.privacyStatementURL[l]); } } } diff --git a/samlmetajs/samlmeta.plugin.location.js b/samlmetajs/samlmeta.plugin.location.js index e7c5553..b95c2dd 100644 --- a/samlmetajs/samlmeta.plugin.location.js +++ b/samlmetajs/samlmeta.plugin.location.js @@ -121,10 +121,20 @@ if (entitydescriptor.hasLocation()) { location = entitydescriptor.getLocation(); - UI.setLocation(location); spl = location.split(','); + if (spl.length !== 2) { + spl = location.split('/'); + if (spl.length !== 2) { + // Bad location data + return; + } + } latLng = new google.maps.LatLng(spl[0], spl[1]); + location = latLng.toString(); + location = location.substring(1, location.length - 1); + + UI.setLocation(location); map.panTo(latLng); mapmarker.setPosition(latLng); UI.geocodePosition(latLng); From 9656a91b94a0122ca4eed775dfb3a7efd4d092a2 Mon Sep 17 00:00:00 2001 From: Alejandro Blanco Date: Wed, 16 Oct 2013 12:18:24 +0200 Subject: [PATCH 2/2] Fix reading mdui information from the sso --- samlmetajs/mdreader.js | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/samlmetajs/mdreader.js b/samlmetajs/mdreader.js index 4071a49..93dd5fa 100644 --- a/samlmetajs/mdreader.js +++ b/samlmetajs/mdreader.js @@ -1326,24 +1326,30 @@ parseFromString = function(xmlstring) { entitydescriptor = parseEntityDescriptor(getNewDoc()); } - - if (entitydescriptor.name) { - // Everthing is OK with the name. No need to override. - } else if (entitydescriptor.saml2sp && entitydescriptor.saml2sp.mdui && entitydescriptor.saml2sp.mdui.name) { - entitydescriptor.name = entitydescriptor.saml2sp.mdui.name; - } else if (entitydescriptor.saml2sp && entitydescriptor.saml2sp.acs && entitydescriptor.saml2sp.acs.name) { - entitydescriptor.name = entitydescriptor.saml2sp.acs.name; + if (!entitydescriptor.name) { + if (entitydescriptor.hasMDUIProperty('name')) { + mduiAux = entitydescriptor.getProperty('mdui'); + entitydescriptor.name = mduiAux.name; + } else if (entitydescriptor.hasProperty('acs')) { + mduiAux = entitydescriptor.getProperty('acs'); + if (hasProp(mduiAux, 'name')) { + entitydescriptor.name = mduiAux.name; + } + } } - if (entitydescriptor.descr) { - // Everthing is OK with the name. No need to override. - } else if (entitydescriptor.saml2sp && entitydescriptor.saml2sp.mdui && entitydescriptor.saml2sp.mdui.descr) { - entitydescriptor.descr = entitydescriptor.saml2sp.mdui.descr; - } else if (entitydescriptor.saml2sp && entitydescriptor.saml2sp.acs && entitydescriptor.saml2sp.acs.descr) { - entitydescriptor.descr = entitydescriptor.saml2sp.acs.descr; + if (!entitydescriptor.descr) { + if (entitydescriptor.hasMDUIProperty('descr')) { + mduiAux = entitydescriptor.getProperty('mdui'); + entitydescriptor.descr = mduiAux.descr; + } else if (entitydescriptor.hasProperty('acs')) { + mduiAux = entitydescriptor.getProperty('acs'); + if (hasProp(mduiAux, 'descr')) { + entitydescriptor.descr = mduiAux.descr; + } + } } - if (!entitydescriptor.name) { processTest(new TestResult('noentityname', 'The entity did not include a name', 0, 1)); }