source: TI12-security/trunk/python/bin/AttAuthorityServer.py @ 1176

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

Changes to incoporate new getHostInfo Attribute Authority WS method.

Tests/AttAuthorityIOtest.py: new unit test test method

Tests/SecurityClientTest?.py: minor changes to test settings

dist/NDG-Security-0.68.tar.gz: new distribution

www/html/attAuthority.wsdl: updated WSDL contains getHostInfo method.

conf/mapConfig.xml: contains new tags for information about the service provider of the AA e.g. loginURI,
service provider name. This is used by the new getHostInfo WS method.

conf/attAuthorityProperties.xml: remove old commented out tags.

NDG/AttAuthorityIO.py: added HostInfo?* classes for handling getHostInfo WS method I/O.

NDG/attAuthority_services_server.py and NDG/attAuthority_services.py: updated inline with WSDL changes.

NDG/AttAuthority.py:

  • readMapConfig updated to include new 'thisHost' tags.
  • self.mapConfig dictionary re-ordered to include top level keys 'thisHost' and 'trustedHosts'
  • New hostInfo property

NDG/AttCert.py: trivial fixes to commenting

NDG/XMLMsg.py: simplify error message for "Invalid keywords set for update..." error

NDG/CredWallet.py:

  • Client public key is now read in at the point where the corresponding pub key file path is set - i.e. in

setClntPubKeyFilePath method. This means the equivalent code in reqAuthorisation is not needed.

  • reqAuthorisation method has a new flag refreshAttCert. If set, the wallet is checked first for an existing

AC issued by the target AA. If found this is returned, and the call to the AA is skipped.

NDG/SecurityClient.py: added AttAuthorityClient?.getHostInfo WS wrapper method.

  • 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 attAuthoritySOAPRequestHandler(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."""
47         
48         wsdlfile = "/var/www/html/attAuthority.wsdl"
49         
50         print "> > > > > using wsdlfile", wsdlfile
51         wsdl = open(wsdlfile).read()
52         self.send_xml(wsdl)
53 
54     def do_POST(self):
55          """Fudge to get _Dispatch to pick up the correct address
56          - seems to be necessary when putting proxy redirect for port in
57          the wsdl e.g. http://glue.badc.rl.ac.uk/attAuthority points to the
58          default port for the Attribute Authority."""
59          self.path = "/attAuthority.wsdl"
60          SOAPRequestHandler.do_POST(self)
61       
62       
63#_____________________________________________________________________________
64# Copied from ZSI.ServiceContainer, extended to instantiate with a custom
65# request handler
66def AsServer(port=80, services=(), RequestHandlerClass=SOAPRequestHandler):
67      """port --
68          services -- list of service instances
69       """
70      address = ("127.0.0.1", port)
71      sc = ServiceContainer(address, RequestHandlerClass=RequestHandlerClass)
72      for service in services:
73           path = service.getPost()
74           sc.setNode(service, path)
75      sc.serve_forever()
76
77
78def usage():
79    """Describes how to call AttAuthorityServer from the command line"""
80    print "usage: %s " % sys.argv[0].split(os.sep)[-1]
81    print """   
82[-h | --help]
83    print usage summary
84   
85[-f <properties file path> | --file=<properties file path>]
86
87[-p <port #> | --port=<port #>
88    specify a port number to override the default
89   
90[-d | --debug]
91    set to stop in debugger on receipt of WS request
92"""
93
94
95#_____________________________________________________________________________
96if __name__ == '__main__':
97
98    try:
99        opts, args = getopt.getopt(sys.argv[1:],
100                                   "hf:p:d",
101                                   ["help", "file=", "port=", "debug"])       
102    except getopt.GetoptError:
103        usage()
104        sys.exit(1)
105
106
107    propFilePath = None
108   
109    # Port may be set from an environment variable.  Note that this will be
110    # overridden if the port command line argument is set
111    if 'NDG_AA_PORT_NUM' in os.environ:
112        port = int(os.environ['NDG_AA_PORT_NUM'])
113    else:
114        # Default port number
115        port = 5000
116       
117    debug = False
118   
119    for opt, arg in opts:
120        if opt in ("-h", "--help"):
121            usage()                     
122            sys.exit(0)
123           
124        elif opt in ("-d", "--debug"):
125            debug = True
126           
127        elif opt in ("-f", "--file"):
128            propFilePath = arg
129
130        elif opt in ("-p", "--port"):
131            port = int(arg)
132
133    if propFilePath is None:
134        # Check in installation area otherwise assume local directory
135        if 'NDG_DIR' in os.environ:
136            propFileDir = os.path.join(os.environ['NDG_DIR'], "conf")
137        else:
138            propFileDir = "."
139
140        propFilePath = os.path.join(propFileDir, 'attAuthorityProperties.xml')
141
142       
143    # Create server instance at start up
144    try:
145        aa = AttAuthority(propFilePath)
146
147    except Exception, e:
148        sys.stderr.write("Initialising Attribute Authority: %s\n" % e)
149        sys.exit(1)
150   
151    print "Attribute Authority Server listening..."
152    try:
153         AsServer(port=port, 
154                  services=[attAuthority(aa, debug=debug)], 
155                  RequestHandlerClass=attAuthoritySOAPRequestHandler)
156
157    except KeyboardInterrupt:
158        sys.exit(0)
159
160    except socket.error, e:
161        sys.stderr.write("Attribute Authority Server socket error: %s\n" % \
162                         e[1])
163        sys.exit(1)
164       
165    except Exception, e:
166        sys.stderr.write("Attribute Authority Server: %s\n" % e)
167        sys.exit(1)
168       
Note: See TracBrowser for help on using the repository browser.