You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by srihari na <na...@gmail.com> on 2013/05/21 11:28:45 UTC

Target server digest authentication fails with Proxy Basic auth

Hi Folks,

We are trying to do HTTPGet on a target server enabled with Digest
authentication. It works perfectly fine, however when proxy with basic
authentication is introduced target authentication is failing. We are using
IBM JDK, HTTP Client 4.2.5. Has anybody faced similar issues and knows a
fix to it?

Code:
HttpHost proxy = new HttpHost(proxyHost, 808);
HttpHost target = new HttpHost(targetHost, 80);
HttpGet req = new HttpGet("/default.asp");
Credentials targetCredentials = new UsernamePasswordCredentials(targetUser,
targetpassword);
Credentials proxyCredentials = new UsernamePasswordCredentials(proxyUser,
proxyPassword);
 DefaultHttpClient httpclient = null;
        try {
        final PoolingClientConnectionManager connectionManager = new
PoolingClientConnectionManager();
        httpclient = new DefaultHttpClient(connectionManager);
            HttpContext localContext = new BasicHttpContext();
            req.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
proxy);
            System.out.println("executing request to " + target + " via " +
proxy);
            httpclient.getCredentialsProvider().setCredentials(new
AuthScope(proxy), proxyCredentials);
            httpclient.getCredentialsProvider().setCredentials(new
AuthScope(target), targetCredentials);
            HttpResponse rsp = httpclient.execute(target, req,localContext);
            AuthState proxyAuthState = (AuthState)
localContext.getAttribute(ClientContext.PROXY_AUTH_STATE);
            System.out.println("Proxy auth state: " +
proxyAuthState.getState());
            System.out.println("Proxy auth scheme: " +
proxyAuthState.getAuthScheme());
            System.out.println("Proxy auth credentials: " +
proxyAuthState.getCredentials());
            AuthState targetAuthState = (AuthState)
localContext.getAttribute(ClientContext.TARGET_AUTH_STATE);
            System.out.println("Target auth state: " +
targetAuthState.getState());
            System.out.println("Target auth scheme: " +
targetAuthState.getAuthScheme());
            System.out.println("Target auth credentials: " +
targetAuthState.getCredentials());

            HttpEntity entity = rsp.getEntity();

            if (entity != null) {
                System.out.println(EntityUtils.toString(entity));
            }

        }catch (Exception e) {
} finally {
            httpclient.getConnectionManager().shutdown();
        }

}

-- 
Regards,
Srihari NA

Re: Target server digest authentication fails with Proxy Basic auth

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, May 22, 2013 at 02:38:53PM +0530, srihari na wrote:
> Here I have attached logs for both scenarios with log level of
> org.apache.http.level = FINEST
> Target server with Digest Auth is working fine
> Target server with Digest Auth with Proxy (Basic Auth) fails
> 
> 

It is a known compatibility issue with Microsoft IIS server caused by what I believe is a bug in Microsoft's implementation of the DIGEST scheme. Please see this JIRA for detailed explanation.

https://issues.apache.org/jira/browse/HTTPCLIENT-1071

Oleg




> On Wed, May 22, 2013 at 1:36 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> > On Tue, May 21, 2013 at 02:58:45PM +0530, srihari na wrote:
> > > Hi Folks,
> > >
> > > We are trying to do HTTPGet on a target server enabled with Digest
> > > authentication. It works perfectly fine, however when proxy with basic
> > > authentication is introduced target authentication is failing. We are
> > using
> > > IBM JDK, HTTP Client 4.2.5. Has anybody faced similar issues and knows a
> > > fix to it?
> > >
> >
> > Please post a complete wire log of the session. See HttpClient logging
> > guide for instructions on wire / context logging.
> >
> > Oleg
> >
> >
> >
> > > Code:
> > > HttpHost proxy = new HttpHost(proxyHost, 808);
> > > HttpHost target = new HttpHost(targetHost, 80);
> > > HttpGet req = new HttpGet("/default.asp");
> > > Credentials targetCredentials = new
> > UsernamePasswordCredentials(targetUser,
> > > targetpassword);
> > > Credentials proxyCredentials = new UsernamePasswordCredentials(proxyUser,
> > > proxyPassword);
> > >  DefaultHttpClient httpclient = null;
> > >         try {
> > >         final PoolingClientConnectionManager connectionManager = new
> > > PoolingClientConnectionManager();
> > >         httpclient = new DefaultHttpClient(connectionManager);
> > >             HttpContext localContext = new BasicHttpContext();
> > >             req.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
> > > proxy);
> > >             System.out.println("executing request to " + target + " via
> > " +
> > > proxy);
> > >             httpclient.getCredentialsProvider().setCredentials(new
> > > AuthScope(proxy), proxyCredentials);
> > >             httpclient.getCredentialsProvider().setCredentials(new
> > > AuthScope(target), targetCredentials);
> > >             HttpResponse rsp = httpclient.execute(target,
> > req,localContext);
> > >             AuthState proxyAuthState = (AuthState)
> > > localContext.getAttribute(ClientContext.PROXY_AUTH_STATE);
> > >             System.out.println("Proxy auth state: " +
> > > proxyAuthState.getState());
> > >             System.out.println("Proxy auth scheme: " +
> > > proxyAuthState.getAuthScheme());
> > >             System.out.println("Proxy auth credentials: " +
> > > proxyAuthState.getCredentials());
> > >             AuthState targetAuthState = (AuthState)
> > > localContext.getAttribute(ClientContext.TARGET_AUTH_STATE);
> > >             System.out.println("Target auth state: " +
> > > targetAuthState.getState());
> > >             System.out.println("Target auth scheme: " +
> > > targetAuthState.getAuthScheme());
> > >             System.out.println("Target auth credentials: " +
> > > targetAuthState.getCredentials());
> > >
> > >             HttpEntity entity = rsp.getEntity();
> > >
> > >             if (entity != null) {
> > >                 System.out.println(EntityUtils.toString(entity));
> > >             }
> > >
> > >         }catch (Exception e) {
> > > } finally {
> > >             httpclient.getConnectionManager().shutdown();
> > >         }
> > >
> > > }
> > >
> > > --
> > > Regards,
> > > Srihari NA
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
> >
> 
> 
> -- 
> Regards,
> Srihari NA


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


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


Re: Target server digest authentication fails with Proxy Basic auth

Posted by srihari na <na...@gmail.com>.
Here I have attached logs for both scenarios with log level of
org.apache.http.level = FINEST
Target server with Digest Auth is working fine
Target server with Digest Auth with Proxy (Basic Auth) fails


On Wed, May 22, 2013 at 1:36 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Tue, May 21, 2013 at 02:58:45PM +0530, srihari na wrote:
> > Hi Folks,
> >
> > We are trying to do HTTPGet on a target server enabled with Digest
> > authentication. It works perfectly fine, however when proxy with basic
> > authentication is introduced target authentication is failing. We are
> using
> > IBM JDK, HTTP Client 4.2.5. Has anybody faced similar issues and knows a
> > fix to it?
> >
>
> Please post a complete wire log of the session. See HttpClient logging
> guide for instructions on wire / context logging.
>
> Oleg
>
>
>
> > Code:
> > HttpHost proxy = new HttpHost(proxyHost, 808);
> > HttpHost target = new HttpHost(targetHost, 80);
> > HttpGet req = new HttpGet("/default.asp");
> > Credentials targetCredentials = new
> UsernamePasswordCredentials(targetUser,
> > targetpassword);
> > Credentials proxyCredentials = new UsernamePasswordCredentials(proxyUser,
> > proxyPassword);
> >  DefaultHttpClient httpclient = null;
> >         try {
> >         final PoolingClientConnectionManager connectionManager = new
> > PoolingClientConnectionManager();
> >         httpclient = new DefaultHttpClient(connectionManager);
> >             HttpContext localContext = new BasicHttpContext();
> >             req.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
> > proxy);
> >             System.out.println("executing request to " + target + " via
> " +
> > proxy);
> >             httpclient.getCredentialsProvider().setCredentials(new
> > AuthScope(proxy), proxyCredentials);
> >             httpclient.getCredentialsProvider().setCredentials(new
> > AuthScope(target), targetCredentials);
> >             HttpResponse rsp = httpclient.execute(target,
> req,localContext);
> >             AuthState proxyAuthState = (AuthState)
> > localContext.getAttribute(ClientContext.PROXY_AUTH_STATE);
> >             System.out.println("Proxy auth state: " +
> > proxyAuthState.getState());
> >             System.out.println("Proxy auth scheme: " +
> > proxyAuthState.getAuthScheme());
> >             System.out.println("Proxy auth credentials: " +
> > proxyAuthState.getCredentials());
> >             AuthState targetAuthState = (AuthState)
> > localContext.getAttribute(ClientContext.TARGET_AUTH_STATE);
> >             System.out.println("Target auth state: " +
> > targetAuthState.getState());
> >             System.out.println("Target auth scheme: " +
> > targetAuthState.getAuthScheme());
> >             System.out.println("Target auth credentials: " +
> > targetAuthState.getCredentials());
> >
> >             HttpEntity entity = rsp.getEntity();
> >
> >             if (entity != null) {
> >                 System.out.println(EntityUtils.toString(entity));
> >             }
> >
> >         }catch (Exception e) {
> > } finally {
> >             httpclient.getConnectionManager().shutdown();
> >         }
> >
> > }
> >
> > --
> > Regards,
> > Srihari NA
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>


-- 
Regards,
Srihari NA

Re: Target server digest authentication fails with Proxy Basic auth

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, May 21, 2013 at 02:58:45PM +0530, srihari na wrote:
> Hi Folks,
> 
> We are trying to do HTTPGet on a target server enabled with Digest
> authentication. It works perfectly fine, however when proxy with basic
> authentication is introduced target authentication is failing. We are using
> IBM JDK, HTTP Client 4.2.5. Has anybody faced similar issues and knows a
> fix to it?
> 

Please post a complete wire log of the session. See HttpClient logging guide for instructions on wire / context logging.

Oleg



> Code:
> HttpHost proxy = new HttpHost(proxyHost, 808);
> HttpHost target = new HttpHost(targetHost, 80);
> HttpGet req = new HttpGet("/default.asp");
> Credentials targetCredentials = new UsernamePasswordCredentials(targetUser,
> targetpassword);
> Credentials proxyCredentials = new UsernamePasswordCredentials(proxyUser,
> proxyPassword);
>  DefaultHttpClient httpclient = null;
>         try {
>         final PoolingClientConnectionManager connectionManager = new
> PoolingClientConnectionManager();
>         httpclient = new DefaultHttpClient(connectionManager);
>             HttpContext localContext = new BasicHttpContext();
>             req.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
> proxy);
>             System.out.println("executing request to " + target + " via " +
> proxy);
>             httpclient.getCredentialsProvider().setCredentials(new
> AuthScope(proxy), proxyCredentials);
>             httpclient.getCredentialsProvider().setCredentials(new
> AuthScope(target), targetCredentials);
>             HttpResponse rsp = httpclient.execute(target, req,localContext);
>             AuthState proxyAuthState = (AuthState)
> localContext.getAttribute(ClientContext.PROXY_AUTH_STATE);
>             System.out.println("Proxy auth state: " +
> proxyAuthState.getState());
>             System.out.println("Proxy auth scheme: " +
> proxyAuthState.getAuthScheme());
>             System.out.println("Proxy auth credentials: " +
> proxyAuthState.getCredentials());
>             AuthState targetAuthState = (AuthState)
> localContext.getAttribute(ClientContext.TARGET_AUTH_STATE);
>             System.out.println("Target auth state: " +
> targetAuthState.getState());
>             System.out.println("Target auth scheme: " +
> targetAuthState.getAuthScheme());
>             System.out.println("Target auth credentials: " +
> targetAuthState.getCredentials());
> 
>             HttpEntity entity = rsp.getEntity();
> 
>             if (entity != null) {
>                 System.out.println(EntityUtils.toString(entity));
>             }
> 
>         }catch (Exception e) {
> } finally {
>             httpclient.getConnectionManager().shutdown();
>         }
> 
> }
> 
> -- 
> Regards,
> Srihari NA

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