def setup(self): self.json_config = self.json_config_file() _jc = self.json_config try: self.interactions = _jc["interaction"] except KeyError: self.interactions = [] self.idp_configure() metadata = MetadataStore(SCHEMA, self.idp_config.attribute_converters, self.idp_config) info = _jc["metadata"].encode("utf-8") md = MetaData(SCHEMA, self.idp_config.attribute_converters, info) md.load() metadata[0] = md self.idp.metadata = metadata #self.idp_config.metadata = metadata if self.args.testpackage: self.tests = import_module("sp_test.package.%s" % self.args.testpackage) try: self.entity_id = _jc["entity_id"] # Verify its the correct metadata assert self.entity_id in md.entity.keys() except KeyError: if len(md.entity.keys()) == 1: self.entity_id = md.entity.keys()[0] else: raise Exception("Don't know which entity to talk to") if "constraints" in _jc: self.constraints = _jc["constraints"] if "name_format" not in self.constraints: self.constraints["name_format"] = NAME_FORMAT_UNSPECIFIED
def handle_metadata_verify_json(self, environ, start_response, qs): """ Handles JSON metadata verifications. The post body must contains a JSON message like { 'xml' : 'a metadata file'} :param environ: wsgi enviroment :param start_response: wsgi start respons :param qs: Query parameters in a dictionary. :return: wsgi response contaning a JSON response. The JSON message will contain the parameter ok and services. ok will contain true if the metadata file can be parsed, otherwise false. services will contain a list of all the service names contained in the metadata file. """ ok = False services = "[]" try: if CONST_BODY in qs: json_message = json.loads(qs[CONST_BODY]) if "xml" in json_message: xml = json_message["xml"] xml = xml.strip() metadata_ok = False ci = None mds = MetadataStore( CONST_ONTS.values(), CONST_ATTRCONV, self.xmlsec_path, disable_ssl_certificate_validation=True) _md = MetaData(CONST_ONTS.values(), CONST_ATTRCONV, metadata=xml) try: _md.load() except: _logger.info( 'Could not parse the metadata file in handleMetadataVerifyJSON.', exc_info=True) else: entity_id = _md.entity.keys()[0] mds.metadata[entity_id] = _md args = {"metad": mds, "dkeys": [self.key]} ci = utils.ConsumerInfo(['metadata'], **args) metadata_ok = True services = "[" first = True if ci is not None: for item in ci.info: if item.ava is not None and entity_id in item.ava: for social in item.ava[entity_id]: if not first: services += "," else: first = False services += '"' + social + '"' services += "]" if metadata_ok: ok = True except: _logger.fatal('Unknown error in handleMetadataVerifyJSON.', exc_info=True) resp = Response('{"ok":"' + str(ok) + '", "services":' + services + '}', headers=[('Content-Type', CONST_TYPEJSON)]) return resp(environ, start_response)