Scenario
Retrieve the IP address of the actual originator of the API request in below mentioned scenario.
In the above deployment scenario, I had a requirement to the get IP address of the client from ESB.
Prerequisite
Solution
'X-Forwarded-For' header property is a transport level header property. This property is normally used by Load Balancer to stamp the IP address of the client which is requesting a service from back-end server.
This property can be used append Client-IP address in the WSO2 API Manager. Later on by accessing this property, relevant Client-IP address can be fetched from ESB side. I included following filter configuration in WSO2 API Manager to append Client-IP address to 'X-Forwarded-For' header property.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<filter source="get-property('transport','X-Forwarded-For')" regex=".*"> | |
<then> | |
<property name="coming-X-Forwarded-For" expression="fn:concat(get-property('transport','X-Forwarded-For'), ', ')" scope="axis2" type="STRING"/> | |
<property name="clientIP" expression="get-property('axis2','REMOTE_ADDR')"/> | |
<property name="X-Forwarded-For" expression="fn:concat(get-property('axis2','coming-X-Forwarded-For'), get-property('clientIP'))" scope="transport" type="STRING"/> | |
</then> | |
<else> | |
<property name="X-Forwarded-For" expression="get-property('axis2','REMOTE_ADDR')" scope="transport" type="STRING"/> | |
</else> | |
</filter> |
Now from the ESB side, you can obtain the Client-IP address from 'X-Forwarded-For' header property by having following synapse configuration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<property name="coming-X-Forwarded-For" expression="get-property('transport','X-Forwarded-For')"/> |