[Twisted-Python] Perspective Broker Anonymous access..

I´m just learning how to use twisted PB and playing with the chat server... I´m trying to create a way to allow authenticated and anonymous users into the system but can't figure how to make it. Here what i´m trying to do: ----------SERVER------------ def requestAvatar(self, avatarId, mind, *interfaces): assert pb.IPerspective in interfaces return pb.IPerspective, MyPerspective(avatarId), lambda:None p = portal.Portal(MyRealm()) c = checkers.InMemoryUsernamePasswordDatabaseDontUse(user1="pass1", user2="pass2") p.registerChecker(checkers.AllowAnonymousAccess(), credentials.Anonymous()) p.registerChecker(c) reactor.listenTCP(8800, pb.PBServerFactory(p)) reactor.run() ----------------------------- CLIENT factory = pb.PBClientFactory() reactor.connectTCP("localhost", 8800, factory) def1 = factory.login(credentials.Anonymous()) def1.addCallback(connected) reactor.run() ----------------------------- It dont work this way, giving me this error: Traceback (most recent call last): Failure: twisted.cred.error.UnauthorizedLogin: Another way i tried to register only the AllowAnonymousAccess in the server but the following error popped: Traceback (most recent call last): Failure: twisted.cred.error.UnhandledCredentials: No checker for twisted.cred.cr edentials.IUsernameHashedPassword, twisted.spread.pb.IUsernameMD5Password, twist ed.spread.interfaces.IJellyable Looks like PB doesn´t support anonymous access but from documentation i saw that i can do the following: # anonymous users share one Avatar, named users each get their own def requestAvatar(self, avatarID, mind, *interfaces): assert pb.IPerspective in interfaces if avatarID == checkers.ANONYMOUS: return pb.IPerspective, self.anonAvatar, lambda:None else: return pb.IPerspective, self.avatars[avatarID], lambda:None Just dont know how.... I already checked the PB internals (pb, portal, checkers, credentials) and havent figured out how to add anonymous support to PB... if you guys could help me I´m commited to add this support... Thanks for all, Carlos Eduardo

Jean-Paul Calderone <exarkun <at> divmod.com> writes:
So, the examples given in http://twistedmatrix.com/projects/core/documentation/howto/pb-cred.html (below) doesnt works? # anonymous users share one Avatar, named users each get their own def requestAvatar(self, avatarID, mind, *interfaces): assert pb.IPerspective in interfaces if avatarID == checkers.ANONYMOUS: return pb.IPerspective, self.anonAvatar, lambda:None else: return pb.IPerspective, self.avatars[avatarID], lambda:None I was looking at pb.py, portal.py and the way i understood, the whole chain (login -> cbSendUsername -> remote login -> cb_Response -> remote respond) is the responsible by the login process... if we send like credentials.Anonymous in login(), all this chain needs to handle it... right? Its a little strange why we cant have authenticated and anonymous users sharing the same process since we can filter in the avatar given the permissions (like example above). Another question... is it interesting to twisted project to have this kind of support? I mean, is it important to provide a way to this support in a patch to the project or should I do modifications I need (if i learn how to) and keep them to me? Thanks for all and sorry if these questions are not in scope... Carlos

Jean-Paul Calderone <exarkun <at> divmod.com> writes:
So, the examples given in http://twistedmatrix.com/projects/core/documentation/howto/pb-cred.html (below) doesnt works? # anonymous users share one Avatar, named users each get their own def requestAvatar(self, avatarID, mind, *interfaces): assert pb.IPerspective in interfaces if avatarID == checkers.ANONYMOUS: return pb.IPerspective, self.anonAvatar, lambda:None else: return pb.IPerspective, self.avatars[avatarID], lambda:None I was looking at pb.py, portal.py and the way i understood, the whole chain (login -> cbSendUsername -> remote login -> cb_Response -> remote respond) is the responsible by the login process... if we send like credentials.Anonymous in login(), all this chain needs to handle it... right? Its a little strange why we cant have authenticated and anonymous users sharing the same process since we can filter in the avatar given the permissions (like example above). Another question... is it interesting to twisted project to have this kind of support? I mean, is it important to provide a way to this support in a patch to the project or should I do modifications I need (if i learn how to) and keep them to me? Thanks for all and sorry if these questions are not in scope... Carlos
participants (2)
-
Carlos Eduardo
-
Jean-Paul Calderone