source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/wsSecurity/server/echoServer.py @ 3165

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

security/python/ndg.security.test/ndg/security/test/wsSecurity: added certs and keys from test CA and made fix to echoServer.py to correctly read these from config file.

  • Property svn:executable set to *
RevLine 
[1696]1#!/usr/bin/env python
[1542]2#
3# How to build an echo server using the extended code generation
4#
[3113]5import sys, os
[3122]6from ConfigParser import SafeConfigParser
[1542]7
8# Import the ZSI stuff you'd need no matter what
[3122]9from ZSI.ServiceContainer import ServiceContainer
[1542]10
11# This is a new method imported to show it's value
12from ZSI.ServiceContainer import GetSOAPContext
13
[3124]14from ndg.security.test.wsSecurity.server.EchoService_services_server import \
15    EchoService as _EchoService
[1542]16
[3113]17from ndg.security.common import wsSecurity
[1634]18
[3113]19priKeyPwd = 'JunkJunk'
20certFilePath = './Junk-cert.pem'
21priKeyFilePath = './Junk-key.pem'
22caCertFilePath = './cacert.pem'
[1634]23
[3124]24class EchoService(_EchoService):
[1696]25
[3113]26    def __init__(self, **kw):
27       
28        # Stop in debugger at beginning of SOAP stub if environment variable
29        # is set
30        self.__debug = bool(os.environ.get('NDGSEC_INT_DEBUG'))
31        if self.__debug:
32            import pdb
33            pdb.set_trace()
34           
[3124]35        _EchoService.__init__(self, **kw)
[3113]36       
[3123]37    def sign(self, sw):
38        '''\
39        Overrides ServiceInterface class method to allow digital signature'''
40        self.signatureHandler.sign(sw)
41       
42    def verify(self, ps):
43        '''\
44        Overrides ServiceInterface class method to allow signature
45        verification'''     
46        self.signatureHandler.verify(ps)
47       
[3113]48    def soap_Echo(self, ps, **kw):
49        '''Simple echo method to test WS-Security DSIG
50       
51        @type ps: ZSI ParsedSoap
52        @param ps: client SOAP message
53        @rtype: tuple
[3122]54        @return: response objects'''
[3113]55        if self.__debug:
56            import pdb
57            pdb.set_trace()
[3122]58       
[3124]59        response = _EchoService.soap_Echo(self, ps)   
[3122]60        response.EchoResult = "Received message from client: " + \
61                            self.request.EchoIn
[3113]62        return response
[1542]63
[1634]64   
[3113]65if __name__ == "__main__":
66    # Here we set up the server
[3122]67    cfg = SafeConfigParser()
68    cfg.read("./echoServer.cfg")
[3113]69   
[3122]70    hostname = cfg.get('setUp', 'hostname')
71    port = cfg.getint('setUp', 'port')
72    path = cfg.get('setUp', 'path')
[3165]73   
[3122]74    signingPriKeyFilePath = cfg.get('setUp', 'signingPriKeyFilePath')
75    signingPriKeyPwd = cfg.get('setUp', 'signingPriKeyPwd')
76    signingCertFilePath = cfg.get('setUp', 'signingCertFilePath')
77    caCertFilePathList = cfg.get('setUp', 'caCertFilePathList').split()
78
79    serviceContainer = ServiceContainer((hostname, port))   
[3113]80   
81    # Create the Inherited version of the server
[3124]82    echo = EchoService(tracefile=sys.stdout)
[3165]83    echo.signatureHandler = wsSecurity.SignatureHandler(\
84                                    signingCertFilePath=signingCertFilePath,
85                                    signingPriKeyFilePath=signingPriKeyFilePath,
86                                    signingPriKeyPwd=signingPriKeyPwd,
87                                    caCertFilePathList=caCertFilePathList)
88
[3113]89    serviceContainer.setNode(echo, url=path)
90   
91    try:
92        # Run the service container
93        print "listening at http://%s:%s%s" % (hostname, port, path)
94        serviceContainer.serve_forever()
95    except KeyboardInterrupt:
96        sys.exit(0)
Note: See TracBrowser for help on using the repository browser.