source: TI12-security/tags/stable-TI12-security-v0.4/python/SessionMgrServer.py @ 542

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/tags/stable-TI12-security-v0.4/python/SessionMgrServer.py@1316
Revision 542, 5.9 KB checked in by pjkersha, 14 years ago (diff)

SimpleCAServer.py: replace setCAPassPhrase() call with reference to
caPassPhrase property.

attAuthorityProperties.xml: modified Attribute Certificate life time
<attCertLifeTime> to 8 hours.

  • 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 Session Manager Web Services server interface
4
5NERC Data Grid Project
6
7P J Kershaw 16/08/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# Session Manager Web Services stub code generated by wsdl2py and
30# wsdl2dispatch
31from NDG.sessionMgr_services import *
32from NDG.sessionMgr_services_server import sessionMgr
33
34# Session Manager
35from NDG.Session 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
71#_____________________________________________________________________________
72def usage(fp=sys.stdout):
73    """Describes how to call SessionMgrServer from the command line"""
74    fp.write("usage: %s \n" % sys.argv[0].split(os.sep)[-1])
75    fp.write("""   
76[-h | --help]
77    print usage summary
78   
79[-f <properties file path> | --file=<properties file path>]
80
81[-p <port #> | --port=<port #>]
82    port number for server to listen on
83
84[-d | --debug]
85    set to stop in debugger on receipt of WS request
86   
87[-n | --nopassphrase]
88    skip the prompt for the database pass-phrase.  In this case, the
89    pass-phrase must be set in the 'dbURI' tag in the configuration file.
90   
91[-w | --nowsdlencrkey]
92    skip the prompt for the WSDL encryption key and pick up the key from the
93    'sessMgrWSDLkey' tag in the configuration file.
94""")
95
96#_____________________________________________________________________________
97if __name__ == '__main__':
98
99    try:
100        optLongNames = [ "help", 
101                         "file=", 
102                         "port=", 
103                         "debug", 
104                         "nopassphrase",
105                         "nowsdlencrkey"]
106        opts, args = getopt.getopt(sys.argv[1:], "hf:p:dnw", optLongNames)
107
108    except getopt.GetoptError, e:
109        sys.stderr.write("Error: %s\n\n" % e)
110        usage(fp=sys.stderr)
111        sys.exit(1)
112
113
114    propFilePath = None
115    port = 5700 #80 # temporary port for testing
116    debug = False
117    noPPhrase = False
118    noWSDLencrKey = False
119   
120    for opt, arg in opts:
121        if opt in ("-h", "--help"):
122            usage()
123            sys.exit(0)
124
125        elif opt in ("-d", "--debug"):
126            debug = True
127
128        elif opt in ("-f", "--file"):
129            propFilePath = arg
130
131        elif opt in ("-p", "--port"):
132            port = int(arg)
133
134        elif opt in ("-n", "--nopassphrase"):
135            noPPhrase = True
136
137        elif opt in ("-w", "--nowsdlencrkey"):
138            noWSDLencrKey = True
139
140        else:
141            sys.stderr.write("Option not recognised: %s" % opt)
142            usage(fp=sys.stderr)
143            sys.exit(1)
144
145
146    if propFilePath is None:
147        # Check in installation area otherwise assume local directory
148        if 'NDG_DIR' in os.environ:
149            propFileDir = os.path.join(os.environ['NDG_DIR'], "conf")
150        else:
151            propFileDir = "."
152
153        propFilePath = os.path.join(propFileDir, 'sessionMgrProperties.xml')
154
155
156    if noPPhrase is False:
157        import getpass
158        try:
159            credReposPPhrase = getpass.getpass(\
160                                prompt="Credential Repository pass-phrase: ")
161        except KeyboardInterrupt:
162            sys.exit(1)
163    else:
164        credReposPPhrase = None
165
166
167    if noWSDLencrKey is False:
168        import getpass
169        try:
170            sessMgrWSDLkey = getpass.getpass(prompt="WSDL Encryption Key: ")
171        except KeyboardInterrupt:
172            sys.exit(1)
173    else:
174        sessMgrWSDLkey = None
175
176
177    # Create server instance at start up
178#    import pdb
179#    pdb.set_trace()
180    try:
181        sm = SessionMgr(propFilePath,
182                        credReposPPhrase=credReposPPhrase,
183                        sessMgrWSDLkey=sessMgrWSDLkey)
184
185    except Exception, e:
186        sys.stderr.write("Initialising Session Manager: %s\n" % e)
187        sys.exit(1)
188
189    print "Session Manager Server listening..."
190    try:
191         AsServer(port=port, 
192                  services=[sessionMgr(sm, debug=debug)], 
193                  RequestHandlerClass=SessionMgrSOAPRequestHandler)
194
195    except KeyboardInterrupt:
196        sys.exit(0)
197
198    except socket.error, e:
199        sys.stderr.write("Session Manager Server socket error: %s\n" % \
200                         e[1])
201        sys.exit(1)
202
203    except Exception, e:
204        sys.stderr.write("Session Manager Server: %s\n" % e)
205        sys.exit(1)
206       
207             
Note: See TracBrowser for help on using the repository browser.