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

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

Fix to WSGI based WS-Security - make ApplySignatureFilter? WSGI reference SignatureVerificationFilter? to enable the client signature value to be copied to support WSSE 1.1 Signatue Confirmation

  • 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 EchoService_services_server import EchoService as _EchoService
15
16from ndg.security.common.wssecurity.dom import SignatureHandler
17
18from os.path import expandvars as xpdVars
19from os.path import join as jnPath
20mkPath = lambda file: jnPath(os.environ['NDGSEC_WSSESRV_UNITTEST_DIR'], file)
21
22import logging
23log = logging.getLogger(__name__)
24
25class EchoService(_EchoService):
26
27    def __init__(self, **kw):
28       
29        # Stop in debugger at beginning of SOAP stub if environment variable
30        # is set
31        logging.basicConfig(level=logging.DEBUG,
32                            format='%(asctime)s %(filename)s:%(lineno)d '
33                            '%(levelname)s %(message)s')
34
35        self.__debug = bool(os.environ.get('NDGSEC_INT_DEBUG'))
36        if self.__debug:
37            import pdb
38            pdb.set_trace()
39           
40        _EchoService.__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        log.info("Server received an Echo service request...")
61        if self.__debug:
62            import pdb
63            pdb.set_trace()
64       
65        response = _EchoService.soap_Echo(self, ps)   
66        response.EchoResult = "Received message from client: " + \
67                            self.request.EchoIn
68        return response
69   
70   
71    def authorize(self, auth_info, post, action):
72        '''Override default simply to display client request info'''
73        ctx = GetSOAPContext()
74        print "-"*80
75        print dir(ctx)
76        print "Container: ", ctx.connection
77        print "Parsed SOAP: ", ctx.parsedsoap
78        print "Container: ", ctx.container
79        print "HTTP Headers:\n", ctx.httpheaders
80        print "-"*80
81        print "Client Request:\n", ctx.xmldata
82        return 1
83
84   
85if __name__ == "__main__":
86    # Here we set up the server
87       
88    if 'NDGSEC_WSSESRV_UNITTEST_DIR' not in os.environ:
89        os.environ['NDGSEC_WSSESRV_UNITTEST_DIR'] = \
90            os.path.abspath(os.path.dirname(__file__))
91   
92    configFilePath = mkPath('echoServer.cfg')
93
94    cfg = SafeConfigParser()
95    cfg.read(configFilePath)
96   
97    hostname = cfg.get('setUp', 'hostname')
98    port = cfg.getint('setUp', 'port')
99    path = cfg.get('setUp', 'path')
100   
101    wsseCfgFilePath = xpdVars(cfg.get('setUp', 'wsseCfgFilePath'))
102
103    serviceContainer = ServiceContainer((hostname, port))   
104   
105    # Create the Inherited version of the server
106    echo = EchoService()
107    echo.signatureHandler = SignatureHandler(cfg=wsseCfgFilePath)
108
109    serviceContainer.setNode(echo, url=path)
110   
111    try:
112        # Run the service container
113        print "listening at http://%s:%s%s" % (hostname, port, path)
114        serviceContainer.serve_forever()
115    except KeyboardInterrupt:
116        sys.exit(0)
Note: See TracBrowser for help on using the repository browser.