~ubuntu-branches/debian/sid/pyro/sid

« back to all changes in this revision

Viewing changes to examples/sessions/auth_server.py

  • Committer: Bazaar Package Importer
  • Author(s): Carl Chenet, Carl Chenet, Jakub Wilk
  • Date: 2010-09-14 01:04:28 UTC
  • Revision ID: james.westby@ubuntu.com-20100914010428-02r7p1rzr7jvw94z
Tags: 1:3.9.1-2
[Carl Chenet]
* revert to 3.9.1-1 package because of the development status 
  of the 4.1 package is unsuitable for stable use
  DPMT svn #8557 revision (Closes: #589172) 
* added debian/source
* added debian/source/format
* package is now 3.0 (quilt) source format
* debian/control
  - Bump Standards-Version to 3.9.1

[Jakub Wilk]
* Add ‘XS-Python-Version: >= 2.5’ to prevent bytecompilation with python2.4
  (closes: #589053).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import Pyro.core
 
2
import Pyro.naming
 
3
import Pyro.protocol
 
4
import sys
 
5
 
 
6
# Server based on using TLS to store session data.
 
7
# It uses client authentication to get the user name for the session.
 
8
 
 
9
 
 
10
print """
 
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."""
 
15
 
 
16
 
 
17
# The datastore.
 
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):
 
21
        def init(self):
 
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")
 
26
        
 
27
        def addline(self, textline):
 
28
                tls=self.getLocalStorage()
 
29
                sys.stdout.write("adding line to "+tls.datastore.name+"\n")
 
30
                sys.stdout.flush()
 
31
                tls.datastore.write(textline+" | user="+tls.username+" | came from "+str(tls.caller)+"\n")
 
32
        
 
33
        def close(self):
 
34
                tls=self.getLocalStorage()
 
35
                tls.datastore.close()   
 
36
 
 
37
 
 
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
 
48
                return (1,0)
 
49
                
 
50
 
 
51
daemon=Pyro.core.Daemon()
 
52
ns=Pyro.naming.NameServerLocator().getNS()
 
53
daemon.useNameServer(ns)
 
54
daemon.setNewConnectionValidator( SimpleServersideConnValidator() )
 
55
 
 
56
try:
 
57
        ns.createGroup(":test")
 
58
except Exception:
 
59
        pass
 
60
try:
 
61
        ns.unregister(":test.datastorage_auth")
 
62
except Exception:
 
63
        pass
 
64
 
 
65
daemon.connect(DataStoreAuth(), ":test.datastorage_auth")
 
66
 
 
67
print "Server (auth) is running."
 
68
daemon.requestLoop()