Java – How to add Basic authentication in Apache Axis Web Service (SOAP)

axisbasic-authenticationjavamavensoap

I use a Maven plugin (org.codehaus.mojo > axistools-maven-plugin) + a WSDL file to generate a Soap Web Service.

Genarated files in target/generated-source/wsdl2java/com.comp.proj are:

  • Foo.java (java interface)
  • FooServiceLocator.java
  • FooSoapBindingImpl.java (java empty implementation)
  • FooSoapBindingSkeleton.java
  • FooSoapBindingStub.java

In my project, i create FooSoapBindingImpl.java in a package with the same name + add my custom code in this java implementation.

This Web services is ready for use in production.

So, today I add Basic authentication on my client (header => Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==)

How to add a check on this Basic authentication in my Axis Web Service?

Best Answer

The "Axis security section 'Authenticating the caller'" mentions:

Clients can authenticate themselves with client certificates, or HTTP basic authentication.
The latter is too weak to be trustable on a non-encrypted channel, but works over HTTPS.

The MessageContext class will be configured with the username and password of the sender when SOAP messages are posted to the endpoint;*

See an example here.

use the appropriate getters to see these values. Note that Axis does not yet integrate with the servlet API authentication stuff.

See a getter example in this answer.