Configuring Basic Security Filter for HTTP Connector
Consider a Mule app that exposes an API for accessing sensitive customer information, such as personal details and order history. To secure this API, you want to implement basic security using a username and password combination. The Anypoint Platform for HTTP (HTTP Connector) Basic Security Filter operation enables you to enforce basic authentication.
The following example illustrates how to configure the Basic Security Filter operation to ensure that only authorized users can access the protected API.
-
In Anypoint Studio, add an HTTP Listener source to your flow. This serves as the entry point for incoming API requests.
-
Drag the Basic Security Filter operation after the HTTP Listener. The operation validates the username and password provided in the request headers.
-
Select the Basic Security Filter operation from your flow.
-
Configure the Basic Security Filter operation with the authentication Realm and Security providers.
-
Continue building your Mule flow by adding the logic for handling API requests, retrieving customer information, or performing other operations.
In the Configuration XML, the configuration looks like this:
<http:listener-config name="HTTP_Listener_config" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="testFlow1">
<http:listener config-ref="HTTP_Listener_config" path="/test"/>
<http:basic-security-filter realm="MuleRealm">
<http:security-providers >
<http:security-provider value="test" />
</http:security-providers>
</http:basic-security-filter>
<!-- Add your API logic here -->
</flow>