
On Wed, 28 Mar 2007 12:01:12 -0500, Justin Johnson <justinjohnson@gmail.com> wrote:
Hi,
I'm running Python 2.5 and Twisted 2.5.0 on Windows 2003 Server.
I have a web site (Twisted/Nevow) where users login with a username and password. I save the username and password once they login because the same username and password are used to connect to various Perspective Broker servers, and I don't want to make users reauthenticate for every server that is connected to behind the scenes. Since the password cannot be hashed when passed to PB I store it in plaintext.
Up to this point I have been using a realm and file password db as listed at the end of this email. When I recently upgraded from Twisted 2.4.0 to 2.5.0 and from Python 2.4 to 2.5 I get the following error.
2007/03/28 10:23 -0500 [Broker,0,IP_ADDRESS] Peer will receive following PB traceback: 2007/03/28 10:23 -0500 [Broker,0,IP_ADDRESS] Unhandled Error Traceback (most recent call last): File "D:\Python25\lib\site-packages\twisted\spread\pb.py", line 847, in _recvMessage netResult = object.remoteMessageReceived(self, message, netArgs, netKw) File "D:\Python25\lib\site-packages\twisted\spread\flavors.py", line 119, in remoteMessageReceived state = method(*args, **kw) File "D:\Python25\lib\site-packages\twisted\spread\pb.py", line 1217, in remote_respond d = self.portalWrapper.portal.login(self, mind, IPerspective) File "D:\Python25\lib\site-packages\twisted\cred\portal.py", line 109, in login return maybeDeferred(c.requestAvatarId, credentials --- <exception caught here> --- File "D:\Python25\lib\site-packages\twisted\internet\defer.py", line 107, in maybeDeferred result = f(*args, **kw) File "d:\python25\lib\site-packages\ratcontrol\login.py", line 195, in requestAvatarId up = credentials.IUsernamePassword(c) exceptions.TypeError: ('Could not adapt', <twisted.spread.pb._PortalAuthChallenger instance at 0x013E3760>,
<InterfaceClass twisted.cred.credentials.IUsernamePassword>)
2007/03/28 10:23 -0500 [Broker,client] Unhandled error in Deferred: 2007/03/28 10:23 -0500 [Broker,client] Unhandled Error Traceback from remote host -- Traceback unavailable
I looked at the Subversion log for twisted.spread.pb.py and am not sure what change is causing this failure. The contents of ratcontrol\login.py are below.
Does anyone have any pointers on what I should be looking for here? Is there any way I can accomplish my goal in a more maintainable way?
It's not clear to me how this worked in the first place. ;) The credentials object being adapted to IUsernamePassword should always have been a _PortalAuthChallenger, and so it only should have ever been adaptable to IUsernameHashedPassword and IUsernameMD5Password. The way you want to write requestAvatarId, though, is to inspect the credentials object to see what interfaces it provides and them handle it accordingly. You can do this by adapting and catching the TypeError, adapting with a default and checking for that, or using the providedBy method of the interface object. The important point is that you have to be able to handle every kind of credentials object which the you have declared you can handle (with the credentialInterfaces attribute). In this specific case, I believe your checker declared it could handle both IUsernamePassword and IUsernameHashedPassword, but its implementation can only actually handle IUsernameePassword. Hope this helps, Jean-Paul