source: TI12-security/trunk/python/bin/GatekeeperServer.py @ 968

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/bin/GatekeeperServer.py@968
Revision 968, 4.3 KB checked in by pjkersha, 14 years ago (diff)

Tests/GatekeeperClientTest?.py: test Gatekeeper WS client.

Tests/AttAuthorityClientTest?.py: renamed methods so that called automatically when script is
invoked with no args.

Tests/SecurityClientTest?.py: set user to 'laurence' in order to get ACs with more roles set.

bin/LogServer.py: typo fix logs -> log

bin/GatekeeperServer.py: working version

NDG/TestGatekeeperResrc.py: test harness for Gatekeeper resource interface

NDG/gatekeeper_services_server.py: working but logic for returning matching roles needs fixing.

NDG/GatekeeperClient.py: client interface class to Gatekeeper WS.

NDG/Gatekeeper.py: working version

NDG/gatekeeper_services.py: regenerated following changes to WSDL.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3"""NDG Gatekeeper Web Service server interface
4
5NERC Data Grid Project
6
7P J Kershaw 18/05/06
8
9Copyright (C) 2006 CCLRC & NERC
10
11This software may be distributed under the terms of the Q Public License,
12version 1.0 or later.
13"""
14
15# Handle socket errors from WS
16import socket 
17
18# Command line processing
19import sys
20import os
21import optparse
22
23# Web service interface
24from ZSI import dispatch
25from ZSI.ServiceContainer import ServiceContainer, SOAPRequestHandler
26
27# Gatekeeper Web Services stub code generated by wsdl2py and
28# wsdl2dispatch
29from NDG.gatekeeper_services import *
30from NDG.gatekeeper_services_server import gatekeeper
31
32# Gatekeeper
33from NDG.Gatekeeper import *
34
35
36#_____________________________________________________________________________
37class GatekeeperSOAPRequestHandler(SOAPRequestHandler):
38     """Add a do_GET method to return the WSDL on HTTP GET requests.
39     Please note that the path to the wsdl file is derived from what
40     the HTTP invocation delivers (which is put into the self.path
41     attribute), so you might want to change this addressing scheme.
42     """
43     def do_GET(self):
44         """Return the WSDL file."""
45         
46         wsdlfile = "/var/www/html/gatekeeper.wsdl"
47         
48         print "> > > > > using wsdlfile", wsdlfile
49         wsdl = open(wsdlfile).read()
50         self.send_xml(wsdl)
51 
52     def do_POST(self):
53          """Fudge to get _Dispatch to pick up the correct address
54          - seems to be necessary when putting proxy redirect for port in
55          the wsdl e.g. http://glue.badc.rl.ac.uk/gatekeeper points to the
56          default port for the Gatekeeper."""
57          self.path = "/gatekeeper.wsdl"
58          SOAPRequestHandler.do_POST(self)
59       
60       
61#_____________________________________________________________________________
62# Copied from ZSI.ServiceContainer, extended to instantiate with a custom
63# request handler
64def AsServer(port=80, services=(), RequestHandlerClass=SOAPRequestHandler):
65      """port --
66          services -- list of service instances
67       """
68      address = ("127.0.0.1", port)
69      sc = ServiceContainer(address, RequestHandlerClass=RequestHandlerClass)
70      for service in services:
71           path = service.getPost()
72           sc.setNode(service, path)
73      sc.serve_forever()
74
75
76#_____________________________________________________________________________
77if __name__ == '__main__':
78
79    parser = optparse.OptionParser()
80    parser.add_option("-p", 
81                      "--port", 
82                      dest="port",
83                      type="int",
84                      default=5200,
85                      help="specify a port number to override the default")
86
87    parser.add_option("-f", 
88                      "--file",
89                      dest="propFilePath",
90                      help=\
91   "properties file path - default is $NDG_DIR/conf/gatekeeperProperties.xml")
92
93    parser.add_option("-d", 
94                      "--debug",
95                      dest="debug",
96                      action="store_true",
97                      default=False,
98                      help="set to stop in debugger on receipt of WS request")
99
100    (options, args) = parser.parse_args()
101
102
103    if options.propFilePath is None:
104        # Check in installation area otherwise assume local directory
105        if 'NDG_DIR' in os.environ:
106            propFileDir = os.path.join(os.environ['NDG_DIR'], "conf")
107        else:
108            propFileDir = "."
109
110        options.propFilePath = os.path.join(propFileDir, 
111                                            'gatekeeperProperties.xml')
112
113
114    # Create server instance at start up
115    try:
116        gatekeeperSrv = Gatekeeper(propFilePath=options.propFilePath)
117
118    except Exception, e:
119        sys.stderr.write("Initialising Gatekeeper: %s\n" % str(e))
120        sys.exit(1)
121   
122    print "Gatekeeper Server listening..."
123    try:
124         AsServer(port=options.port, 
125                  services=[gatekeeper(gatekeeperSrv, debug=options.debug)], 
126                  RequestHandlerClass=GatekeeperSOAPRequestHandler)
127
128    except KeyboardInterrupt:
129        sys.exit(0)
130
131    except socket.error, e:
132        sys.stderr.write("Gatekeeper Server socket error: %s\n" % \
133                         e[1])
134        sys.exit(1)
135       
136    except Exception, e:
137        sys.stderr.write("Gatekeeper Server: %s\n" % str(e))
138        sys.exit(1)
139       
Note: See TracBrowser for help on using the repository browser.