Return-Path: X-Original-To: apmail-hc-dev-archive@www.apache.org Delivered-To: apmail-hc-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 53D4DD4B7 for ; Wed, 25 Jul 2012 08:19:55 +0000 (UTC) Received: (qmail 60589 invoked by uid 500); 25 Jul 2012 08:19:55 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 58294 invoked by uid 500); 25 Jul 2012 08:19:44 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 56152 invoked by uid 99); 25 Jul 2012 08:19:36 -0000 Received: from issues-vm.apache.org (HELO issues-vm) (140.211.11.160) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Jul 2012 08:19:36 +0000 Received: from isssues-vm.apache.org (localhost [127.0.0.1]) by issues-vm (Postfix) with ESMTP id CEAE9142868 for ; Wed, 25 Jul 2012 08:19:35 +0000 (UTC) Date: Wed, 25 Jul 2012 08:19:35 +0000 (UTC) From: "Oleg Kalnichevski (JIRA)" To: dev@hc.apache.org Message-ID: <153306593.100280.1343204375850.JavaMail.jiratomcat@issues-vm> In-Reply-To: <1809796459.63479.1342527035002.JavaMail.jiratomcat@issues-vm> Subject: [jira] [Commented] (HTTPCLIENT-1215) http://host and http://host:80 not considered the same for credential matching MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/HTTPCLIENT-1215?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13422079#comment-13422079 ] Oleg Kalnichevski commented on HTTPCLIENT-1215: ----------------------------------------------- Probably all it really takes is a map of default ports keyed by scheme generated based on content of a SchemeRegistry. Oleg > http://host and http://host:80 not considered the same for credential matching > ------------------------------------------------------------------------------ > > Key: HTTPCLIENT-1215 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1215 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient > Affects Versions: 4.2.1 > Reporter: Radai Rosenblatt > Fix For: 4.2.2 > > > the following code (taken from http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html section 4.8 and modified to use a URI) will not add authentication headers to the outgoing http request because the URI string does not explicitely specify the port: > URI uri = new URI("http://somedomain.com/stuff"); > HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); > DefaultHttpClient httpclient = new DefaultHttpClient(); > httpclient.getCredentialsProvider().setCredentials( > new AuthScope(targetHost.getHostName(), targetHost.getPort()), > new UsernamePasswordCredentials("username", "password")); > // Create AuthCache instance > AuthCache authCache = new BasicAuthCache(); > // Generate BASIC scheme object and add it to the local auth cache > BasicScheme basicAuth = new BasicScheme(); > authCache.put(targetHost, basicAuth); > // Add AuthCache to the execution context > BasicHttpContext localcontext = new BasicHttpContext(); > localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); > HttpGet httpget = new HttpGet(uri); > for (int i = 0; i < 3; i++) { > HttpResponse response = httpclient.execute(targetHost, httpget, localcontext); > System.err.println(response.getStatusLine()); > HttpEntity entity = response.getEntity(); > EntityUtils.consume(entity); > } > the root cause for this is in RequestAuthCache.java line 90: > HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); > if (target.getPort() < 0) { > SchemeRegistry schemeRegistry = (SchemeRegistry) context.getAttribute( > ClientContext.SCHEME_REGISTRY); > Scheme scheme = schemeRegistry.getScheme(target); > target = new HttpHost(target.getHostName(), > scheme.resolvePort(target.getPort()), target.getSchemeName()); > } > AuthState targetState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); > if (target != null && targetState != null && targetState.getState() == AuthProtocolState.UNCHALLENGED) { > AuthScheme authScheme = authCache.get(target); > if (authScheme != null) { > doPreemptiveAuth(target, authScheme, targetState, credsProvider); > } > } > the target has no port (meaning <0 ), so its recreated with the default http scheme port of 80. > meanwhile authCache uses the original target host as key, and so authScheme will be null. > explicitely declaring port 80 in the URI string works around this, but i think this should work by default. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa 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