source: TI12-security/trunk/python/ndg.security.test/ndg/security/test/wsSecurity/client/EchoClient.py @ 3114

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.test/ndg/security/test/wsSecurity/client/EchoClient.py@3114
Revision 3114, 2.5 KB checked in by pjkersha, 13 years ago (diff)

security/python/ndg.security.test/ndg/security/test/wsSecurity/client: add client from Tests/ area.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2#
3# Exampe echo client, to show extended code generation in ZSI
4#
5# Import the client proxy object
6from EchoServer_client import EchoServerSOAP
7import sys
8
9import wsSecurity
10
11# Lambda used by WS-Security handler to check which operation has been
12# invoked
13isEchoRequest = lambda sw: sw.body.node.childNodes[0].localName=='Echo'
14isEchoEncrRequest = lambda sw: sw.body.node.childNodes[0].localName=='EchoEncr'
15
16isEchoResponse = lambda ps: \
17ps.dom.childNodes[1].childNodes[1].childNodes[0].localName == 'EchoResponse'
18isEchoEncrResponse = lambda ps: \
19ps.dom.childNodes[1].childNodes[1].childNodes[0].localName=='EchoEncrResponse'
20
21class WSSEhandler:
22    def __init__(self, sigHandler=None, encrHandler=None):
23        self.sigHandler = sigHandler
24        self.encrHandler = encrHandler
25       
26    def sign(self, sw):
27        if self.sigHandler:
28            self.sigHandler.sign(sw)
29           
30    def verify(self, ps):
31        if self.sigHandler:
32            self.sigHandler.verify(ps)
33       
34    def encrypt(self, sw):
35        if self.encrHandler:
36            self.encrHandler.encrypt(sw)
37           
38    def decrypt(self, ps):
39        if self.encrHandler:
40            self.encrHandler.decrypt(ps)
41
42
43#priKeyPwd = open('../tmp2').read().strip()
44#certFilePath = '../Junk-cert.pem'
45#priKeyFilePath = '../Junk-key.pem'
46priKeyPwd = None
47certFilePath = '../webSphereTestcert.pem'
48priKeyFilePath = '../webSphereTestkey.pem'
49
50# Signature handler object is passed to binding
51sigHandler = wsSecurity.SignatureHandler(certFilePath=certFilePath,
52                                         priKeyFilePath=priKeyFilePath,
53                                         priKeyPwd=priKeyPwd)
54
55encrHandler = wsSecurity.EncryptionHandler(certFilePath=certFilePath,
56                                           priKeyFilePath=priKeyFilePath,
57                                           priKeyPwd=priKeyPwd)
58
59# Test encryption only
60#wsseHandler = WSSEhandler(sigHandler, encrHandler)
61wsseHandler = WSSEhandler(encrHandler=encrHandler)
62   
63       
64# Instantiate a client proxy object, then call it
65#wsURL = "http://192.100.78.234:9081/EchoServiceWeb/services/EchoServer"
66wsURL = "http://localhost:7000"
67echoSrv = EchoServerSOAP(wsURL,
68                         sig_handler=sigHandler,
69                         encr_handler=encrHandler,
70                         tracefile=sys.stdout)
71try:
72    #import pdb;pdb.set_trace()
73    print echoSrv.Echo("Test String")
74    #print echoSrv.EchoEncr("Test Secret")
75except Exception, e:
76    print "Failed to echo: ", e
77
Note: See TracBrowser for help on using the repository browser.