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

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

security/python/ndg.security.test/ndg/security/test/wsSecurity/client: use ndg urn for WSDL and rename 'EchoService?'

  • 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
6from ConfigParser import SafeConfigParser
7
8# Import the ZSI stuff you'd need no matter what
9from ZSI.ServiceContainer import ServiceContainer
10
11# This is a new method imported to show it's value
12from ZSI.ServiceContainer import GetSOAPContext
13
14from ndg.security.test.wsSecurity.server.Echo_services_server import \
15    Echo as _Echo
16
17from ndg.security.common import wsSecurity
18
19priKeyPwd = 'JunkJunk'
20certFilePath = './Junk-cert.pem'
21priKeyFilePath = './Junk-key.pem'
22caCertFilePath = './cacert.pem'
23
24class Echo(_Echo):
25
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           
35        self.signatureHandler = wsSecurity.SignatureHandler(\
36                                    signingCertFilePath=certFilePath,
37                                    signingPriKeyFilePath=priKeyFilePath,
38                                    signingPriKeyPwd=priKeyPwd,
39                                    caCertFilePathList=[caCertFilePath])
40        _Echo.__init__(self, **kw)
41       
42    def sign(self, sw):
43        '''\
44        Overrides ServiceInterface class method to allow digital signature'''
45        self.signatureHandler.sign(sw)
46       
47    def verify(self, ps):
48        '''\
49        Overrides ServiceInterface class method to allow signature
50        verification'''     
51        self.signatureHandler.verify(ps)
52       
53    def soap_Echo(self, ps, **kw):
54        '''Simple echo method to test WS-Security DSIG
55       
56        @type ps: ZSI ParsedSoap
57        @param ps: client SOAP message
58        @rtype: tuple
59        @return: response objects'''
60        if self.__debug:
61            import pdb
62            pdb.set_trace()
63       
64        response = _Echo.soap_Echo(self, ps)   
65        response.EchoResult = "Received message from client: " + \
66                            self.request.EchoIn
67        return response
68
69   
70if __name__ == "__main__":
71    # Here we set up the server
72    cfg = SafeConfigParser()
73    cfg.read("./echoServer.cfg")
74   
75    hostname = cfg.get('setUp', 'hostname')
76    port = cfg.getint('setUp', 'port')
77    path = cfg.get('setUp', 'path')
78    signingPriKeyFilePath = cfg.get('setUp', 'signingPriKeyFilePath')
79    signingPriKeyPwd = cfg.get('setUp', 'signingPriKeyPwd')
80    signingCertFilePath = cfg.get('setUp', 'signingCertFilePath')
81    caCertFilePathList = cfg.get('setUp', 'caCertFilePathList').split()
82
83    serviceContainer = ServiceContainer((hostname, port))   
84   
85    # Create the Inherited version of the server
86    echo = Echo(tracefile=sys.stdout)
87    serviceContainer.setNode(echo, url=path)
88   
89    try:
90        # Run the service container
91        print "listening at http://%s:%s%s" % (hostname, port, path)
92        serviceContainer.serve_forever()
93    except KeyboardInterrupt:
94        sys.exit(0)
Note: See TracBrowser for help on using the repository browser.