- # check if we're done
- self.saml_result.update(fd, server=urlparse(uri).netloc)
- GLib.timeout_add(1000, self.check_done)
+ fd = {}
+ for comment in html_parser.comments:
+ if self.verbose > 1:
+ print("[SAML ] Found comment in response body: '%s'" % comment, file=stderr)
+ try:
+ # xml parser requires valid xml with a single root tag, but our expected content
+ # is just a list of data tags, so we need to improvise
+ xmlroot = ET.fromstring("<fakexmlroot>%s</fakexmlroot>" % comment)
+ # search for any valid first level xml tags (inside our fake root) that could contain SAML data
+ for elem in xmlroot:
+ if elem.tag.startswith("saml-") or elem.tag in COOKIE_FIELDS:
+ fd[elem.tag] = elem.text
+ except ET.ParseError:
+ pass # silently ignore any comments that don't contain valid xml
+
+ if self.verbose > 1:
+ print("[SAML ] Finished parsing response body for %s" % resource.get_uri(), file=stderr)
+ if fd:
+ if self.verbose:
+ print("[SAML ] Got SAML result tags: %s" % fd, file=stderr)
+ self.saml_result.update(fd, server=urlparse(resource.get_uri()).netloc)
+
+ if not self.check_done():
+ # Work around timing/race condition by retrying check_done after 1 second
+ GLib.timeout_add(1000, self.check_done)