示例#1
0
 def get_authorizer(self):
     warnings.warn(
         "Application.authorizer attribute is deprecated, use Service.authorizer instead",
         category=DeprecationWarning,
         stacklevel=3)
     if not self._authorizer:
         self._authorizer = DefaultAuthorizer()
         self._authorizer.setApplication(self)
     return self._authorizer
示例#2
0
def updateApplication(app, config):
    profileTable=McFoo.score.ProfileTable()
    filler=McFoo.suggest.Suggestions(config.songdirs, profileTable)
    playqueue = McFoo.playqueue.PlayQueue(filler.get)

    volume = McFoo.volume.VolumeControl()
    auth = DefaultAuthorizer()
    auth.setApplication(app)
    dj=McFoo.dj.Dj(app, auth,
                   playqueue, volume, profileTable)

    perspective=dj.getPerspectiveNamed("guest")
    perspective.setService(dj)
    perspective.makeIdentity("guest")

    portno = config.port
    prot = pb.BrokerFactory(pb.AuthRoot(auth))

    app.listenTCP(portno, prot)
    SaveService("save", app, auth)
示例#3
0
    def testPerspectiveInit(self):
        # TODO: this is an awful lot of crap to have to import / do in order to
        # create a functional authentication system.  Cut down on it.
        from twisted.internet.app import MultiService
        ms = MultiService("hello")
        from twisted.cred.authorizer import DefaultAuthorizer
        auth = DefaultAuthorizer(ms)
        from twisted.cred.service import Service
        svc = Service("test_service", ms, auth)
        myp = svc.createPerspective("test")
        myp.makeIdentity("test")

        sessWrapped = static.Data("you should never see this", "text/plain")
        swChild = static.Data("NO", "text/plain")
        sessWrapped.putChild("yyy",swChild)
        da = static.Data("b","text/plain")
        q = static.Data("you should never see this either", "text/plain")
        q.putChild("yyy", static.Data("YES", "text/plain"))
        authFactory = lambda p, q=q: q
        pwrap = guard.PerspectiveWrapper(svc, sessWrapped, authFactory)
        swrap = guard.SessionWrapper(pwrap)
        da.putChild("xxx", swrap)
        st = FakeSite(da)
        chan = FakeHTTPChannel()
        chan.site = st

        req = chan.makeFakeRequest("/xxx/"+guard.INIT_SESSION+"/yyy")
        req = chan.makeFakeRequest("/xxx/yyy")
        self.assertEquals(req.written.getvalue(),"NO")
        req = chan.makeFakeRequest("/xxx/"+guard.INIT_PERSPECTIVE+
                                   "?identity=test&password=tenxt")
        assert not req.session.services.values()
        req = chan.makeFakeRequest("/xxx/"+guard.INIT_PERSPECTIVE+
                                   "?identity=test&password=test")
        self.assertEquals(req.session.services.values()[0][0], myp)
        # print req.written.getvalue()
        req = chan.makeFakeRequest("/xxx/yyy")
        self.assertEquals(req.written.getvalue(), "YES")
        # print req.session.services
        for sz in swrap.sessions.values():
            sz.expire()
示例#4
0
def main():
    """..."""
    from twisted.spread import pb
    from twisted.application import service
    from twisted.cred.authorizer import DefaultAuthorizer
    from twisted.internet import reactor, app

    evManager = EventManager()
    sharedObjectRegistry = {}

    log = TextLogView(evManager)
    timer = TimerController(evManager, reactor)
    #clientContr = NetworkClientController( evManager, sharedObjectRegistry )
    clientView = NetworkClientView(evManager, sharedObjectRegistry)
    game = Game(evManager)

    #from twisted.spread.jelly import globalSecurity
    #globalSecurity.allowModules( network )

    application = app.Application("myServer")
    auth = DefaultAuthorizer(application)

    #create a service, tell it to generate NetworkClientControllers
    serv = pb.Service("myService", application, auth)
    serv.perspectiveClass = NetworkClientController

    #create a Perspective
    per1 = serv.createPerspective("perspective1")
    per1.PostInit(evManager, sharedObjectRegistry)

    #create an Identity
    iden1 = auth.createIdentity("user1")
    iden1.setPassword("asdf")
    #allow it access to the perspective named perspective1
    iden1.addKeyByString("myService", "perspective1")
    auth.addIdentity(iden1)

    #application.listenTCP(8000, pb.BrokerFactory(clientContr) )
    application.listenTCP(8000, pb.PBServerFactory(pb.AuthRoot(auth)))

    application.run(save=0)
# Import Twisted code
from twisted.spread.pb import AuthRoot, BrokerFactory, portno
from twisted.internet.app import Application
from twisted.cred.authorizer import DefaultAuthorizer
# Import our own library
import cellphone
import metamorph
# Create root-level object and authorizer
app = Application("Metamorphosis")
auth = DefaultAuthorizer(app)
# Create our services (inside the App directory)
phoneCompany = cellphone.PhoneCompany("cellphone", app, auth)
buggyWorld = metamorph.BuggyWorld("metamorph", app, auth)
# Create Identities for Joe and Bob.

def makeAccount(userName, phoneNumber, bugName, pw):
    # Create a cell phone for the player, so they can chat.
    phone = phoneCompany.createPerspective(phoneNumber)
    # Create a bug for the player, so they can play the game.
    bug = buggyWorld.createPerspective(bugName)
    # Create an identity for the player, so they can log in.
    i = auth.createIdentity(userName)
    i.setPassword(pw)
    # add perspectives to identity we created
    i.addKeyForPerspective(phone)
    i.addKeyForPerspective(bug)
    # Finally, commit the identity back to its authorizer.
    i.save()

# Create both Bob's and Joe's accounts.
makeAccount("joe", "222-303-8484", "fritz", "joepass")
示例#6
0
 def upgradeToVersion1(self):
     """Version 1 Persistence Upgrade
     """
     log.msg("Upgrading %s Application." % repr(self.name))
     self.authorizer = DefaultAuthorizer()
     self.services = {}