[CalendarServer-changes] [6696] CalendarServer/trunk/contrib/performance/httpauth.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Dec 15 14:02:12 PST 2010
Revision: 6696
http://trac.macosforge.org/projects/calendarserver/changeset/6696
Author: exarkun at twistedmatrix.com
Date: 2010-12-15 14:02:09 -0800 (Wed, 15 Dec 2010)
Log Message:
-----------
HTTP Digest auth using the implementation in CalDAVClientLibrary
Modified Paths:
--------------
CalendarServer/trunk/contrib/performance/httpauth.py
Modified: CalendarServer/trunk/contrib/performance/httpauth.py
===================================================================
--- CalendarServer/trunk/contrib/performance/httpauth.py 2010-12-15 19:26:59 UTC (rev 6695)
+++ CalendarServer/trunk/contrib/performance/httpauth.py 2010-12-15 22:02:09 UTC (rev 6696)
@@ -14,16 +14,19 @@
# limitations under the License.
##
-import shlex, urlparse
+import urlparse, urllib2
from twisted.web.http_headers import Headers
+# CalDAVClientLibrary
+from protocol.http.authentication.digest import Digest
+
class BasicChallenge(object):
def __init__(self, realm):
self.realm = realm
- def response(self, uri, keyring):
+ def response(self, uri, method, keyring):
username, password = keyring.passwd.find_user_password(self.realm, uri)
credentials = ('%s:%s' % (username, password)).encode('base64').strip()
authorization = 'basic ' + credentials
@@ -31,6 +34,30 @@
+class DigestChallenge(object):
+ def __init__(self, realm, **fields):
+ self.realm = realm
+ self.fields = fields
+ self.fields['realm'] = realm
+
+
+ def response(self, uri, method, keyring):
+ username, password = keyring.passwd.find_user_password(self.realm, uri)
+ digest = Digest(username, password, [])
+ digest.fields.update(self.fields)
+ authorization = []
+
+ class BigSigh:
+ def getURL(self):
+ return uri
+ BigSigh.method = method
+ BigSigh.url = uri
+
+ digest.addHeaders(authorization, BigSigh())
+ return {'authorization': [value for (name, value) in authorization]}
+
+
+
class AuthHandlerAgent(object):
def __init__(self, agent, authinfo):
self._agent = agent
@@ -52,20 +79,23 @@
def _parse(self, authorization):
- parts = shlex.split(authorization)
- scheme = parts.pop(0)
- args = dict([p.split('=', 1) for p in parts])
- if scheme == 'basic':
- return BasicChallenge(**args)
- return None
+ scheme, rest = authorization.split(None, 1)
+ args = urllib2.parse_keqv_list(urllib2.parse_http_list(rest))
+ challengeType = {
+ 'basic': BasicChallenge,
+ 'digest': DigestChallenge,
+ }.get(scheme)
+ if challengeType is None:
+ return None
+ return challengeType(**args)
-
+
def _respondToChallenge(self, challenge, method, uri, headers, bodyProducer):
if headers is None:
headers = Headers()
else:
headers = Headers(dict(headers.getAllRawHeaders()))
- for k, vs in challenge.response(uri, self._authinfo).iteritems():
+ for k, vs in challenge.response(uri, method, self._authinfo).iteritems():
for v in vs:
headers.addRawHeader(k, v)
return self._agent.request(method, uri, headers, bodyProducer)
@@ -87,6 +117,7 @@
return response
+
if __name__ == '__main__':
from urllib2 import HTTPDigestAuthHandler
handler = HTTPDigestAuthHandler()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20101215/442ac32d/attachment-0001.html>
More information about the calendarserver-changes
mailing list