auth_server.py :  » Database » Python-Remote-Objects » Pyro-3.10 » examples » sessions » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » Python Remote Objects 
Python Remote Objects » Pyro 3.10 » examples » sessions » auth_server.py
import Pyro.core
import Pyro.naming
import Pyro.protocol
import sys

# Server based on using TLS to store session data.
# It uses client authentication to get the user name for the session.


print """
This is the storage server that depends on TLS and multithreading.
It uses client connection authentication to identify the client that
belongs to the connection, instead of simply storing a client identifier
that is passed in via a remote method call."""


# The datastore.
# It will store lines of text in a file named after the 'user'.
# The resource that is owned by this user session (the file handle) is stored on the TLS.
class DataStoreAuth(Pyro.core.ObjBase):
  def init(self):
    # use the username set on the connection object (by the ConnValidator)
    tls=self.getLocalStorage()
    tls.username=tls.caller.username
    tls.datastore=open("datastorage_%s.txt" % tls.username,"w")
  
  def addline(self, textline):
    tls=self.getLocalStorage()
    sys.stdout.write("adding line to "+tls.datastore.name+"\n")
    sys.stdout.flush()
    tls.datastore.write(textline+" | user="+tls.username+" | came from "+str(tls.caller)+"\n")
  
  def close(self):
    tls=self.getLocalStorage()
    tls.datastore.close()  


# The Connection Validator, server side
# This is only an example, don't use it like this in your own code!
class SimpleServersideConnValidator(Pyro.protocol.DefaultConnValidator):
  def acceptIdentification(self, daemon, connection, token, challenge):
    # The token will be the username:password string, received from the client.
    login, password = token.split(':', 1)
    if password!="secretpassw0rd":
      return (0,Pyro.constants.DENIED_SECURITY)
    # We store the login name on the connection object to refer to it later.
    connection.username=login
    return (1,0)
    

daemon=Pyro.core.Daemon()
ns=Pyro.naming.NameServerLocator().getNS()
daemon.useNameServer(ns)
daemon.setNewConnectionValidator( SimpleServersideConnValidator() )

try:
  ns.createGroup(":test")
except Exception:
  pass
try:
  ns.unregister(":test.datastorage_auth")
except Exception:
  pass

daemon.connect(DataStoreAuth(), ":test.datastorage_auth")

print "Server (auth) is running."
daemon.requestLoop()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.