Add User and Pass to SOAP Header in Mule - soap

It seems this should be simple but the solution has been eluding me. My flow is XML -> XSLT translation -> consume web service (IBM Web Sphere Web Service to be specific). I have the pieces working individually but I am having trouble figuring out how to add user/pass to the SOAP header. I would think that I should be able to add them to the keys in the security tab on the Mule SOAP Component (I have the operation set to Proxy Client). Unfortunately, I cannot figure out what the valid keys are. Maybe I am way off base even attempting to use the security tab. So ultimately I need my outgoing XML to contain:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>
myUserName
</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
myPa33W0rd
</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
Currently my Mule flow is putting out:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
Do I need to add the security information manually (maybe in the XSLT translation)? That doesn't feel right but I can't figure out how to add it.
Here are the relevant lines from my flow:
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="src\main\resources\MappingMapToChangeCatalogEntry.xslt" outputEncoding="US-ASCII" doc:name="XSLT"/>
<cxf:proxy-client payload="body" enableMuleSoapHeaders="true" doc:name="SOAP"/>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>

In order to add WS-Sec you need to configure the CXF WSS4J interceptors and inject them into Mule's CXF message processors.
Pre 3.3 =
<spring:bean name="wss4jOutConfiguration"
class="org.springframework.beans.factory.config.MapFactoryBean">
<spring:property name="sourceMap">
<spring:map>
<spring:entry key="action" value="Signature" />
<spring:entry key="user" value="joe" />
<spring:entry key="signaturePropFile" value="org/mule/module/cxf/wssec/wssecurity.properties" />
<spring:entry key="passwordCallbackClass" value="org.mule.module.cxf.wssec.ClientPasswordCallback" />
</spring:map>
</spring:property>
</spring:bean>
...
<cxf:proxy-client payload="body" enableMuleSoapHeaders="true" doc:name="SOAP">
<cxf:outInterceptors>
<spring:bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<spring:property name="properties" ref="wss4jOutConfiguration"/>
</spring:bean>
</cxf:outInterceptors>
</cxf:proxy-client>
Rough Sample Password Callback class:
public class ClientPasswordCallback implements CallbackHandler{
#Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback callback = (WSPasswordCallback) callbacks[0];
if(callback.getIdentifier().equals("joe")){
callback.setPassword("pass");
}
}
See more here: http://www.mulesoft.org/documentation/display/current/WS-Security+Usability+Improvement
3.3.+ :
There is a new cxf:ws-security element availble in 3.3+ Here is an example flow here: https://svn.codehaus.org/mule/tags/mule-3.4-M2/modules/cxf/src/test/resources/org/mule/module/cxf/wssec/cxf-secure-proxy-flow.xml
<cxf:proxy-client payload="body"
enableMuleSoapHeaders="true" doc:name="SOAP">
<cxf:ws-security>
<cxf:ws-config>
<cxf:property key="action"
value="UsernameToken
Timestamp" />
<cxf:property key="user" value="joe" />
<cxf:property key="passwordCallbackClass"
value="com.mulesoft.mule.example.security.PasswordCallback" />
<cxf:property key="mustUnderstand" value="false" />
</cxf:ws-config>
</cxf:ws-security>
</cxf:proxy-client>
Previously I have also just handled he entire envelope myself when using XSLT. I have then passed the user and pass into the XSLT via context params
<xm:xslt-transformer xsl-file="xslt/ToSomethingSOAPY.xsl">
<xm:context-property key="user" value="${my.user}" />
<xm:context-property key="password" value="${my.pass}" />
</xm:xslt-transformer>
And then reieived them via xsl params like so:
<xsl:param name="user" />
....
<wsse:UsernameToken
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
wsu:Id="UsernameToken-1018444980">
<wsse:Username><xsl:value-of select="$user" /></wsse:Username>

Related

How exactly works this payloadFactory chained with an header mediator in a WSO2 ESB project?

I am absolutly new in WSO2 and I am working on a WSO2 Enterprise Integrator project containing this ESB project section (I think that my question is only related to ESB).
So my doubt is: I have an XML file defining an API. The flow starts with a payloadFactory mediator, something like this:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/xxxTest2" name="xxxTest2" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<!-- Create empty message to get all samples from DSS -->
<!-- Get Sample ID -->
<payloadFactory media-type="xml">
<format>
<body/>
</format>
<args>
<arg evaluator="xml" expression="get-property('uri.var.int_val')" xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
<!--
Adding an header that defines the actionr related to the "FindNotProcessed" DSS service
used to retrieve all the unprocessed resource on the DB
-->
<header name="Action" scope="default" value="urn:FindNotProcessed"/>
<!-- Log the request generated by the previous payloadFactory mediator: -->
<log level="full"/>
...............................................................
...............................................................
...............................................................
</api>
My doubt is: this payloadFactory mediator generate and empty message because its content is:
<format>
<body/>
</format>
The next element in the chain is the header mediator:
<header name="Action" scope="default" value="urn:FindNotProcessed"/>
used to set a new header having name="Action" that specify (as value) the name of a DSS service to obtain some data from the DB.
Finnally the next element in the chain is a log mediator. It seems to me that is is used to log the message generated by the concatenation of the previous payloadFactory mediator chianed with the following header mediator.
This log mediator generate this log:
TID: [-1234] [] [2017-03-28 10:05:30,943] INFO {org.apache.synapse.mediators.builtin.LogMediator} -
To: /glisTest2, WSAction: urn:FindNotProcessed, SOAPAction: urn:FindNotProcessed, MessageID: urn:uuid:95913219-2ad1-4488-a260-78693f3bbde2, Direction: request,
Envelope:
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<body xmlns="http://ws.apache.org/ns/synapse"/>
</soapenv:Body>
</soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
My doubts are:
1) Why is it generating an XML message that embedd a soapenv structure?
2) It depends by the fact that the header meadiator defines scope="default" that should coincide to Synapse. Because reading the official documentation:
https://docs.wso2.com/display/ESB481/Header+Mediator
it says:
Scope: Select Synapse if you want to manipulate SOAP headers. Select
Transport if you want to manipulate HTTP headers.
so I think that settings in this way is generating a SOAP message and so is the reason because my message is into the soapenv structure.
Is it or am I missing something?
By default, all the messages in the WSO2 EI/ESB will be treated as SOAP messages, that's why your payload is enclosed in the soap envelope.
Headers actually work when you send the message to an endpoint, so if you have an endpoint http://hostname:port/abc/xyz , the Action (Soap Action) of the message will be set as urn:FindNotProcessed. It means that the message will go to the urn:FindNotProcessed operation of the endpoint, provided the endpoint is a soap endpoint.
Thanks

Access a web-service with session-key/token from WSO2 ESB

I'm starting to evaluate WSO2 ESB and try to implement some simple but real life scenarios.
What I'm trying to do, in this specific case is connect to a web-service that uses a session-key in the payload to do the authentication. So there is one web-service call with user and password to get the key and then I need to put this into the payload of the second web-service call to actually retrieve data from a service.
I don't want to log in with every service call, for performance reasons, but log in once, store the key for some time and do a couple of requests.
The service I want to call is a SugarCRM web-service.
The login message would be something like this:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sug="http://www.sugarcrm.com/sugarcrm" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soapenv:Header/>
<soapenv:Body>
<sug:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<user_auth xsi:type="sug:user_auth">
<user_name xsi:type="xsd:string">interface</user_name>
<password xsi:type="xsd:string">MD5HASHOFPASSWORD</password>
</user_auth>
<application_name xsd:string">dummy</application_name>
<name_value_list xsi:type="sug:name_value_list" soapenc:arrayType="sug:name_value[]"/>
</sug:login>
</soapenv:Body>
Which returns something like this:
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.sugarcrm.com/sugarcrm">
<SOAP-ENV:Body>
<ns1:loginResponse xmlns:ns1="http://www.sugarcrm.com/sugarcrm">
<return xsi:type="tns:entry_value">
<id xsi:type="xsd:string">loggfi0i3j6eeugs7l0a0m2587</id>
</return>
</ns1:loginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Then I need to use the "id" field as the token for a new request.
Example, to request all the Leads (the "id" is put into the "session" field):
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sug="http://www.sugarcrm.com/sugarcrm" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soapenv:Header/>
<soapenv:Body>
<sug:get_entry_list soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<session xsi:type="xsd:string">loggfi0i3j6eeugs7l0a0m2587</session>
<module_name xsi:type="xsd:string">Leads</module_name>
</sug:get_entry_list>
</soapenv:Body>
</soapenv:Envelope>
This request then returns all the Leads in the database.
Equally this is needed for accessing web-services that use OAuth2, for example the REST-API of MS Dynamics CRM, only then I need to put the token/bearer in the header.
How would I go about realizing the above scenario in WSO2 ESB? I'm sure this is pretty common, but I have not found documentation or examples for it.
Here is the sequence to get the session-id from the CRM:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="sugar_login" trace="enable" xmlns="http://ws.apache.org/ns/synapse">
<payloadFactory media-type="xml">
<format>
<sug:login xmlns:sug="http://www.sugarcrm.com/sugarcrm">
<sug:user_auth>
<user_name>interface</user_name>
<password>MD5HASHOFPASSWORD</password>
<version>1</version>
</sug:user_auth>
<application_name>dummy</application_name>
</sug:login>
</format>
</payloadFactory>
<header name="To" value="http://my.sugarcrm.com:9090/service/v4_1/soap.php"/>
<call>
<endpoint name="templEPTimeout" template="org.wso2.carbon.connector.sugarcrm.timeout">
<axis2ns653:parameter name="timoutDuration" value="6000" xmlns:axis2ns653="http://ws.apache.org/ns/synapse"/>
<axis2ns654:parameter name="maximumDuration" value="3000" xmlns:axis2ns654="http://ws.apache.org/ns/synapse"/>
<axis2ns655:parameter name="progressAFactor" value="2.0" xmlns:axis2ns655="http://ws.apache.org/ns/synapse"/>
<axis2ns656:parameter name="initialDuration" value="2000" xmlns:axis2ns656="http://ws.apache.org/ns/synapse"/>
</endpoint>
</call>
<!-- Remove response custom header information -->
<header action="remove" name="X-SOAP-Server" scope="transport"/>
<header action="remove" name="Cache-control" scope="transport"/>
<header action="remove" name="Vary" scope="transport"/>
<header action="remove" name="Expires" scope="transport"/>
<header action="remove" name="Set-Cookie" scope="transport"/>
<header action="remove" name="path" scope="transport"/>
<property expression="//ns1:loginResponse/return/id"
name="sugarsessionid" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
</sequence>
You can use the sugarcrm connector to connect with SugarCRM API. You can find the sugarcrm connector at WSO2 Store. Find more details in the documentation.

How can I send an empty node as part of a SOAP request in mule studio?

I'm trying to configure a flow in mule studio using the Web Services Connector. The SOAP body the endpoint is expecting looks like:
<soapenv:Body>
<v4:readFields>
<filter>
<type>?</type>
<id>?</id>
<name>
<operator>?</operator>
<value>?</value>
</name>
</filter>
<pageNumber>?</pageNumber>
</v4:readFields>
</soapenv:Body>
The <filter> node itself is required, but the contents are optional, so I'd like to get my flow to send a body like:
<soapenv:Body>
<v4:readFields>
<filter />
<pageNumber>1</pageNumber>
</v4:readFields>
</soapenv:Body>
Is there a way to set up the message payload to send this request?
Running Anypoint Studio 5.1.0, Mule ESB 3.6.
My current flow config:
<flow name="GetFieldInfo">
<http:listener config-ref="localhost" path="/fields" doc:name="HTTP"/>
<enricher source="#[payload]" target="#[flowVars.sessionId]" doc:name="GetSessionId">
<flow-ref name="GetSessionId" doc:name="Login"/>
</enricher>
<data-mapper:transform config-ref="Xml_loginResponse__To_Xml_sessionHeader_" input-ref="#[flowVars["sessionId"]]" target="#[message.outboundProperties["soap.sessionHeader"]]" doc:name="Set Session Header"/>
<ws:consumer config-ref="BrontoAPI" operation="readFields" doc:name="Web Service Consumer"/>
<echo-component doc:name="Echo"/>
</flow>
you can make use of mule parse template to send static xml with variable data
sample :
<soapenv:Body>
<v4:readFields>
<filter />
<pageNumber>#[payload]</pageNumber>
</v4:readFields>
</soapenv:Body>
you can find the documentation here https://developer.mulesoft.com/docs/display/current/Parse+Template+Reference

SOAP mediation Wso2 ESB

Hello I have the following message:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="true">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-11">
<wsu:Created>2012-09-06T09:59:04.031Z</wsu:Created>
<wsu:Expires>2012-09-06T10:04:04.031Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-12">
<wsse:Username>admin</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">admin</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body />
</soapenv:Envelope>
I wanted to use an XPath to get the username <wsse:Username>admin</wsse:Username> from the incoming message
any suggestion?
EDIT:
I tried this:
<inSequence xmlns="http://ws.apache.org/ns/synapse">
<property xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" name="p1" expression="$header/wsse:Username" scope="default" />
<log>
<property name="output*********" expression="get-property('p1')" />
</log>
</inSequence>
but it does not output the username:
MessageID: urn:uuid:68f95493-7dfd-416a-b
455-f77f4fd5c9c5, Direction: request, output********* =
Nuvio,
You can use the expression "$header/wsse:Security" where "wsse" prefixes the namespace carried by the Security header element. Shown below is how you can get it saved to a Synapse message context property.
<property xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" name="Security" expression="$header/wsse:Security" />
FYI, you can use the syntax "$header/header_name" to extract any SOAP header element that exists in your SOAP message.
Hope this helps!
Cheers,
Prabath
otherwise you have option to get it use this xpath:"//wsse:Username/text()"
I think it will help you i am also new for this wso2 tool.
hope this carry you..

coldfusion publish webservice using SOAP

I am trying to create a web service that can be consumed with SOAP. I were exercising with normal webservices that returns any values, but know i want to check which elements in the SOAP:BODY are needed and return them with a response. I found the methods
GetSoapRequest()
and
AddSoapResponse()
in the livedoc from adobe, but don't understand how to use them.
I saw the explenation of a request and response on w3school.com
i tried to solve the Problem with the tags "cfsavecontent"
<cffunction
name="soap"
access="remote"
returntype="any"
output="false">
<cfsavecontent variable="soapMessage">
<?xml version="1.0">
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Header>
</soap:Header>
<soap:Body>
<m:GetPriveResponse xmlns:m="namespace">
<m:Price>1.90</m:Price>
</m:GetPriceResponse>
</soap:Body>
</soap:Envelope>
</cfsavecontent>
but it only works, if the cffunction has returntype="any". The type "xml" occurs an error.
thx for helf
The easiest way to create a web service in CF, see
Creating components for web services http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec13a13-7fe2.html
Publishing web services
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-78b7.html
I just installed the soapUI eclipse addon and called the WSDL that includes an argument of a complexe type. After testing the methods of my web service with the addon, I got the SOAP-Message I was searching all the time. Maybe it will help anybody, i just where searching long time for this solution.
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:com="http://components.conner.somebody">
<soapenv:Header/>
<soapenv:Body>
<com:echoAddress soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<input xsi:type="com:Address">
<City xsi:type="xsd:string">?</City>
<Country xsi:type="xsd:string">?</Country>
<State xsi:type="xsd:string">?</State>
<Street xsi:type="xsd:string">?</Street>
</input>
</com:echoAddress>
</soapenv:Body>
</soapenv:Envelope>
Here is the method of the coldfusion component that will be called
<cffunction
name="echoAddress"
returnType="address"
output="false"
access="remote">
<cfargument
name="input"
type="address">
<cfreturn #arguments.input#>
</cffunction>