[Erp5-report] r23567 - /erp5/trunk/products/ERP5Wizard/Tool/WizardTool.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Sep 11 15:48:49 CEST 2008
Author: ivan
Date: Thu Sep 11 15:48:44 2008
New Revision: 23567
URL: http://svn.erp5.org?rev=23567&view=rev
Log:
Use cookie authentication in order to fully emulate a browser viewing a page.
Modified:
erp5/trunk/products/ERP5Wizard/Tool/WizardTool.py
Modified: erp5/trunk/products/ERP5Wizard/Tool/WizardTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Wizard/Tool/WizardTool.py?rev=23567&r1=23566&r2=23567&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Wizard/Tool/WizardTool.py (original)
+++ erp5/trunk/products/ERP5Wizard/Tool/WizardTool.py Thu Sep 11 15:48:44 2008
@@ -46,6 +46,21 @@
cookiejar = cookielib.CookieJar()
referer = None
+def _isUserAcknowledged(cookiejar):
+ """ Is user authenticated to remote system through a cookie. """
+ for cookie in cookiejar:
+ if cookie.name == '__ac' and cookie.value != '':
+ return 1
+ return 0
+
+def _getAcCookieFromServer(url, opener, cookiejar, username, password, header_dict = {}):
+ """ get __ac cookie from server """
+ data = urllib.urlencode({'__ac_name': username,
+ '__ac_password': password})
+ request = urllib2.Request(url, data, header_dict)
+ f = opener.open(request)
+ return f
+
def _setSuperSecurityManager(self):
""" Change to super user account. """
user = self.getWrappedOwner()
@@ -272,8 +287,18 @@
user_and_password = self._getSubsribedUserAndPassword()
if (len(user_and_password)==2 and
user_and_password[0] and user_and_password[1]):
- auth = 'Basic %s' % base64.standard_b64encode('%s:%s' % user_and_password)
- header_dict['Authorization'] = auth
+ # try login to server only once using cookie method
+ if not _isUserAcknowledged(cookiejar):
+ server_url = self.getServerUrl()
+ f = _getAcCookieFromServer('%s/WebSite_login' %server_url,
+ self.simple_opener_director,
+ cookiejar,
+ user_and_password[0],
+ user_and_password[1])
+ # if server doesn't support cookie authentication try basic authentication
+ if not _isUserAcknowledged(cookiejar):
+ auth = 'Basic %s' % base64.standard_b64encode('%s:%s' % user_and_password)
+ header_dict['Authorization'] = auth
if content_type:
header_dict['Content-Type'] = content_type
More information about the Erp5-report
mailing list