This documentation is for WSO2 ESB version 4.0.3. View documentation for the latest release.

HTTP Basic Authentication over a Proxy Server

ESB may be behind a firewall, and it may want to talk to a server through a Proxy Server. A Proxy Server may require HTTP basic authentication.

There are several configurations that need to be done in order to configure ESB to handle this.

1. Tell ESB that it is behind a Proxy Server. To do this, edit the axis2.xml file in the repository/conf directory.

2. Edit the transportSender configuration of the http transport in axis2.xml. The configurations are self-explanatory.

<transportSender name="http" class="org.apache.synapse.transport.nhttp.HttpCoreNIOSender">
<parameter name="non-blocking" locked="false">true</parameter>
<parameter name="http.proxyHost" locked="false">localhost</parameter>
<parameter name="http.proxyPort" locked="false">8080</parameter>
</transportSender>

3. Set the following two properties in the synapse configuration before doing the send through the Proxy Server.

<syn:property name="Proxy-Authorization" expression="fn:concat('Basic', base64Encode('userName:password'))" scope="transport"/>
<syn:property name="POST_TO_URI" value="true" scope="axis2"/>

The first property sets the Proxy-Authorization HTTP transport header with the base64 encoded user name and password as expected by the HTTP basic authentication.

The second property makes the out-going URL a complete URL understandable by the Proxy Server.

For example, in normal scenarios the outgoing request is sent as following:

POST /services/SimpleStockQuoteService HTTP/1.1

But the Proxy Server requires sending the actual URL:

POST [http://localhost:9000/services/SimpleStockQuoteService] HTTP/1.1

Sample of the Proxy Service with these two properties:

<syn:proxy name="StockQuoteProxy" startOnLoad="true">
<syn:target>
<syn:inSequence>
<syn:property name="Proxy-Authorization" expression="fn:concat('Basic ', base64Encode('supun:test123'))" scope="transport"/>
<syn:property name="POST_TO_URI" value="true" scope="axis2"/>
<syn:send>
<syn:endpoint name="endpoint_urn_uuid_379C485AD3CB65037F10216600509076498395882">
<syn:address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</syn:endpoint>
</syn:send>
</syn:inSequence>
<syn:outSequence>
<syn:send/>
</syn:outSequence>
</syn:target>
<syn:publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
</syn:proxy>