How to authenticate an Axis2 client running against a Windows Web Server
bouncer_big.JPG

If you are running against a Windows web server, you may have problems with authentication, if you get the following error :

INFO org.apache.commons.httpclient.auth.AuthChallengeProcessor - ntlm authentication scheme selected
INFO org.apache.commons.httpclient.HttpMethodDirector - No credentials available for NTLM <any realm>@yourhost:80
INFO org.apache.axis2.transport.http.HTTPSender - Unable to sendViaPost to url[http://yoururl]

The webserver is trying to authenticate via windows authentication, you have to set up a NTCredentials, the following code shows you how to overcome this issue :

import org.apache.axis2.AxisFault;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.auth.AuthScheme;
import org.apache.commons.httpclient.auth.CredentialsNotAvailableException;
import org.apache.commons.httpclient.auth.CredentialsProvider;
import org.apache.commons.httpclient.params.DefaultHttpParams;
 
public class Main {
 
    public static void main(String... args) throws AxisFault {
 
        final NTCredentials nt = new NTCredentials("your username", "your password", "", "your domain");
        final CredentialsProvider myCredentialsProvider = new CredentialsProvider() {
            public Credentials getCredentials(final AuthScheme scheme, final String host, int port, boolean proxy) throws CredentialsNotAvailableException {
                return nt; 
            }
        };
 
        DefaultHttpParams.getDefaultParams().setParameter("http.authentication.credential-provider", myCredentialsProvider);
 
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License