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

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

fixes to X509, XMLSecDoc, wsSecurity and sessionMgrClient unit tests - latter still to complete

security/python/ndg.security.test/ndg/security/test/SecurityCGItest.py: deleted as this code is no longer needed. Pylons code replaces it. The module that the unit test is based still exists.

security/python/ndg.security.test/ndg/security/test/sessionMgrClient/README: more detailed instructions

security/python/ndg.security.test/ndg/security/test/server.py: repalce equivalent .sh bash script with python version

security/python/ndg.security.test/ndg/security/test/sessionMgrClient/sessionMgrClient.cfg: extra comments and use unit test dir env var to ref all files to enable running from any dir

security/python/ndg.security.test/ndg/security/test/sessionMgrClient/SessionMgrClient.py: part way through refactoring for changes as of the previous

security/python/ndg.security.test/ndg/security/test/sessionMgrClient/sessionMgrProperties.xml: fix env var refs.

security/python/ndg.security.test/ndg/security/test/wsSecurity/*,
security/python/ndg.security.test/ndg/security/test/X509/*,
security/python/ndg.security.test/ndg/security/test/XMLSecDoc/*: fixed for use with env vars

  • 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.EchoService_services_server import \
15    EchoService as _EchoService
16
17from ndg.security.common import wsSecurity
18
19from os.path import expandvars as xpdVars
20from os.path import join as jnPath
21mkPath = lambda file: jnPath(os.environ['NDGSEC_WSSESRV_UNITTEST_DIR'], file)
22
23
24class EchoService(_EchoService):
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        _EchoService.__init__(self, **kw)
36       
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       
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
54        @return: response objects'''
55        if self.__debug:
56            import pdb
57            pdb.set_trace()
58       
59        response = _EchoService.soap_Echo(self, ps)   
60        response.EchoResult = "Received message from client: " + \
61                            self.request.EchoIn
62        return response
63
64   
65if __name__ == "__main__":
66    # Here we set up the server
67       
68    if 'NDGSEC_WSSESRV_UNITTEST_DIR' not in os.environ:
69        os.environ['NDGSEC_WSSESRV_UNITTEST_DIR'] = \
70            os.path.abspath(os.path.dirname(__file__))
71   
72    configFilePath = jnPath(os.environ['NDGSEC_WSSESRV_UNITTEST_DIR'],
73                            "echoServer.cfg")
74    cfg = SafeConfigParser()
75    cfg.read(configFilePath)
76   
77    hostname = cfg.get('setUp', 'hostname')
78    port = cfg.getint('setUp', 'port')
79    path = cfg.get('setUp', 'path')
80   
81    signingPriKeyFilePath = xpdVars(cfg.get('setUp', 'signingPriKeyFilePath'))
82    signingPriKeyPwd = xpdVars(cfg.get('setUp', 'signingPriKeyPwd'))
83    signingCertFilePath = xpdVars(cfg.get('setUp', 'signingCertFilePath'))
84    caCertFilePathList = [xpdVars(file) for file in \
85                          cfg.get('setUp', 'caCertFilePathList').split()]
86
87    serviceContainer = ServiceContainer((hostname, port))   
88   
89    # Create the Inherited version of the server
90    echo = EchoService(tracefile=sys.stdout)
91    echo.signatureHandler = wsSecurity.SignatureHandler(\
92                                signingCertFilePath=signingCertFilePath,
93                                signingPriKeyFilePath=signingPriKeyFilePath,
94                                signingPriKeyPwd=signingPriKeyPwd,
95                                caCertFilePathList=caCertFilePathList)
96
97    serviceContainer.setNode(echo, url=path)
98   
99    try:
100        # Run the service container
101        print "listening at http://%s:%s%s" % (hostname, port, path)
102        serviceContainer.serve_forever()
103    except KeyboardInterrupt:
104        sys.exit(0)
Note: See TracBrowser for help on using the repository browser.