Nirosan
Nirosan

Reputation: 11

How to pass basic auth header to SOAP endpoint from WS02 Api Manager?

I am using API Manager 2.0, I have designed a new API and the production url is an end point of web service. In API I have added "Message Mediation Policies" to convert json to soap in request and convert back the soap to json in request. This works fine when there is no authentication.

When I tried to connect to an endpoint which is authenticated using basic am unable to send the auth header. Is it possible to pass and if so how to achieve it?

I have already tried Endpoint Security Schema and no success with that.

Upvotes: 1

Views: 1778

Answers (2)

Basanagouda Patil
Basanagouda Patil

Reputation: 91

You can do this by implementing a mediator which can be configured for the particular API. The class will be invoked before making ESB call during that you can inspect the request and set the header with the basic auth details. Steps. 1. Create a mediator project 2. Implement the log in the mediator class (handleRequest Method) 3. Export this class as a jar file 4. Copy it in Carbon_home/repository/components/lib 5. Configure the mediator for the particular API file is located(C:\WSO2\wso2am- 2.0.0\repository\deployment\server\synapse-configs\default\api) 6. add the configuration in the handlers section example

  1. Restart the server APM

Upvotes: 0

Bee
Bee

Reputation: 12513

If you configure Endpoint Security Scheme properly, you should see Authorization property like below, in your api file, in repository/deployment/server/synapse-configs/default/api/ directory. Double check if it's there.

   <resource methods="GET" url-mapping="/menu" faultSequence="fault">
      <inSequence>
         <property name="api.ut.backendRequestTime"
                   expression="get-property('SYSTEM_TIME')"/>
         <filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION">
            <then>
               <property name="Authorization"
                         expression="fn:concat('Basic ', 'YmhhdGhpeWE6cGFzc3dvcmQ=')"
                         scope="transport"/>
               <send>
                  <endpoint name="admin--PizzaShackAPI_APIproductionEndpoint_1">
                     <http uri-template="https://localhost:9443/am/sample/pizzashack/v1/api/"/>
                     <property name="ENDPOINT_ADDRESS"
                               value="https://localhost:9443/am/sample/pizzashack/v1/api/"/>
                  </endpoint>
               </send>
            </then>
            <else>
               <property name="Authorization"
                         expression="fn:concat('Basic ', 'YmhhdGhpeWE6cGFzc3dvcmQ=')"
                         scope="transport"/>
               <send>
                  <endpoint name="admin--PizzaShackAPI_APIsandboxEndpoint_1">
                     <http uri-template="https://localhost:9443/am/sample/pizzashack/v1/api/"/>
                     <property name="ENDPOINT_ADDRESS"
                               value="https://localhost:9443/am/sample/pizzashack/v1/api/"/>
                  </endpoint>
               </send>
            </else>
         </filter>
      </inSequence>
      <outSequence>
         <class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtResponseHandler"/>
         <send/>
      </outSequence>
   </resource>

Upvotes: 2

Related Questions