[Twisted-Python] PB and Woven authentication

Justin Johnson justinjohnson at fastmail.fm
Tue Oct 7 07:49:44 MDT 2003


I know there have been other posts on this topic, but I wasn't sure how
up-to-date they are.

I currently have a PB server that I connect to via the command line.  It
allows me to do tasks on wintel servers I manage.  I'm now trying to
create a web interface to that service using woven.

Below is what I'm currently doing for authentication.

First of all, am I doing things right below?  Any corrections or
suggestions for improvement?

Once that is correct, how do I hook this up to woven?  I was trying to
look through the Quotient code to figure it out, but there is so much
other stuff in there I'm having a hard time keeping it all straight.

Thanks much.
-Justin


***** SERVER SIDE *****
----
class RatControlRealm:
    def __init__(self):
        self.p = RatControlPerspective("admin")
                                                                                
    def requestAvatar(self, avatarId, mind, interface):
        assert interface == pb.IPerspective
        assert mind == "BRAINS!"
        self.p.loggedIn = 1
        return pb.IPerspective, self.p, self.p.logout
                                                                                

from twisted.cred import portal, checkers, credentials
realm = RatControlRealm()
portal = portal.Portal(realm)
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
checker.addUser(config.adminUser, config.adminPassword)
portal.registerChecker(checker)
                                                                                
factory = pb.PBServerFactory(portal)
reactor.listenTCP(config.portNumber, factory)
reactor.run()
--------

***** CLIENT SIDE *****
-----
    def connectToServer(self, server):
        def _cbSuccess(perspective):
            return perspective
        def _cbFailure(failure):
            print "Failed to connect to '%s'." % server
            return failure
        factory = pb.PBClientFactory()
        reactor.connectTCP(server, config.portNumber, factory)
        d = factory.login(credentials.UsernamePassword(config.adminUser,
        config.adminPassword), "BRAINS!")
        d.addCallbacks(_cbSuccess, _cbFailure)
        return d
------




More information about the Twisted-Python mailing list