Beispiel #1
0
 def _parse_oidc_backends_config(self, config_file):
     self.oidc_backends_config = {}
     self.oidc_backends_implementation = {}
     try:
         tree = parse_xml(config_file)
         root = tree.getroot()
         if root.tag != 'OIDC':
             raise etree.ParseError("The root element in OIDC config xml file is expected to be `OIDC`, "
                              "found `{}` instead -- unable to continue.".format(root.tag))
         for child in root:
             if child.tag != 'provider':
                 log.error("Expect a node with `provider` tag, found a node with `{}` tag instead; "
                           "skipping the node.".format(child.tag))
                 continue
             if 'name' not in child.attrib:
                 log.error("Could not find a node attribute 'name'; skipping the node '{}'.".format(child.tag))
                 continue
             idp = child.get('name').lower()
             if idp in BACKENDS_NAME:
                 self.oidc_backends_config[idp] = self._parse_idp_config(child)
                 self.oidc_backends_implementation[idp] = 'psa'
                 self.app.config.oidc[idp] = {'icon': self._get_idp_icon(idp)}
             elif idp in KEYCLOAK_BACKENDS:
                 self.oidc_backends_config[idp] = self._parse_custos_config(child)
                 self.oidc_backends_implementation[idp] = 'custos'
                 self.app.config.oidc[idp] = {'icon': self._get_idp_icon(idp)}
             else:
                 raise etree.ParseError("Unknown provider specified")
         if len(self.oidc_backends_config) == 0:
             raise etree.ParseError("No valid provider configuration parsed.")
     except ImportError:
         raise
     except etree.ParseError as e:
         raise etree.ParseError("Invalid configuration at `{}`: {} -- unable to continue.".format(config_file, e))
Beispiel #2
0
 def _parse_oidc_config(self, config_file):
     self.oidc_config = {}
     try:
         tree = parse_xml(config_file)
         root = tree.getroot()
         if root.tag != 'OIDC':
             raise etree.ParseError("The root element in OIDC_Config xml file is expected to be `OIDC`, "
                              "found `{}` instead -- unable to continue.".format(root.tag))
         for child in root:
             if child.tag != 'Setter':
                 log.error("Expect a node with `Setter` tag, found a node with `{}` tag instead; "
                           "skipping this node.".format(child.tag))
                 continue
             if 'Property' not in child.attrib or 'Value' not in child.attrib or 'Type' not in child.attrib:
                 log.error("Could not find the node attributes `Property` and/or `Value` and/or `Type`;"
                           " found these attributes: `{}`; skipping this node.".format(child.attrib))
                 continue
             try:
                 if child.get('Type') == "bool":
                     func = string_as_bool
                 else:
                     func = getattr(builtins, child.get('Type'))
             except AttributeError:
                 log.error("The value of attribute `Type`, `{}`, is not a valid built-in type;"
                           " skipping this node").format(child.get('Type'))
                 continue
             self.oidc_config[child.get('Property')] = func(child.get('Value'))
     except ImportError:
         raise
     except etree.ParseError as e:
         raise etree.ParseError("Invalid configuration at `{}`: {} -- unable to continue.".format(config_file, e))