source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/Echo/EchoServer.py @ 1804

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/Echo/EchoServer.py@3105
Revision 1804, 4.6 KB checked in by pjkersha, 13 years ago (diff)

Changes for WebSphere? tests.

  • 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
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
13# Import the generated Server Object
14import EchoServer_interface
15
16# Set security operation by request type
17from EchoServer_messages import *
18
19import wsSecurity
20
21psBodyChildName = lambda ps: \
22    ps.dom.childNodes[1].childNodes[1].childNodes[0].localName
23
24priKeyPwd = None
25certFilePath = '../webSphereTestcert.pem'
26priKeyFilePath = '../webSphereTestkey.pem'
27
28   
29# Create a Server implementation
30
31#_____________________________________________________________________________
32class EchoSOAPRequestHandler(SOAPRequestHandler):
33     """Add a do_GET method to return the WSDL on HTTP GET requests.
34     Please note that the path to the wsdl file is derived from what
35     the HTTP invocation delivers (which is put into the self.path
36     attribute), so you might want to change this addressing scheme.
37     """
38     def do_GET(self):
39         """Return the WSDL file."""         
40         self.send_xml(EchoServer_interface.EchoServer._wsdl)
41         
42     def do_POST(self):
43          """Fudge to get _Dispatch to pick up the correct address
44          - seems to be necessary when putting proxy redirect for port in
45          the wsdl e.g. http://glue.badc.rl.ac.uk/sessionMgr points to the
46          default port for the Session Manager."""
47          self.path = "/EchoServIn"
48          SOAPRequestHandler.do_POST(self)
49   
50# This using a derived server instead
51class EchoServIn(EchoServer_interface.EchoServer):
52    def __init__(self, post='', **kw):
53        EchoServer_interface.EchoServer.__init__(self, post, **kw)
54
55        # Fudge to copy methods of this class so that equivalent
56        # SimpleCAService class WS stub picks it up
57        self.impl = self
58       
59        self.signatureHandler = wsSecurity.SignatureHandler(\
60                                    certFilePath=certFilePath,
61                                    priKeyFilePath=priKeyFilePath,
62                                    priKeyPwd=priKeyPwd)
63
64        self.encryptionHandler = wsSecurity.EncryptionHandler(\
65                                    certFilePath=certFilePath,
66                                    priKeyFilePath=priKeyFilePath,
67                                    priKeyPwd=priKeyPwd)
68       
69       
70#    def sign(self, sw):
71#        '''\
72#        Overrides ServiceInterface class method to allow digital signature'''
73#        if isinstance(self.request, EchoRequest):
74#            # Echo response applies digital signature
75#            self.signatureHandler.sign(sw)
76#       
77#    def verify(self, ps):
78#        '''\
79#        Overrides ServiceInterface class method to allow signature
80#        verification'''     
81#        if isinstance(self.request, EchoRequest):
82#            # Echo request checks digital signature
83#            self.signatureHandler.verify(ps)
84
85    def encrypt(self, sw):
86        #if isinstance(self.request, EchoEncrRequest):
87        # Assume EchoEncr response - apply encryption
88        self.encryptionHandler.encrypt(sw)
89
90           
91    def decrypt(self, ps):
92        if psBodyChildName(ps) == 'EncryptedData':
93            # Assume EchoEncr request
94            self.encryptionHandler.decrypt(ps)
95       
96#
97#       
98#    def authorize(self, auth_info, post, action):
99#        print "Authorizing INHERIT Echo"
100#        ctx = GetSOAPContext()
101#        print dir(ctx)
102#        print "Container: ", ctx.connection
103#        print "Parsed SOAP: ", ctx.parsedsoap
104#        print "Container: ", ctx.container
105#        print "HTTP Headers:\n", ctx.httpheaders
106#        print "----"
107#        print "XML Data:\n", ctx.xmldata
108#        return 1
109
110    def Echo(self, input):
111        return "Input message was: %s" % input
112
113    def EchoEncr(self, input):
114        return "Input secret was: %s" % input
115
116# Here we set up the server
117serviceContainer = ServiceContainer(('localhost', 7000),#7100),
118                                    RequestHandlerClass=EchoSOAPRequestHandler)
119
120# Create the TIE version of the server
121#hws = EchoServer()
122#hwsi = EchoServer_interface.EchoServer(impl=hws,
123#                                       auth_method_name="authorize")
124#serviceContainer.setNode(hwsi, url="/EchoServer")
125
126# Create the Inherited version of the server
127import sys
128hws2 = EchoServIn(tracefile=sys.stdout)
129serviceContainer.setNode(hws2, url="/EchoServIn")
130
131try:
132    # Run the service container
133    serviceContainer.serve_forever()
134except KeyboardInterrupt:
135    sys.exit(0)
Note: See TracBrowser for help on using the repository browser.