From 0f6713087dd1f406ec49211374d70ebcce9f4b6d Mon Sep 17 00:00:00 2001 From: Joshua Boverhof Date: Tue, 11 May 2004 08:07:05 +0000 Subject: [PATCH] ---------------------------------------------------------------------- Modified Files: Namespaces.py -- added a bunch of namespaces (encryption, ws-address, ws-resourcepolicy, etc) WSDLTools.py -- added functionality for getting WS-ResourceProperties and ws-Address information out of WSDL. Ran all unittests and passed. ---------------------------------------------------------------------- --- Namespaces.py | 67 +++++++++++++++++++++++++++++++++++++++---- WSDLTools.py | 78 +++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 131 insertions(+), 14 deletions(-) diff --git a/Namespaces.py b/Namespaces.py index 71f2f74..591f4e8 100755 --- a/Namespaces.py +++ b/Namespaces.py @@ -3,7 +3,7 @@ """ try: - from xml.ns import SOAP, SCHEMA, WSDL, XMLNS + from xml.ns import SOAP, SCHEMA, WSDL, XMLNS, DSIG, ENCRYPTION except: class SOAP: ENV = "http://schemas.xmlsoap.org/soap/envelope/" @@ -20,12 +20,69 @@ except: BASE = XSD3 class WSDL: - BASE = 'http://schemas.xmlsoap.org/wsdl/' - BIND_HTTP = 'http://schemas.xmlsoap.org/wsdl/http/' - BIND_MIME = 'http://schemas.xmlsoap.org/wsdl/mime/' - BIND_SOAP = 'http://schemas.xmlsoap.org/wsdl/soap/' + BASE = "http://schemas.xmlsoap.org/wsdl/" + BIND_HTTP = "http://schemas.xmlsoap.org/wsdl/http/" + BIND_MIME = "http://schemas.xmlsoap.org/wsdl/mime/" + BIND_SOAP = "http://schemas.xmlsoap.org/wsdl/soap/" class XMLNS: BASE = "http://www.w3.org/2000/xmlns/" XML = "http://www.w3.org/XML/1998/namespace" HTML = "http://www.w3.org/TR/REC-html40" + + class DSIG: + BASE = "http://www.w3.org/2000/09/xmldsig#" + C14N = "http://www.w3.org/TR/2000/CR-xml-c14n-20010315" + C14N_COMM = "http://www.w3.org/TR/2000/CR-xml-c14n-20010315#WithComments" + C14N_EXCL = "http://www.w3.org/2001/10/xml-exc-c14n#" + DIGEST_MD2 = "http://www.w3.org/2000/09/xmldsig#md2" + DIGEST_MD5 = "http://www.w3.org/2000/09/xmldsig#md5" + DIGEST_SHA1 = "http://www.w3.org/2000/09/xmldsig#sha1" + ENC_BASE64 = "http://www.w3.org/2000/09/xmldsig#base64" + ENVELOPED = "http://www.w3.org/2000/09/xmldsig#enveloped-signature" + HMAC_SHA1 = "http://www.w3.org/2000/09/xmldsig#hmac-sha1" + SIG_DSA_SHA1 = "http://www.w3.org/2000/09/xmldsig#dsa-sha1" + SIG_RSA_SHA1 = "http://www.w3.org/2000/09/xmldsig#rsa-sha1" + XPATH = "http://www.w3.org/TR/1999/REC-xpath-19991116" + XSLT = "http://www.w3.org/TR/1999/REC-xslt-19991116" + + class ENCRYPTION: + BASE = "http://www.w3.org/2001/04/xmlenc#" + BLOCK_3DES = "http://www.w3.org/2001/04/xmlenc#des-cbc" + BLOCK_AES128 = "http://www.w3.org/2001/04/xmlenc#aes128-cbc" + BLOCK_AES192 = "http://www.w3.org/2001/04/xmlenc#aes192-cbc" + BLOCK_AES256 = "http://www.w3.org/2001/04/xmlenc#aes256-cbc" + DIGEST_RIPEMD160 = "http://www.w3.org/2001/04/xmlenc#ripemd160" + DIGEST_SHA256 = "http://www.w3.org/2001/04/xmlenc#sha256" + DIGEST_SHA512 = "http://www.w3.org/2001/04/xmlenc#sha512" + KA_DH = "http://www.w3.org/2001/04/xmlenc#dh" + KT_RSA_1_5 = "http://www.w3.org/2001/04/xmlenc#rsa-1_5" + KT_RSA_OAEP = "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" + STREAM_ARCFOUR = "http://www.w3.org/2001/04/xmlenc#arcfour" + WRAP_3DES = "http://www.w3.org/2001/04/xmlenc#kw-3des" + WRAP_AES128 = "http://www.w3.org/2001/04/xmlenc#kw-aes128" + WRAP_AES192 = "http://www.w3.org/2001/04/xmlenc#kw-aes192" + WRAP_AES256 = "http://www.w3.org/2001/04/xmlenc#kw-aes256" + + +class WSSE: + BASE = "http://schemas.xmlsoap.org/ws/2002/04/secext" + +class WSU: + BASE = "http://schemas.xmlsoap.org/ws/2002/04/utility" + UTILITY = "http://schemas.xmlsoap.org/ws/2002/07/utility" + +class WSR: + PROPERTIES = "http://www.ibm.com/xmlns/stdwip/web-services/WS-ResourceProperties" + LIFETIME = "http://www.ibm.com/xmlns/stdwip/web-services/WS-ResourceLifetime" + +class WSA: + ADDRESS = "http://schemas.xmlsoap.org/ws/2003/03/addressing" + ANONYMOUS = "%s/role/anonymous" %ADDRESS + FAULT = "http://schemas.xmlsoap.org/ws/2004/03/addressing/fault" + +class WSP: + POLICY = "http://schemas.xmlsoap.org/ws/2002/12/policy" + + + diff --git a/WSDLTools.py b/WSDLTools.py index 14fdc77..1837a33 100755 --- a/WSDLTools.py +++ b/WSDLTools.py @@ -11,6 +11,7 @@ ident = "$Id$" from Utility import DOM, Collection, CollectionNS from XMLSchema import XMLSchema, SchemaReader, WSDLToolsAdapter +from Namespaces import WSR, WSA from StringIO import StringIO import urllib @@ -379,18 +380,22 @@ class MessagePart(Element): class PortType(Element): '''PortType has a anyAttribute, thus must provide for an extensible - mechanism for supporting such attributes. + mechanism for supporting such attributes. ResourceProperties is + specified in WS-ResourceProperties. wsa:Action is specified in + WS-Address. Instance Data: - operations -- - attributes -- - + name -- name attribute + resourceProperties -- optional. wsr:ResourceProperties attribute, + value is a QName this is Parsed into a (namespaceURI, name) + that represents a Global Element Declaration. + operations ''' def __init__(self, name, documentation=''): Element.__init__(self, name, documentation) self.operations = Collection(self) - self.attributes = {} + self.resourceProperties = None def getWSDL(self): return self.parent().parent() @@ -403,7 +408,10 @@ class PortType(Element): def load(self, element): self.name = DOM.getAttr(element, 'name') self.documentation = GetDocumentation(element) - self.attributes.update(DOM.getAttrs(element)) + + if DOM.hasAttr(element, 'ResourceProperties', WSR.PROPERTIES): + rpref = DOM.getAttr(element, 'ResourceProperties', WSR.PROPERTIES) + self.resourceProperties = ParseQName(rpref, element) NS_WSDL = DOM.GetWSDLUri(self.getWSDL().version) elements = DOM.getElements(element, 'operation', NS_WSDL) @@ -421,7 +429,8 @@ class PortType(Element): docs = GetDocumentation(item) msgref = DOM.getAttr(item, 'message') message = ParseQName(msgref, item) - operation.setInput(message, name, docs) + input = operation.setInput(message, name, docs) + input.setAction(GetWSAActionInput(operation, item)) item = DOM.getElement(element, 'output', None, None) if item is not None: @@ -429,14 +438,17 @@ class PortType(Element): docs = GetDocumentation(item) msgref = DOM.getAttr(item, 'message') message = ParseQName(msgref, item) - operation.setOutput(message, name, docs) + output = operation.setOutput(message, name, docs) + output.setAction(GetWSAActionOutput(operation, item)) for item in DOM.getElements(element, 'fault', None): name = DOM.getAttr(item, 'name') docs = GetDocumentation(item) msgref = DOM.getAttr(item, 'message') message = ParseQName(msgref, item) - operation.addFault(message, name, docs) + fault = operation.addFault(message, name, docs) + fault.setAction(GetWSAActionFault(operation, item)) + class Operation(Element): @@ -450,18 +462,30 @@ class Operation(Element): def getPortType(self): return self.parent().parent() + def getInputAction(self): + """wsa:Action attribute""" + return self.input.action + def getInputMessage(self): if self.input is None: return None wsdl = self.getPortType().getWSDL() return wsdl.messages[self.input.message] + def getOutputAction(self): + """wsa:Action attribute""" + return self.output.action + def getOutputMessage(self): if self.output is None: return None wsdl = self.getPortType().getWSDL() return wsdl.messages[self.output.message] + def getFaultAction(self, name): + """wsa:Action attribute""" + return self.faults[name].action + def getFaultMessage(self, name): wsdl = self.getPortType().getWSDL() return wsdl.messages[self.faults[name].message] @@ -489,6 +513,11 @@ class MessageRole(Element): Element.__init__(self, name, documentation) self.message = message self.type = type + self.action = None + + def setAction(self, action): + """action is a URI, part of WS-Address specification """ + self.action = action class Binding(Element): @@ -972,6 +1001,37 @@ def GetExtensions(element): return [ item for item in DOM.getElements(element, None, None) if item.namespaceURI != DOM.NS_WSDL ] +def GetWSAActionFault(operation, element): + """Find wsa:Action attribute, and return value or WSA.FAULT + for the default. + """ + attr = DOM.getAttr(element, 'Action', WSA.ADDRESS, None) + if attr is not None: + return attr + return WSA.FAULT + +def GetWSAActionInput(operation, element): + attr = DOM.getAttr(element, 'Action', WSA.ADDRESS, None) + if attr is not None: + return attr + targetNamespace = operation.getPortType().getWSDL().targetNamespace + ptName = operation.getPortType().name + msgName = operation.getInputMessage().name + if targetNamespace.endswith('/'): + return '%s%s/%s' %(targetNamespace, ptName, msgName) + return '%s/%s/%s' %(targetNamespace, ptName, msgName) + +def GetWSAActionOutput(operation, element): + attr = DOM.getAttr(element, 'Action', WSA.ADDRESS, None) + if attr is not None: + return attr.value + targetNamespace = operation.getPortType().getWSDL().targetNamespace + ptName = operation.getPortType().name + msgName = operation.getOutputMessage().name + if targetNamespace.endswith('/'): + return '%s%s/%s' %(targetNamespace, ptName, msgName) + return '%s/%s/%s' %(targetNamespace, ptName, msgName) + def FindExtensions(object, kind, t_type=type(())): if isinstance(kind, t_type): result = []