You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Dave Godbey (JIRA)" <ji...@apache.org> on 2013/06/03 19:27:20 UTC

[jira] [Created] (HTTPCLIENT-1364) Consider reorganizing authentication schemes

Dave Godbey created HTTPCLIENT-1364:
---------------------------------------

             Summary: Consider reorganizing authentication schemes
                 Key: HTTPCLIENT-1364
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1364
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: HttpClient
    Affects Versions: 4.3 Beta1
         Environment: Fedora 15 java 1.6.0_30
            Reporter: Dave Godbey
            Priority: Minor


The attached code is closely based on the ClientPreemptiveDigestAuthentication example class. Compare this class to my own code below that using NTLMv2 authentication.

Notice the following between the two code sets: 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. Should all the authentication schemes behave similarly?

See code below:

    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;
    }


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org