Exemplo n.º 1
0
    def _post_xml(self, xml, **kwargs):
        # Lock them out if too many bad auth attempts
        if NetConnect.failed_auth_attempts >= constants.MAX_AUTH_ATTEMPTS:
            raise exceptions.MaxAuthAttemptsException()

        url = self.ecals.get_net_connect_url()

        _log_pretty_xml(xml, "request")

        logging.info("Net Connect URL: %s" % url)

        data = "NETCONNECT_TRANSACTION=%s" % (urllib.quote_plus(xml))
        headers = {"Content-Type": "application/x-www-form-urlencoded"}
        auth = (self.config["user_id"], self.config["user_pw"])

        response = session.get_session().post(url, headers=headers, auth=auth, data=data, **kwargs)

        logging.info(response.text)

        if re.search("^<\?xml", response.text, re.IGNORECASE):
            _log_pretty_xml(response.text, "response")

            NetConnect.failed_auth_attempts = 0

        elif re.search("^<(!DOCTYPE )?html", response.text, re.IGNORECASE):

            # TODO using DEMO environment this is the only way to test for bad AUTH.
            if re.search("app\.logonUrl", response.text):
                NetConnect.failed_auth_attempts += 1
                raise exceptions.FailedAuthException()
            elif re.search("changepw", response.text):
                raise exceptions.PasswordExpiredException()

        return response.text
Exemplo n.º 2
0
 def _fetch_net_connect_url(self):
     logging.info("Fetching new Net Connect URL from ECALS.")
     response = session.get_session().get(self.ecals_url)
     if response.status_code == constants.HTTP_STATUS_OK:
         net_connect_url = response.text
         if Ecals.is_valid_net_connect_url(net_connect_url):
             return net_connect_url
         else:
             raise exceptions.InvalidNetConnectUrlException()
     else:
         raise exceptions.EcalsLookupException()
Exemplo n.º 3
0
 def _fetch_net_connect_url(self):
     logging.info("Fetching new Net Connect URL from ECALS.")
     response = session.get_session().get(self.ecals_url)
     if response.status_code == constants.HTTP_STATUS_OK:
         net_connect_url = response.text
         if Ecals.is_valid_net_connect_url(net_connect_url):
             return net_connect_url
         else:
             raise exceptions.InvalidNetConnectUrlException()
     else:
         raise exceptions.EcalsLookupException()
Exemplo n.º 4
0
    def _post_xml(self, xml, **kwargs):
        # Lock them out if too many bad auth attempts
        if NetConnect.failed_auth_attempts >= constants.MAX_AUTH_ATTEMPTS:
            raise exceptions.MaxAuthAttemptsException()

        url = self.ecals.get_net_connect_url()

        _log_pretty_xml(xml, 'request')

        logging.info("Net Connect URL: %s" % url)

        data = "NETCONNECT_TRANSACTION=%s" % (urllib.quote_plus(xml))
        headers = {'Content-Type': 'application/x-www-form-urlencoded'}
        auth = (self.config['user_id'], self.config['user_pw'])

        response = session.get_session().post(url,
                                              headers=headers,
                                              auth=auth,
                                              data=data,
                                              **kwargs)

        logging.info(response.text)

        if re.search('^<\?xml', response.text, re.IGNORECASE):
            _log_pretty_xml(response.text, 'response')

            NetConnect.failed_auth_attempts = 0

        elif re.search('^<(!DOCTYPE )?html', response.text, re.IGNORECASE):

            # TODO using DEMO environment this is the only way to test for bad AUTH.
            if re.search('app\.logonUrl', response.text):
                NetConnect.failed_auth_attempts += 1
                raise exceptions.FailedAuthException()
            elif re.search('changepw', response.text):
                raise exceptions.PasswordExpiredException()

        return response.text