source: security/trunk/python/AttAuthorityServer.py @ 532

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/security/trunk/python/AttAuthorityServer.py@532
Revision 532, 4.4 KB checked in by pjkersha, 14 years ago (diff)

AttAuthorityServer?.py: updated to use stub code generated by wsdl2dispatch

SessionMgrServer?.py: added debug keyword arg for sessionMgr WS class.

attAuthority.wsdl: rationalised all methods to single string i/o. to allow
encryption of messages if required and help with Java <-> Python
interoperability.

sessionMgr.wsdl: changed authorisation method name to reqAuthorisation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/env python
2
3"""NDG Attribute Authority Web Services server interface
4
5NERC Data Grid Project
6
7P J Kershaw 05/05/05
8
9Copyright (C) 2005 CCLRC & NERC
10
11This software may be distributed under the terms of the Q Public License,
12version 1.0 or later.
13"""
14
15cvsID = '$Id$'
16
17# Handle socket errors from WS
18import socket 
19
20# Command line processing
21import sys
22import os
23import getopt
24
25# Web service interface
26from ZSI import dispatch
27from ZSI.ServiceContainer import ServiceContainer, SOAPRequestHandler
28
29# Attribute Authority Web Services stub code generated by wsdl2py and
30# wsdl2dispatch
31from NDG.attAuthority_services import *
32from NDG.attauthority_services_server import attAuthority
33
34# Attribute Authority
35from NDG.AttAuthority import *
36
37
38#_____________________________________________________________________________
39class SessionMgrSOAPRequestHandler(SOAPRequestHandler):
40     """Add a do_GET method to return the WSDL on HTTP GET requests.
41     Please note that the path to the wsdl file is derived from what
42     the HTTP invocation delivers (which is put into the self.path
43     attribute), so you might want to change this addressing scheme.
44     """
45     def do_GET(self):
46           """Return the WSDL file. We expect to get the location from the
47           invocation URL ("path").
48           """
49           wsdlfile = os.path.join('.', 
50                                   self.path.replace('/', "", 1) + ".wsdl")
51           print "> > > > > using wsdlfile", wsdlfile
52           wsdl = open(wsdlfile).read()
53           self.send_xml(wsdl)
54       
55       
56#_____________________________________________________________________________
57# Copied from ZSI.ServiceContainer, extended to instantiate with a custom
58# request handler
59def AsServer(port=80, services=(), RequestHandlerClass=SOAPRequestHandler):
60      """port --
61          services -- list of service instances
62       """
63      address = ("127.0.0.1", port)
64      sc = ServiceContainer(address, RequestHandlerClass=RequestHandlerClass)
65      for service in services:
66           path = service.getPost()
67           sc.setNode(service, path)
68      sc.serve_forever()
69
70
71def usage():
72    """Describes how to call AttAuthorityServer from the command line"""
73    print "usage: %s " % sys.argv[0].split(os.sep)[-1]
74    print """   
75[-h | --help]
76    print usage summary
77   
78[-f <properties file path> | --file=<properties file path>]
79
80[-p <port #> | --port=<port #>
81    specify a port number to override the default
82   
83[-d | --debug]
84    set to stop in debugger on receipt of WS request
85"""
86
87
88#_____________________________________________________________________________
89if __name__ == '__main__':
90
91    try:
92        opts, args = getopt.getopt(sys.argv[1:],
93                                   "hf:p:d",
94                                   ["help", "file=", "port=", "debug"])       
95    except getopt.GetoptError:
96        usage()
97        sys.exit(1)
98
99
100    propFilePath = None
101    port = 5000 #80 # temporary port for testing
102    debug = False
103   
104    for opt, arg in opts:
105        if opt in ("-h", "--help"):
106            usage()                     
107            sys.exit(0)
108           
109        elif opt in ("-d", "--debug"):
110            debug = True
111           
112        elif opt in ("-f", "--file"):
113            propFilePath = arg
114
115        elif opt in ("-p", "--port"):
116            port = int(arg)
117
118    if propFilePath is None:
119        # Check in installation area otherwise assume local directory
120        if 'NDG_DIR' in os.environ:
121            propFileDir = os.path.join(os.environ['NDG_DIR'], "conf")
122        else:
123            propFileDir = "."
124
125        propFilePath = os.path.join(propFileDir, 'attAuthorityProperties.xml')
126
127       
128    # Create server instance at start up
129    try:
130        aa = AttAuthority(propFilePath)
131
132    except Exception, e:
133        sys.stderr.write("Initialising Attribute Authority: %s\n" % e)
134        sys.exit(1)
135   
136    print "Attribute Authority Server listening..."
137    try:
138         AsServer(port=port, 
139                  services=[attAuthority(aa, debug=debug)], 
140                  RequestHandlerClass=SessionMgrSOAPRequestHandler)
141
142    except KeyboardInterrupt:
143        sys.exit(0)
144
145    except socket.error, e:
146        sys.stderr.write("Attribute Authority Server socket error: %s\n" % \
147                         e[1])
148        sys.exit(1)
149       
150    except Exception, e:
151        sys.stderr.write("Attribute Authority Server: %s\n" % e)
152        sys.exit(1)
153       
Note: See TracBrowser for help on using the repository browser.