Changeset 1356
- Timestamp:
- 09/11/06 17:04:28
- Files:
-
- trunk/cherrypy/lib/auth.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/auth.py
r1355 r1356 1 import md52 1 import cherrypy 3 4 from httpauth import parseAuthorization, checkResponse, basicAuth, digestAuth 2 from cherrypy.lib import httpauth 5 3 6 4 … … 9 7 if 'authorization' in cherrypy.request.headers: 10 8 # make sure the provided credentials are correctly set 11 ah = parseAuthorization(cherrypy.request.headers['authorization'])9 ah = httpauth.parseAuthorization(cherrypy.request.headers['authorization']) 12 10 if ah is None: 13 11 raise cherrypy.HTTPError(400, 'Bad Request') 14 12 15 13 if not encrypt: 16 encrypt = lambda x: md5.new(x).hexdigest()17 14 encrypt = httpauth.DIGEST_AUTH_ENCODERS[httpauth.MD5] 15 18 16 if callable(users): 19 17 users = users() # expect it to return a dictionary 20 18 21 19 if not isinstance(users, dict): 22 raise ValueError, "Authentication users must be passed contained ina dictionary"23 20 raise ValueError, "Authentication users must be a dictionary" 21 24 22 # fetch the user password 25 23 password = users.get(ah["username"], None) … … 27 25 # validate the authorization by re-computing it here 28 26 # and compare it with what the user-agent provided 29 if checkResponse(ah, password, method=cherrypy.request.method, encrypt=encrypt): 27 if httpauth.checkResponse(ah, password, method=cherrypy.request.method, 28 encrypt=encrypt): 30 29 return True 31 30 … … 44 43 45 44 # inform the user-agent this path is protected 46 cherrypy.response.headers['www-authenticate'] = basicAuth(realm)45 cherrypy.response.headers['www-authenticate'] = httpauth.basicAuth(realm) 47 46 48 47 raise cherrypy.HTTPError(401, "You are not authorized to access that resource") … … 58 57 59 58 # inform the user-agent this path is protected 60 cherrypy.response.headers['www-authenticate'] = digestAuth(realm)59 cherrypy.response.headers['www-authenticate'] = httpauth.digestAuth(realm) 61 60 62 61 raise cherrypy.HTTPError(401, "You are not authorized to access that resource")

