2007-05-22

Axis2 1.2 BASIC Authentication

Call me stupid, but I spent the better part of the afternoon to figure out how to soap a server that expects user credentials encoded in BASIC authentication. (You know, like user:password scrambled with base64.)

Players in this drama: Apache Axis2 1.2, therefrom the wsdl2java compiler with databinding xmlbeans, the custom target server (sporting Axis2 1.1.1 himself) and yours truly.

The wsdl2java compiler (generator) works perfectly and leaves you a Stub class to start from. But there's no way to tell this stub straightforwardly that we're needing to basic authenticate with the server to get our call through.

To guess from the Axis2 JIRA and documentation, all you need is access to the Options object, create an Auhenticator and set some of its properties. As to which properties, the documentation is incorrect (as of 2007-05-22, I'll open a JIRA ticket on it).

Update: The bug is already fixed in subversion.

It tells us:

Options options = new Options(); HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); auth.setUsername("username"); auth.setPassword("password"); // set if realm or domain is know options.setProperty(org.apache.axis2.transport.http.HTTPConstants.BASIC_AUTHENTICATE,auth);

When it should be (in the context of a generated Stub):

  1. YourStub stub = new YourStub("-- your service endpoint --");
  2. Options options = stub._getServiceClient().getOptions();
  3. HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
  4. auth.setPreemptiveAuthentication(true);
  5. auth.setPassword("root");
  6. auth.setUsername("root");
  7. options.setProperty(HTTPConstants.AUTHENTICATE,auth);

Note how it's HTTPConstants.AUTHENTICATE, because client and server ought to discuss which specific authentication scheme to use. If that doesn't work (as with my stuff), add the statement auth.setPreemptiveAuthentication(true);, which seems to end all discussions and just gets the BASIC authentication through.

I put it down here in length, because there are so many places where older versions of this are presented, and they just don't work.

1 Kommentar:

Davanum Srinivas (dims) hat gesagt…

Fixed in latest svn:
http://svn.apache.org/viewvc?view=rev&revision=541728

thanks,
dims