source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/wsSecurity/server/EchoServer.py @ 3113

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/wsSecurity/server/EchoServer.py@3113
Revision 3113, 3.7 KB checked in by pjkersha, 12 years ago (diff)

security/python/ndg.security.test/ndg/security/test/wsSecurity/server: working test server using ServiceContainer? - needs test vs. client

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2#
3# How to build an echo server using the extended code generation
4#
5import sys, os
6
7# Import the ZSI stuff you'd need no matter what
8from ZSI.ServiceContainer import ServiceContainer, SOAPRequestHandler
9
10# This is a new method imported to show it's value
11from ZSI.ServiceContainer import GetSOAPContext
12
13from ndg.security.test.wsSecurity.server.Echo_services_server import \
14    Echo as _Echo
15
16from ndg.security.common import wsSecurity
17
18priKeyPwd = 'JunkJunk'
19certFilePath = './Junk-cert.pem'
20priKeyFilePath = './Junk-key.pem'
21caCertFilePath = './cacert.pem'
22
23class Echo(_Echo):
24
25    def __init__(self, **kw):
26       
27        # Stop in debugger at beginning of SOAP stub if environment variable
28        # is set
29        self.__debug = bool(os.environ.get('NDGSEC_INT_DEBUG'))
30        if self.__debug:
31            import pdb
32            pdb.set_trace()
33           
34        self.signatureHandler = wsSecurity.SignatureHandler(\
35                                    signingCertFilePath=certFilePath,
36                                    signingPriKeyFilePath=priKeyFilePath,
37                                    signingPriKeyPwd=priKeyPwd,
38                                    caCertFilePathList=[caCertFilePath])
39        _Echo.__init__(self, **kw)
40       
41    def sign(self, sw):
42        '''Overrides ServiceInterface class method to allow digital signature
43        '''
44        if isinstance(self.request, EchoRequest):
45            # Echo response applies digital signature
46            self.signatureHandler.sign(sw)
47       
48    def verify(self, ps):
49        '''Overrides ServiceInterface class method to allow signature
50        verification'''     
51        if isinstance(self.request, EchoRequest):
52            # Echo request checks digital signature
53            self.signatureHandler.verify(ps)
54
55    def soap_Echo(self, ps, **kw):
56        '''Simple echo method to test WS-Security DSIG
57       
58        @type ps: ZSI ParsedSoap
59        @param ps: client SOAP message
60        @rtype: tuple
61        @return: request and response objects'''
62        if self.__debug:
63            import pdb
64            pdb.set_trace()
65           
66        response = AttAuthorityService.soap_Echo(self, ps)
67
68        response.EchoResult = self.request._EchoIn
69        return response
70   
71# Create a Server implementation
72
73#_____________________________________________________________________________
74class EchoSOAPRequestHandler(SOAPRequestHandler):
75     """Add a do_GET method to return the WSDL on HTTP GET requests.
76     Please note that the path to the wsdl file is derived from what
77     the HTTP invocation delivers (which is put into the self.path
78     attribute), so you might want to change this addressing scheme.
79     """
80     def do_GET(self):
81         """Return the WSDL file."""         
82         self.send_xml(EchoServer_interface.EchoServer._wsdl)
83         
84     def do_POST(self):
85          """Fudge to get _Dispatch to pick up the correct address
86          - seems to be necessary when putting proxy redirect for port in
87          the wsdl e.g. http://glue.badc.rl.ac.uk/sessionMgr points to the
88          default port for the Session Manager."""
89          self.path = "/EchoServIn"
90          SOAPRequestHandler.do_POST(self)
91   
92if __name__ == "__main__":
93    # Here we set up the server
94    hostname = 'localhost'
95    port = 7000
96    path = "/Echo"
97    serviceContainer = ServiceContainer((hostname, port))
98   
99   
100    # Create the Inherited version of the server
101    echo = Echo(tracefile=sys.stdout)
102    serviceContainer.setNode(echo, url=path)
103   
104    try:
105        # Run the service container
106        print "listening at http://%s:%s%s" % (hostname, port, path)
107        serviceContainer.serve_forever()
108    except KeyboardInterrupt:
109        sys.exit(0)
Note: See TracBrowser for help on using the repository browser.