Apache Axis2 1.5.1 and NTLM Authentication

11,059

Try this: http://robaustin.wikidot.com/axis It works for me. You need to call setupCertsAndCredential() before getService()

private void setupCredential() {
  final NTCredentials nt = new NTCredentials("user", "pass", "", "domain");
  final CredentialsProvider myCredentialsProvider = new CredentialsProvider() {
   public Credentials getCredentials(AuthScheme scheme, String host, int port, boolean proxy) throws CredentialsNotAvailableException {
    return nt;
   }
  };
  DefaultHttpParams.getDefaultParams().setParameter("http.authentication.credential-provider", myCredentialsProvider);
 }

ServiceStub getService() {  

  try {   
    ServiceStub stub = new ServiceStub(   
        "http://myserver/some/path/to/webservices.asmx"); // this service is hosted on IIS   

    return stub;    
  } catch (AxisFault e) {    
      e.printStackTrace();    
  }    
      return null;    
}    
Share:
11,059
andyczerwonka
Author by

andyczerwonka

Business and Software Architect, Entrepreneur, Polyglot Programmer, Scala Enthusiast

Updated on June 04, 2022

Comments

  • andyczerwonka
    andyczerwonka almost 2 years

    I've browsed all of the discussions here on StackOverflow regarding NTLM and Java, and I can't seem to find the answer. I'll try and be much more specific.

    Here's some code that returns a client stub that (I hope) is configured for NTLM authentication:

    ServiceStub getService() {
      try {
        ServiceStub stub = new ServiceStub(
            "http://myserver/some/path/to/webservices.asmx"); // this service is hosted on IIS
        List<String> ntlmPreferences = new ArrayList<String>(1);
        ntlmPreferences.add(HttpTransportProperties.Authenticator.NTLM);
        HttpTransportProperties.Authenticator ntlmAuthenticator = new HttpTransportProperties.Authenticator();
        ntlmAuthenticator.setAuthSchemes(ntlmPreferences);
        ntlmAuthenticator.setUsername("me");
        ntlmAuthenticator.setHost("localhost");
        ntlmAuthenticator.setDomain("mydomain");
        Options options = stub._getServiceClient().getOptions();
        options.setProperty(HTTPConstants.AUTHENTICATE, ntlmAuthenticator);
        options.setProperty(HTTPConstants.CHUNKED, "false");
        return stub;
      } catch (AxisFault e) {
          e.printStackTrace();
      }
          return null;
    }
    

    This returns a valid SerivceStub object. When I try to invoke a call on the stub, I see the following in my log:

    Jun 9, 2010 12:12:22 PM org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
    INFO: NTLM authentication scheme selected
    Jun 9, 2010 12:12:22 PM org.apache.commons.httpclient.HttpMethodDirector authenticate
    SEVERE: Credentials cannot be used for NTLM authentication: org.apache.commons.httpclient.UsernamePasswordCredentials
    

    Does anyone have a solution to this issue?