Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _select_username_password_polices(self, xpath):
policies = {}
username_token_nodes = xmlutil.xpath_find(self._dom, xpath)
if not username_token_nodes:
self._log.warn("No username token policy nodes found.")
return
for node in username_token_nodes:
policy_node = self._parents[self._parents[self._parents[self._parents[self._parents[self._parents[self._parents[node]]]]]]]
policy_id = self._check_policy(policy_node)
if policy_id:
id_ref = '#' + policy_id
policies[id_ref] = {policy_id:id_ref}
return policies if policies else None
def _check_policy(self, policy_node):
policy_id = policy_node.attrib["{{{}}}Id".format(XmlNamespaces.namespaces['wsu'])]
# Try with Transport Binding XPath
transport_binding_nodes = xmlutil.xpath_find(policy_node, TRANSPORT_BINDING_XPATH)
# If unsuccessful, try again with 2005 XPath
if not transport_binding_nodes:
transport_binding_nodes = xmlutil.xpath_find(policy_node, TRANSPORT_BINDING_2005_XPATH)
# If we did not find any binding, this is potentially bad.
if not transport_binding_nodes:
self._log.debug(
"Potential policy did not match required transport binding: %(policy_id)s",
{"policy_id": policy_id})
else:
self._log.debug("Found matching policy id: %(policy_id)s",
{"policy_id": policy_id})
return policy_id
def _check_soap_action_and_transport(self, binding_node):
soap_action = ""
soap_transport = ""
name = binding_node.get('name')
soap_transport_attributes = ""
soap_action_attributes = xmlutil.xpath_find(binding_node, SOAP_ACTION_XPATH)[0].attrib['soapAction']
if soap_action_attributes:
soap_action = soap_action_attributes
soap_transport_attributes = xmlutil.xpath_find(binding_node, SOAP_TRANSPORT_XPATH)[0].attrib['transport']
if soap_transport_attributes:
soap_transport = soap_transport_attributes
if soap_transport == SOAP_HTTP_TRANSPORT_VALUE:
if soap_action == RST_SOAP_ACTION_13:
self._log.debug(
'found binding matching Action and Transport: %(binding_node)s',
{"binding_node": name})
return WSTrustVersion.WSTRUST13
elif soap_action == RST_SOAP_ACTION_2005:
self._log.debug(
def _check_policy(self, policy_node):
policy_id = policy_node.attrib["{{{}}}Id".format(XmlNamespaces.namespaces['wsu'])]
# Try with Transport Binding XPath
transport_binding_nodes = xmlutil.xpath_find(policy_node, TRANSPORT_BINDING_XPATH)
# If unsuccessful, try again with 2005 XPath
if not transport_binding_nodes:
transport_binding_nodes = xmlutil.xpath_find(policy_node, TRANSPORT_BINDING_2005_XPATH)
# If we did not find any binding, this is potentially bad.
if not transport_binding_nodes:
self._log.debug(
"Potential policy did not match required transport binding: %(policy_id)s",
{"policy_id": policy_id})
else:
self._log.debug("Found matching policy id: %(policy_id)s",
{"policy_id": policy_id})
return policy_id
def _check_soap_action_and_transport(self, binding_node):
soap_action = ""
soap_transport = ""
name = binding_node.get('name')
soap_transport_attributes = ""
soap_action_attributes = xmlutil.xpath_find(binding_node, SOAP_ACTION_XPATH)[0].attrib['soapAction']
if soap_action_attributes:
soap_action = soap_action_attributes
soap_transport_attributes = xmlutil.xpath_find(binding_node, SOAP_TRANSPORT_XPATH)[0].attrib['transport']
if soap_transport_attributes:
soap_transport = soap_transport_attributes
if soap_transport == SOAP_HTTP_TRANSPORT_VALUE:
if soap_action == RST_SOAP_ACTION_13:
self._log.debug(
'found binding matching Action and Transport: %(binding_node)s',
{"binding_node": name})
return WSTrustVersion.WSTRUST13
elif soap_action == RST_SOAP_ACTION_2005:
self._log.debug(
'found binding matching Action and Transport: %(binding_node)s',
{"binding_node": name})
return WSTrustVersion.WSTRUST2005