Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 47B85271B for ; Sat, 7 May 2011 15:30:43 +0000 (UTC) Received: (qmail 49070 invoked by uid 500); 7 May 2011 15:30:43 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 49035 invoked by uid 500); 7 May 2011 15:30:43 -0000 Mailing-List: contact commits-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 commits@hc.apache.org Received: (qmail 49028 invoked by uid 99); 7 May 2011 15:30:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 May 2011 15:30:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 May 2011 15:30:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3BB4323889E7; Sat, 7 May 2011 15:30:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1100557 - /httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java Date: Sat, 07 May 2011 15:30:18 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110507153018.3BB4323889E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Sat May 7 15:30:17 2011 New Revision: 1100557 URL: http://svn.apache.org/viewvc?rev=1100557&view=rev Log: Implemented proxy authentication for tunneled SSL connections Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java?rev=1100557&r1=1100556&r2=1100557&view=diff ============================================================================== --- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java (original) +++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java Sat May 7 15:30:17 2011 @@ -287,7 +287,10 @@ class DefaultAsyncRequestDirector imp if (method.equalsIgnoreCase("CONNECT") && status == HttpStatus.SC_OK) { this.managedConn.tunnelTarget(this.params); } else { - this.finalResponse = response; + this.followup = handleConnectResponse(); + if (this.followup == null) { + this.finalResponse = response; + } } } else { this.followup = handleResponse(); @@ -569,11 +572,52 @@ class DefaultAsyncRequestDirector imp } private RoutedRequest handleResponse() throws HttpException { - HttpRoute route = this.mainRequest.getRoute(); - RequestWrapper request = this.mainRequest.getRequest(); - if (HttpClientParams.isRedirecting(this.params) && this.redirectStrategy.isRedirected( + RoutedRequest followup = null; + if (HttpClientParams.isRedirecting(this.params)) { + followup = handleRedirect(); + if (followup != null) { + return followup; + } + } + if (HttpClientParams.isAuthenticating(this.params)) { + CredentialsProvider credsProvider = (CredentialsProvider) this.localContext.getAttribute( + ClientContext.CREDS_PROVIDER); + if (credsProvider != null) { + followup = handleTargetChallenge(credsProvider); + if (followup != null) { + return followup; + } + followup = handleProxyChallenge(credsProvider); + if (followup != null) { + return followup; + } + } + } + return null; + } + + private RoutedRequest handleConnectResponse() throws HttpException { + RoutedRequest followup = null; + if (HttpClientParams.isAuthenticating(this.params)) { + CredentialsProvider credsProvider = (CredentialsProvider) this.localContext.getAttribute( + ClientContext.CREDS_PROVIDER); + if (credsProvider != null) { + followup = handleProxyChallenge(credsProvider); + if (followup != null) { + return followup; + } + } + } + return null; + } + + private RoutedRequest handleRedirect() throws HttpException { + if (this.redirectStrategy.isRedirected( this.currentRequest, this.currentResponse, this.localContext)) { + HttpRoute route = this.mainRequest.getRoute(); + RequestWrapper request = this.mainRequest.getRequest(); + int maxRedirects = this.params.getIntParameter(ClientPNames.MAX_REDIRECTS, 100); if (this.redirectCount >= maxRedirects) { throw new RedirectException("Maximum redirects (" @@ -615,75 +659,79 @@ class DefaultAsyncRequestDirector imp } return new RoutedRequest(newRequest, newRoute); } + return null; + } - CredentialsProvider credsProvider = (CredentialsProvider) this.localContext.getAttribute( - ClientContext.CREDS_PROVIDER); - - if (credsProvider != null && HttpClientParams.isAuthenticating(params)) { - - if (this.targetAuthHandler.isAuthenticationRequested(this.currentResponse, this.localContext)) { + private RoutedRequest handleTargetChallenge( + final CredentialsProvider credsProvider) throws HttpException { + if (this.targetAuthHandler.isAuthenticationRequested(this.currentResponse, this.localContext)) { + HttpRoute route = this.mainRequest.getRoute(); - HttpHost target = (HttpHost) this.localContext.getAttribute( - ExecutionContext.HTTP_TARGET_HOST); - if (target == null) { - target = route.getTargetHost(); - } + HttpHost target = (HttpHost) this.localContext.getAttribute( + ExecutionContext.HTTP_TARGET_HOST); + if (target == null) { + target = route.getTargetHost(); + } - this.log.debug("Target requested authentication"); - Map challenges = this.targetAuthHandler.getChallenges( + this.log.debug("Target requested authentication"); + Map challenges = this.targetAuthHandler.getChallenges( + this.currentResponse, this.localContext); + try { + processChallenges(challenges, + this.targetAuthState, this.targetAuthHandler, this.currentResponse, this.localContext); - try { - processChallenges(challenges, - this.targetAuthState, this.targetAuthHandler, - this.currentResponse, this.localContext); - } catch (AuthenticationException ex) { - if (this.log.isWarnEnabled()) { - this.log.warn("Authentication error: " + ex.getMessage()); - return null; - } - } - updateAuthState(this.targetAuthState, target, credsProvider); - - if (this.targetAuthState.getCredentials() != null) { - // Re-try the same request via the same route - return this.mainRequest; - } else { + } catch (AuthenticationException ex) { + if (this.log.isWarnEnabled()) { + this.log.warn("Authentication error: " + ex.getMessage()); return null; } + } + updateAuthState(this.targetAuthState, target, credsProvider); + + if (this.targetAuthState.getCredentials() != null) { + // Re-try the same request via the same route + return this.mainRequest; } else { - // Reset target auth scope - this.targetAuthState.setAuthScope(null); + return null; } + } else { + // Reset target auth scope + this.targetAuthState.setAuthScope(null); + } + return null; + } - if (this.proxyAuthHandler.isAuthenticationRequested(this.currentResponse, this.localContext)) { + private RoutedRequest handleProxyChallenge( + final CredentialsProvider credsProvider) throws HttpException { + if (this.proxyAuthHandler.isAuthenticationRequested(this.currentResponse, this.localContext)) { + HttpRoute route = this.mainRequest.getRoute(); - HttpHost proxy = route.getProxyHost(); + HttpHost proxy = route.getProxyHost(); - this.log.debug("Proxy requested authentication"); - Map challenges = this.proxyAuthHandler.getChallenges( + this.log.debug("Proxy requested authentication"); + Map challenges = this.proxyAuthHandler.getChallenges( + this.currentResponse, this.localContext); + try { + processChallenges(challenges, + this.proxyAuthState, this.proxyAuthHandler, this.currentResponse, this.localContext); - try { - processChallenges(challenges, - this.proxyAuthState, this.proxyAuthHandler, - this.currentResponse, this.localContext); - } catch (AuthenticationException ex) { - if (this.log.isWarnEnabled()) { - this.log.warn("Authentication error: " + ex.getMessage()); - return null; - } - } - updateAuthState(this.proxyAuthState, proxy, credsProvider); - - if (this.proxyAuthState.getCredentials() != null) { - // Re-try the same request via the same route - return this.mainRequest; - } else { + } catch (AuthenticationException ex) { + if (this.log.isWarnEnabled()) { + this.log.warn("Authentication error: " + ex.getMessage()); return null; } + } + updateAuthState(this.proxyAuthState, proxy, credsProvider); + + if (this.proxyAuthState.getCredentials() != null) { + // Re-try the same request via the same route + return this.mainRequest; } else { - // Reset proxy auth scope - this.proxyAuthState.setAuthScope(null); + return null; } + } else { + // Reset proxy auth scope + this.proxyAuthState.setAuthScope(null); } return null; }