NLTM auth using HttpUrlConnection failing

只愿长相守 提交于 2019-12-07 08:01:12

问题


I am trying to authenticate against a server supporting NTLM authentication in my Java application using java.net's HttpUrlConnection.

The problem is that the application fails to send the Authenticate response.

I have attached proxy to the http connection so that the traffic is routed via fiddler. In fiddler i can see Negotiate message being sent, and server Challenge is received. But after this, the application just stops saying it got a 401, without sending the type3 authenticate message.

Any ideas? Here is the code -

Authenticator.setDefault(new Authenticator() {
    public PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication("username",
                                          "password".toCharArray());
    }
});
URL url = new URL("https://service_url.svc");

// Proxy for fiddler
Proxy proxy = new Proxy(Proxy.Type.HTTP,
                  new InetSocketAddress("localhost", 8888));

// Create a connection
HttpURLConnection conn = (HttpURLConnection)url.openConnection(proxy);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);

InputStream is = conn.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = rd.readLine()) != null)
    System.out.println(line);

rd.close();

Appreciate any help. Thanks.

来源:https://stackoverflow.com/questions/10313356/nltm-auth-using-httpurlconnection-failing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!