In this post, we will take a look at how to access a web service which is secured with http basic authentication using
WSO2 ESB.
This scenario is depicted by the following diagram.
There is a web service which is secured with HTTP Basic Authentication and it is required to be consumed by a client who does not send the required authentication credentials in the request. So a proxy service is created which will inject these basic authentication headers to incoming request and send it to the actual secured service.
If you want to know how to secure a web service with http basic authentication,
this is a good reference written by
Prabath.
The required authentication credentials are sent to the service in a HTTP header named 'Authorization'. So it will look similar to the following.
Authorization: Basic cHJhYmF0aDpwcmFiYXRo
This is the base64 encoded value of (username:password) pair. So this header will be created using a
Property Mediator in ESB. Following is the corresponding entry in the Synapse configuration language.
This will concatenate the value of "Basic " (please mind the space after the word "Basic") and base64 encoded value of "username:password" and set it as the Authorization header at the transport level.
And this is how it looks like when it is configured through the UI.
And this is the complete Proxy configuration for your reference.