Search code examples
oauth-2.0apache-camelcxfjbossfuseblueprint-osgi

How can I implement an OAuth flow in a CXF endpoint (SOAP) in Camel (preferably Blueprint)?


I would like to address a SOAP web service via camel-cxf endpoint. How can I implement an OAuth flow, preferably in the blueprint? Is that configurative or do I have to implement it myself?


Solution

  • I have found nice documentation on this:

    Basically, you have to implement interceptors and filters: Your blueprint.xml

    <bean id="tvServiceClientFactory" class="org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean">
        <property name="address" value="http://localhost:${http.port}/services/oauth/validate"/>
        <property name="headers">
            <map>
                <entry key="Accept" value="application/xml"/>
                <entry key="Content-Type" value="application/x-www-form-urlencoded"/>
            </map>
        </property>
    </bean>
    
    <bean id="tvServiceClient" factory-bean="tvServiceClientFactory" factory-method="createWebClient"/>
    
    <bean id="tokenValidator" class="org.apache.cxf.rs.security.oauth2.filters.AccessTokenValidatorClient">
        <property name="tokenValidatorClient" ref="tvServiceClient"/>
    </bean>
    
    <bean id="oauthFiler" class="org.apache.cxf.rs.security.oauth2.filters.OAuthRequestFilter">
        <property name="tokenValidator" ref="tokenValidator"/>
    </bean>
    
    <bean id="myApp" class="org.myapp.MyApp"/>
    
    <jaxrs:server id="fromThirdPartyToMyApp" address="/thirdparty-to-myapp">
       <jaxrs:serviceBeans>
          <ref bean="myApp"/>
      </jaxrs:serviceBeans>
      <jaxrs:providers>
          <ref bean="oauthFilter"/>
      </jaxrs:providers>
    </jaxrs:server>