Avatar of sangameshrh
sangameshrh asked on

Problem With NTLM authentication while using Apache HTTPClient APIs

I am using Apache HTTPClient for file uploading.(Apache File Upload at the server side)
Code looks like this
if(proxyStatus)
{
      client.getHostConfiguration().setProxy(proxyHost,port);
      if(userName!=null)
      {
            HttpState httpState = new HttpState();
            httpState.setProxyCredentials(new AuthScope(proxyHost,port),new NTCredentials(userName,password));
            filePost.setDoAuthentication(true);
            client.setState(httpState);
      }
      else
      {
            filePost.setDoAuthentication(false);
      }
}

Its working file if the proxy is without authentication or with Authentication.

But at one place I have encountered an error like this

Oct 24, 2007 1:36:28 PM org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
INFO: ntlm authentication scheme selected
Oct 24, 2007 1:36:28 PM org.apache.commons.httpclient.HttpMethodDirector authenticate
SEVERE: Credentials cannot be used for NTLM authentication: org.apache.commons.httpclient.UsernamePasswordCredentials
org.apache.commons.httpclient.auth.InvalidCredentialsException: Credentials cannot be used for NTLM authentication: org.apache.commons.httpclient.UsernamePasswordCredentials
      at org.apache.commons.httpclient.auth.NTLMScheme.authenticate(NTLMScheme.java:332)
      at org.apache.commons.httpclient.HttpMethodDirector.authenticateProxy(HttpMethodDirector.java:320)
      at org.apache.commons.httpclient.HttpMethodDirector.authenticate(HttpMethodDirector.java:232)
      at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
      at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
      at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
      at Test.submitMessage(UserValidation.java:276)
      at SendMessage.run(SendMessage.java:305)
      at java.lang.Thread.run(Unknown Source)
Oct 24, 2007 1:36:28 PM org.apache.commons.httpclient.HttpMethodDirector processProxyAuthChallenge
INFO: Failure authenticating with NTLM <any realm>@172.16.200.3:8080

Thanks
Java EEJava

Avatar of undefined
Last Comment
Mick Barry

8/22/2022 - Mon
Mick Barry

try specifying the domain/realm
ASKER
sangameshrh

Can you tell me how?
ASKER CERTIFIED SOLUTION
Mick Barry

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck