I'm trying to do create a CXF soap web service client to make soap calls with a Kerberos authenticated SharePoint instance.
I import the following:
- org.apache.cxf:cxf-rt-frontend-jaxws:3.2.6
- org.apache.cxf:cxf-rt-transports-http:3.2.6
- org.apache.cxf:cxf-rt-transports-http-hc:3.2.6
- org.apache.cxf:cxf-rt-ws-security:3.2.6
Here is my java program.
import crawler.common.sharepoint.stubs.lists.Lists;
import crawler.common.sharepoint.stubs.lists.ListsSoap;
import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.configuration.security.AuthorizationPolicy;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit;
import org.apache.cxf.transport.http.auth.HttpAuthHeader;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.apache.cxf.ws.security.wss4j.KerberosTokenInterceptor;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
public class SharepointKerberosTesterClient {
public static void main(String[] args) {
System.setProperty("java.security.krb5.conf", "/home/ndipiazza/xxxx/spnego-http-client/krb5.conf");
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
System.setProperty("java.security.auth.login.config", "/home/ndipiazza/xxxx/spnego-http-client/login.conf");
String endpoint = "http://win-qbfsb933r5p/_vti_bin/Lists.asmx";
Service service = Service.create(Lists.SERVICE);
ListsSoap soap = service.getPort(ListsSoap.class);
BindingProvider bindingProvider = (BindingProvider) soap;
bindingProvider.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC,
Boolean.TRUE);
bindingProvider.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
Client client = ClientProxy.getClient(bindingProvider);
client.getEndpoint().put("org.apache.cxf.stax.maxChildElements", System.getProperty("org.apache.cxf.stax.maxChildElements") != null
? System.getProperty("org.apache.cxf.stax.maxChildElements") : "5000000");
HTTPConduit http = (HTTPConduit) client.getConduit();
AuthorizationPolicy authorization = new AuthorizationPolicy();
authorization.setAuthorization("SharePoint");
authorization.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_NEGOTIATE);
http.setAuthorization(authorization);
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setAutoRedirect(true);
TLSClientParameters tlsClientParameters = new TLSClientParameters();
tlsClientParameters.setDisableCNCheck(true);
http.setTlsClientParameters(tlsClientParameters);
http.setClient(httpClientPolicy);
System.out.println("Size of lists: " + soap.getListCollection().getContent().size());
}
}
If you take a look at this example, http://cxf.apache.org/docs/jaxrs-kerberos.html#JAXRSKerberos-AuthorizationPolicy there is a special class KerberosAuthOutInterceptor that is able to add the Negotiate Authorization headers as required.
But in 3.1.x and 3.2.x versions of CXF that doesn't seem to exist.
Instead there is a https://github.com/apache/cxf/blob/master/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/interceptors/SpnegoTokenInterceptorProvider.java that I think I am supposed to use.
But I do not know how to use an interceptor provider. Does anyone know how to use this with the programmatic (non-xml) declaration of CXF?