Mule Set JSESSIONID from first into 2nd REST request or how to put the cookie through - rest

for my Thesis I'm integrating Bonita BPM into a Mule SOA.
To start a new case or process-instance in Bonita I have to call the Bonita REST. First I have to authenticate with that Bonita REST. And here starts my problem.
The authentication works like "You have to call the loginservice and put the responding cookie in all future request".
How could this be done inside a mule flow ? Some articles told me that copy-properties propertyName="JSESSIONID" should do that. But this does not work.
Does anybody have a idea ?
Further heres my flow and the related print messages:
PRINT1 : CopyPropertiesTransformer: Property value for is null, no property will be copied
PRINT 2 : LoggerMessageProcessor: {Set-Cookie=JSESSIONID=F60114E3ECB450A62171E3D63EAC3E4D; Path=/bonita/; HttpOnly}
PRINT 3 : Response code 401 mapped as failure. Message payload is of type: BufferInputStream
<http:request-config name="bos" host="localhost"
port="8080" basePath="/bonita" doc:name="bos-connection" />
<flow name="sendOrderFlow">
<http:listener config-ref="HTTP_Listener_Configuration"
path="/" doc:name="HTTP" />
<http:request config-ref="bos" path="loginservice"
method="GET" followRedirects="false" doc:name="bos-login">
<http:request-builder>
<http:query-param paramName="username" value="walter.bates" />
<http:query-param paramName="password" value="bpm" />
</http:request-builder>
</http:request>
<copy-properties propertyName="JSESSIONID" /> <!-- PRINT 1 HERE -->
<logger message="#[headers:INBOUND:Set-Cookie]" level="INFO" /> <!-- PRINT 2 HERE -->
<http:request config-ref="bos"
path="API/bpm/process" method="GET" followRedirects="false" doc:name="bos-listAvailableProcesses">
<http:request-builder>
<http:query-param paramName="p" value="0" />
</http:request-builder>
</http:request>

Additionally to JSESSIONID you also need to include X-Bonita-API-Token in HTTP header. The value of this header is provide as a cookie sent with the answer to the authentication (i.e. the call to loginservice).

Related

Mule with Facebook connector - OAuth access token could not be extracted from

I m using below code to authorize Facebook API. but m getting error -
Root Exception stack trace:
java.lang.IllegalArgumentException: OAuth access token could not be extracted from: {"access_token":"EAAJmNrYXQ4wBAFJIv69EuGaeUlh8LZCAUsZBLMlp8IDbyn9JLxtOsSVb3pVn6pdJb4mTzjVCrX14fBAoEuHBIOhYBSEyjPBr0l4ahOwef9l7o4BhLtzu0bACBqee7LY48OC51BDQhmea3ZANokY4KOj9HZCN6eAZD","token_type":"bearer","expires_in":5112514}
<http:listener-config name="callback" host="localhost" port="3000" doc:name="HTTP Listener Configuration" />
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="AutorizeFacebook" >
<http:listener config-ref="HTTP_Listener_Configuration" path="/facebookauthorize" doc:name="HTTP"/>
<facebook:authorize config-ref="Facebook" doc:name="Authorize" />
<set-session-variable doc:name="Save Access Token" value="\#[flowVars['OAuthAccessTokenId']]" variableName="accessTokenId"/>
<choice doc:name="Choice">
<when expression="#[flowVars['OAuthAccessTokenId']]!= null">
<logger message="Authorization Successful" level="INFO"
doc:name="Logger" />
<set-payload value="Facebook Authorization Successful"
doc:name="Set Payload" />
</when>
<otherwise>
<logger message="Authorization Failed" level="INFO" doc:name="Logger" />
<set-payload value="Facebook Authorization Failed"
doc:name="Set Payload" />
</otherwise>
</choice
</flow>
This error is due to change in Facebook API, accessToken is returned in a JSON string.
The Regex for the access token is \"access_token\":\"([^&]+?)\"
and for expiration time you have \"expires_in\":([^&]+?),")
Use DEVKIT to install connector to your studio by cloning facebook repo
Clone updated facebook connector project from
https://github.com/mulesoft/facebook-connector
import to studio as anypoint connector project
install connector to your studio and use facebook connector in your flows

How to use Choice Pattern over Soap Request in Mule ESB?

I have an endpoint accepting Soap Requests, after this endpoint, it goes to a Transform Message which generates the appropriate request to an external web service.
What I want to do is to use the Choice Pattern to decide to which external web service I must redirect.
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<cxf:configuration name="CXF_Configuration" enableMuleSoapHeaders="true" initializeStaticBusInstance="true" doc:name="CXF Configuration"/>
<ws:consumer-config name="Web_Service_Consumer" service="KarmaService" port="KarmaPort" serviceAddress="http://localhost:8080/TestingWS/Karma" wsdlLocation="http://localhost:8080/TestingWS/Karma?wsdl" doc:name="Web Service Consumer"/>
<flow name="testingChoice">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<cxf:proxy-service configuration-ref="CXF_Configuration" payload="body" doc:name="CXF"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://karmapackage/
---
{
ns0#sayHello: {
arg0: payload.invoke.arg0
}
}]]></dw:set-payload>
</dw:transform-message>
<choice doc:name="Choice">
<when expression="#[payload]">
<logger message="Info1" level="INFO" doc:name="Logger"/>
</when>
<otherwise>
<logger message="Default" level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
<ws:consumer config-ref="Web_Service_Consumer" operation="sayHello" doc:name="Web Service Consumer"/>
<logger message="Andando" level="INFO" doc:name="Logger"/>
</flow>
Right now, Choice is redirecting to Logger info, just to know what it is doing.
I don't know how to set the expression on the when condition to check if arg0 has the value choosePath1 for example.
I would appreciate any help,
Thanks in advance
Check this post, write xpath expression based on your transformed xml. Mule 3.4.0 Choice router based on presence of a node in payload using Xpath
Also check how to build xml xpath on mule documents
https://docs.mulesoft.com/mule-user-guide/v/3.8/xpath

Error while consuming REST service over HTTPs

I have a simple REST HTTPS POST, the uri of it is like that: https://paymentservicestest.informa.com/mcas_services.asp?
which works perfectly to run in a browser, Postman, etc. With Mule 3.8 HTTP I select the uri from the RAML generataed specification, set uri-param and still I am getting an exception and Code below.
ERROR 2016-10-11 16:16:52,944 [[tstconnection].HTTP_Listener_Configuration.worker.01] org.mule.module.http.internal.request.DefaultHttpRequester: Remote host closed connection. Possible SSL/TLS handshake issue. Check protocols, cipher suites and certificate set up. Use -Djavax.net.debug=handshake for further debugging.
ERROR 2016-10-11 16:16:53,025 [[tstconnection].HTTP_Listener_Configuration.worker.01] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Error sending HTTP request.
Payload : {NullPayload}
Payload Type : org.mule.transport.NullPayload
Element : /tstconnectionFlow/processors/1 # tstconnection:tstconnection.xml:14 (HTTP)
Element XML : <http:request config-ref="HTTP_Request_Configuration" path="/mcas_services.asp" method="POST" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName="username" value="XXXXX"></http:query-param>
<http:query-param paramName="password" value="XXXXX"></http:query-param>
<http:query-param paramName="method" value="XXXXX"></http:query-param>
<http:query-param paramName="source" value="XXXXX"></http:query-param>
<http:query-param paramName="cardtype" value="XXXXX"></http:query-param>
<http:query-param paramName="currency" value="XXXXX"></http:query-param>
</http:request-builder>
</http:request>
--------------------------------------------------------------------------------
Root Exception stack trace:
java.io.IOException: Remotely closed
My sample Code is :
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="2020" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="paymentservice.informa.com" port="443" connectionIdleTimeout="300000" responseTimeout="300000" doc:name="HTTP Request Configuration" />
<flow name="tstconnectionFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<logger message="sampleTest" level="INFO" doc:name="Logger"/>
<http:request config-ref="HTTP_Request_Configuration" path="/mcas_services.asp" method="GET" doc:name="HTTP">
<!-- <http:request-builder>
<http:query-param paramName="qParams1" value="#[flowVars.qParams]"/>
</http:request-builder> -->
<http:request-builder>
<http:query-param paramName="username" value="XXXXXX"/>
<http:query-param paramName="password" value="XXXXXX"/>
<http:query-param paramName="method" value="XXXXXXX"/>
<http:query-param paramName="source" value="XXXXX"/>
<http:query-param paramName="cardtype" value="XXXX"/>
<http:query-param paramName="currency" value="XXX"/>
</http:request-builder>
</http:request>
<logger level="INFO" doc:name="blankResponse"/>
<logger message="Reponse: #[payload]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
It looks like you have a typo in your URI
I can see from your post that the actual URI should be:
https://paymentservices.informa.com/
whilst in your config you are calling the following URI:
https://paymentservice.informa.com/
make sure you include the 's' in "services", this should at least make a successful request to the correct server.
Change your HTTP_Request_Configuration to:
<?xml version="1.0" encoding="UTF-8"?>
<mule
...
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="paymentservices.informa.com" port="443" connectionIdleTimeout="300000" responseTimeout="300000" doc:name="HTTP Request Configuration" />
...
</mule>

Add User and Pass to SOAP Header in Mule

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>

Spring Security Redirect if no access on page

I have a j2ee web application using spring web flow ang spring security. I want to redirect the user to page(maybe an error page) if the user's role has no access on the page being accessed because currently I get the error
Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.
If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.
How do I do this redirection.I tried the access-denied-page attribute of security:http but I still get the error. Here's my configuration for security-http.
By the way.I am using Spring Faces and Facelets. Could this have been the cause of the problem?
<!-- Configure Spring Security -->
<security:http auto-config="true" access-denied-page="/deniedpage.xhtml"
session-fixation-protection="newSession">
<security:intercept-url pattern="/main.do"
access="ROLE_SUPERVISOR, ROLE_USER" />
<security:intercept-url pattern="/logoutSuccess.do"
access="ROLE_SUPERVISOR, ROLE_USER" />
<security:intercept-url pattern="/edit.do"
access="ROLE_SUPERVISOR" />
<security:intercept-url pattern="/register.do"
access="ROLE_SUPERVISOR" />
<security:intercept-url pattern="/admin_main.do"
access="ROLE_SUPERVISOR" />
<security:intercept-url pattern="/*"
access="IS_AUTHENTICATED_ANONYMOUSLY" />
<security:form-login login-page="/loginForm.do"
default-target-url="/main.do" authentication-failure-url="/loginForm.do?login_error=1" />
<security:logout logout-url="/logout.do"
invalidate-session="true" logout-success-url="/logoutSuccess.do" />
<security:concurrent-session-control
max-sessions="-1" exception-if-maximum-exceeded="true" expired-url="/loginform.do" />
</security:http>
The access-denied-page attribute of security:http should be enough, show us the Spring configuration you are using.
In the meantime try adding this to web.xml:
<error-page>
<error-code>404</error-code>
<location>notfound.jsp</location>
</error-page>