1
# Copyright (c) 2008 Divmod. See LICENSE for details.
4
An AMP server which requires authentication of its clients before exposing an
10
from twisted.python.log import startLogging, msg
11
from twisted.internet import reactor
12
from twisted.cred.portal import Portal
13
from twisted.protocols.amp import IBoxReceiver, Command, Integer, AMP
15
from epsilon.ampauth import CredAMPServerFactory, OneTimePadChecker
20
An example of an application-defined command which should be made available
21
to clients after they successfully authenticate.
23
arguments = [("left", Integer()),
26
response = [("sum", Integer())]
32
An example of an application-defined AMP protocol, the responders defined
33
by which should only be available to clients after they have successfully
36
def __init__(self, avatarId):
38
self.avatarId = avatarId
42
def add(self, left, right):
43
msg("Adding %d to %d for %s" % (left, right, self.avatarId))
44
return {'sum': left + right}
48
class AdditionRealm(object):
50
An example of an application-defined realm.
52
def requestAvatar(self, avatarId, mind, *interfaces):
54
Create Adder avatars for any IBoxReceiver request.
56
if IBoxReceiver in interfaces:
57
return (IBoxReceiver, Adder(avatarId), lambda: None)
58
raise NotImplementedError()
64
Start the AMP server and the reactor.
67
checker = OneTimePadChecker({'pad': 0})
68
realm = AdditionRealm()
69
factory = CredAMPServerFactory(Portal(realm, [checker]))
70
reactor.listenTCP(7805, factory)
74
if __name__ == '__main__':