Reputation: 119
i am using HTTP component of mule to connect to a REST API which is having a basic Authentication with USERNAME and PASSWORD . I used "HTTP settings" tab of HTTP component to supply the authentication details , username and Password. but i think its not working . Am i doing anything wrong ? is there any better way to call REST service which is having Basic authentication like.
Upvotes: 1
Views: 3060
Reputation: 119
HTTP outbound with basic authentication
Thanks everyone for replying !! The username and password on the connector is for when you want to secure your inbound endpoint with HTTP basic authentication.
When calling a external services that is secured with basic auth you should use the uri method
Upvotes: 0
Reputation: 6647
You should set the Basic Authentication value as a Header Property in to the outgoing Mule Message when you are consuming a REST service via the Mule HTTP outbound endpoint.
<flow name="consume_rest">
.............
..........
<set-property propertyName="Authorization" value="Basic Authorization String combination of Username and password" />
<http:outbound-endpoint exchange-pattern="request-response" method="POST" responseTimeout="20000"
host="localhost" path="rest.path" port="Port number" />
.............
.............
</flow>
Hope this helps.
Upvotes: 2
Reputation: 8311
The following is an example of REST Service with Basic Authentication :-
<mule-ss:security-manager>
<mule-ss:delegate-security-provider name="memory-provider" delegate-ref="authenticationManager" />
</mule-ss:security-manager>
<spring:beans>
<ss:authentication-manager alias="authenticationManager">
<ss:authentication-provider>
<ss:user-service id="userService">
<ss:user name="your username" password="your password" authorities="ROLE_ADMIN" />
<ss:user name="your username2" password="your password2" authorities="ROLE_USER" />
</ss:user-service>
</ss:authentication-provider>
</ss:authentication-manager>
</spring:beans>
<flow name="MainService" doc:name="MainService">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP">
<mule-ss:http-security-filter realm="realm" />
<mule-ss:authorization-filter requiredAuthorities="ROLE_ADMIN"/> <!-- Restrict a particular group of users -->
</http:inbound-endpoint>
<jersey:resources doc:name="REST">
<component class="com.test.services.schema.maindata.v1.Impl.MainDataImpl"/>
</jersey:resources>
</flow>
And for connecting an existing external REST Service from Mule use:- http://username:password@host/yourpath
in http outbound endpoint
Upvotes: 2