6
# Server based on using TLS to store session data.
7
# It uses client authentication to get the user name for the session.
11
This is the storage server that depends on TLS and multithreading.
12
It uses client connection authentication to identify the client that
13
belongs to the connection, instead of simply storing a client identifier
14
that is passed in via a remote method call."""
18
# It will store lines of text in a file named after the 'user'.
19
# The resource that is owned by this user session (the file handle) is stored on the TLS.
20
class DataStoreAuth(Pyro.core.ObjBase):
22
# use the username set on the connection object (by the ConnValidator)
23
tls=self.getLocalStorage()
24
tls.username=tls.caller.username
25
tls.datastore=open("datastorage_%s.txt" % tls.username,"w")
27
def addline(self, textline):
28
tls=self.getLocalStorage()
29
sys.stdout.write("adding line to "+tls.datastore.name+"\n")
31
tls.datastore.write(textline+" | user="+tls.username+" | came from "+str(tls.caller)+"\n")
34
tls=self.getLocalStorage()
38
# The Connection Validator, server side
39
# This is only an example, don't use it like this in your own code!
40
class SimpleServersideConnValidator(Pyro.protocol.DefaultConnValidator):
41
def acceptIdentification(self, daemon, connection, token, challenge):
42
# The token will be the username:password string, received from the client.
43
login, password = token.split(':', 1)
44
if password!="secretpassw0rd":
45
return (0,Pyro.constants.DENIED_SECURITY)
46
# We store the login name on the connection object to refer to it later.
47
connection.username=login
51
daemon=Pyro.core.Daemon()
52
ns=Pyro.naming.NameServerLocator().getNS()
53
daemon.useNameServer(ns)
54
daemon.setNewConnectionValidator( SimpleServersideConnValidator() )
57
ns.createGroup(":test")
61
ns.unregister(":test.datastorage_auth")
65
daemon.connect(DataStoreAuth(), ":test.datastorage_auth")
67
print "Server (auth) is running."