Ok, I guess my previous post was a bit winded, and I got no response. No big 
deal. I was able to get my application working using HC 4.3 for NTLMv2 
authentication. I used your ClientPreemptiveDigestAuthentication class as a 
guide, and replaced all DigestScheme stuff with NTLM scheme stuff. I attach my 
code that is a slight variant of the Digest class. You may add this to your 
examples package if you wish.

I do see one issue you may want to address. This call in the code below (line 
44): entity.getContentLength() always returns -1 for me. 
The entity does unpack properly containing my SOAP response, even though 
getContentLength does not tell me the size of the payload.

Of secondary importance, the symmetry is missing for the NTLMScheme class. You 
cannot instantiate an NTLMScheme object like you can a DigestScheme object, you 
need to go directly to an AuthScheme through the NTLMSchmeFactory. And the 
NTLMSchemeFactory does not have a getNTLMScheme method, just a method that 
returns an AuthScheme object. I don't see any way of actually handling an 
NTLMScheme object. Or perhaps you meant to hide the DigestScheme object behind 
a factory? I suppose not a big deal, but maybe something you want to consider.

    private String getSoapReponse() {
        String retStr = null;
        CloseableHttpClient httpclient = null;
        try {
            String localIp = Inet4Address.getLocalHost().getHostAddress();
            HttpHost targetHost = new HttpHost(_host, 443, "https");
            CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(new AuthScope(targetHost), new 
NTCredentials(_user, _password, localIp, _domain));

            httpclient = 
HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();

// Create AuthCache instance
            AuthCache authCache = new BasicAuthCache();

// NTLM-based AuthScheme
            NTLMSchemeFactory f = new NTLMSchemeFactory();
            HttpContext ctx = new BasicHttpContext();
            AuthScheme ns = f.create(ctx);
            authCache.put(targetHost, ns);

// Add AuthCache to the execution context
            HttpClientContext localContext = HttpClientContext.create();
            localContext.setAuthCache(authCache);

            HttpGet http = new HttpGet(_serviceEndpoint);

            System.out.println("executing request: " + http.getRequestLine());
            System.out.println("to target: " + targetHost);

            CloseableHttpResponse response = httpclient.execute(targetHost, 
http, localContext);
            try {
                HttpEntity entity = response.getEntity();

                System.out.println("----------------------------------------");
                System.out.println(response.getStatusLine());
                if (entity != null) {
                    System.out.println("Response content length: " + 
entity.getContentLength());
                    retStr = EntityUtils.toString(entity);
                }
                EntityUtils.consume(entity);
            } finally {
                response.close();
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if (httpclient != null)
                    httpclient.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return retStr;
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

  • 4.3 issue with NTLMv2... Godbey, David J. (HQ-LM020)[DIGITAL MANAGEMENT INC.]

Reply via email to