title: Invoke Secured Webservice with WS Policy using Camel-CXF
body: <p>We are trying to invoke Secured Webservice using Camel CXf component. WSDL has wsp:Policy defined in it and I am able to successfully invoke service from soapUI by passing username/password but facing lot of problems if i try to invoke service using Camel-Cxf component or invoke using generated stub.  Any help is appreciated.</p>
  
  <p>WSDL has following policy defined in it.</p>
  
  <pre><code>            &lt;wsp:Policy wsu:Id="WSHttpBinding_ReferenceLookupLists_policy"&gt;
                      &lt;wsp:ExactlyOne&gt;
                          &lt;wsp:All&gt;
                              &lt;http:BasicAuthentication
                                  xmlns:http="http://schemas.microsoft.com/ws/06/2004/policy/http"/&gt;
                              &lt;sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"&gt;
                                  &lt;wsp:Policy&gt;
                                      &lt;sp:TransportToken&gt;
                                          &lt;wsp:Policy&gt;
                                              &lt;sp:HttpsToken RequireClientCertificate="false"/&gt;
                                          &lt;/wsp:Policy&gt;
                                      &lt;/sp:TransportToken&gt;
                                      &lt;sp:AlgorithmSuite&gt;
                                          &lt;wsp:Policy&gt;
                                              &lt;sp:Basic256/&gt;
                                          &lt;/wsp:Policy&gt;
                                      &lt;/sp:AlgorithmSuite&gt;
                                      &lt;sp:Layout&gt;
                                          &lt;wsp:Policy&gt;
                                              &lt;sp:Strict/&gt;
                                          &lt;/wsp:Policy&gt;
                                      &lt;/sp:Layout&gt;
                                  &lt;/wsp:Policy&gt;
                              &lt;/sp:TransportBinding&gt;
                              &lt;wsaw:UsingAddressing/&gt;
                          &lt;/wsp:All&gt;
                      &lt;/wsp:ExactlyOne&gt;
                  &lt;/wsp:Policy&gt;
  </code></pre>
  
  <p>Cxf endpoint in blueprint file:</p>
  
  <pre><code>        &lt;camel-cxf:cxfEndpoint id="abclookupEndpoint"
                      wsdlURL="wsdl/abclookupLists.wsdl"
                      endpointName="tns:WSHttpBinding_abclookup"
                      serviceName="tns:abclookup"
                      address="http://abc.abc/2013/12/6/abclookup.svc"
                      xmlns:tns="http://abc.abc/2013/12/6/ServiceContracts/"&gt;
                  &lt;camel-cxf:outInterceptors&gt;
                     &lt;ref component-id="abcOutInterceptor"/&gt;
                  &lt;/camel-cxf:outInterceptors&gt;
                  &lt;camel-cxf:properties&gt;
                      &lt;entry key="dataFormat" value="PAYLOAD"/&gt;
                  &lt;/camel-cxf:properties&gt;
              &lt;/camel-cxf:cxfEndpoint&gt;
  </code></pre>
  
  <p>Route Builder class which uses above defined cxf endpoint
          @Override
              public void configure() throws Exception {</p>
  
  <pre><code>    from("direct:retrieveData").routeId(getRouteId().concat("svc.refLookupList"))
              .log(LoggingLevel.DEBUG, "Entered into direct:retrieveData route")
              .setHeader("operationName", constant("GetCustomFieldDropdownList"))
              .setHeader("SOAPAction",constant(getSoapActionHeader()))
              .bean("soapRequestBean","constructRequest")
              .to("cxf:bean:abclookupEndpoint?username=aaaaaaaa&amp;password=bbbbbbbb")
              .log(LoggingLevel.INFO, "Service Response : ${body}")
              .end();
  </code></pre>
  
  <p>Tried adding AuthorizationPolicy like below but did not help
          Map properties = new HashMap();</p>
  
  <pre><code>            AuthorizationPolicy authPolicy = new AuthorizationPolicy();
              authPolicy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_BASIC);
              authPolicy.setUserName("aaaaaaaa");
              authPolicy.setPassword("bbbbbbbb");
              authPolicy.setAuthorization("true");
  
              properties.put("org.apache.cxf.configuration.security.AuthorizationPolicy",authPolicy);
              CxfEndpoint myCxfEp = (CxfEndpoint)getContext().getEndpoint("cxf:bean:abclookupEndpoint");
              myCxfEp.setProperties(properties);*/
  </code></pre>
  
  <p>Exception message in logs when tried to invoke serivce:</p>
  
  <pre><code>"No assertion builder for type  http://schemas.microsoft.com/ws/06/2004/policy/http}BasicAuthentication registered. Exception in thread "main" org.apache.cxf.ws.policy.PolicyException: None of the policy alternatives"
  </code></pre>