hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (JIRA)" <j...@apache.org>
Subject [jira] Updated: (HTTPCLIENT-524) Provide feedback mechanism to CredentialsProvider
Date Mon, 15 May 2006 19:11:07 GMT
     [ http://issues.apache.org/jira/browse/HTTPCLIENT-524?page=all ]

Oleg Kalnichevski updated HTTPCLIENT-524:
-----------------------------------------

    Component: HttpAuth
                   (was: HttpClient)

> Provide feedback mechanism to CredentialsProvider
> -------------------------------------------------
>
>          Key: HTTPCLIENT-524
>          URL: http://issues.apache.org/jira/browse/HTTPCLIENT-524
>      Project: HttpComponents HttpClient
>         Type: Bug

>   Components: HttpAuth
>     Versions: 3.0 RC4
>  Environment: Operating System: Windows XP
> Platform: Other
>     Reporter: David Martineau
>     Assignee: HttpClient Dev
>      Fix For: 4.0 Alpha 1

>
> If the remote server is using BASIC or NT authentication and you pass in 
> invalid credentials you get stuck in an infinite for loop, repeatedly sending 
> the same authentication request again and again to the server.  The for loop is 
> in the executeMethod method of the HttpMethodDirector class.
> Sample code:
> =================================================================
> import org.apache.commons.httpclient.Credentials;
> import org.apache.commons.httpclient.NTCredentials;
> import org.apache.commons.httpclient.UsernamePasswordCredentials;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.commons.httpclient.auth.*;
> import java.io.IOException;
> import java.io.BufferedInputStream;
> import java.io.ByteArrayOutputStream;
> /**
>  * Created by IntelliJ IDEA.
>  * User: dmartineau
>  * Date: Nov 8, 2005
>  * Time: 1:43:21 PM
>  */
> public class ShowProblem
> {
>     private String location;
>     private String user;
>     private String pass;
>     private String domain;
>     public ShowProblem(String location, String user, String pass, String domain)
>     {
>         this.location = location;
>         this.user=user;
>         this.pass=pass;
>         this.domain=domain;
>     }
>     public int getFile()
>     {
>         int status = 500;
>         HttpClient client = new HttpClient();
>         client.getParams().setParameter(
>             CredentialsProvider.PROVIDER, new CProvider(user,pass,domain));
>         GetMethod httpget = new GetMethod(location);
>         httpget.setDoAuthentication(true);
>         try
>         {
>             // execute the GET
>             status = client.executeMethod(httpget);
>             if (status==200)
>             {
>                 BufferedInputStream bin = new BufferedInputStream
> (httpget.getResponseBodyAsStream());
>                 ByteArrayOutputStream bos = new ByteArrayOutputStream();
>                 int bytesRead = 0;
>                 byte[] buff = new byte[16384];
>                 while ( (bytesRead = bin.read(buff)) != -1) {
>                     bos.write(buff, 0, bytesRead);
>                 }
>                 // display the results.
>                 System.out.println(new String(bos.toByteArray()));
>             }
>         }
>         catch (Throwable t)
>         {
>             t.printStackTrace();
>         }
>         finally
>         {
>             // release any connection resources used by the method
>             httpget.releaseConnection();
>         }
>         return status;
>     }
>     public static void main(String[] args)
>     {
>         ShowProblem showProblem = new ShowProblem(args[0],args[1],args[2],args
> [3]);
>         int response = showProblem.getFile();
>         
>     }
>     class CProvider implements CredentialsProvider
>     {
>         private String user;
>         private String password;
>         private String domain;
>         public CProvider(String user, String password, String domain)
>         {
>             super();
>             this.user = user;
>             this.password = password;
>             this.domain = domain;
>         }
>         public Credentials getCredentials(final AuthScheme authscheme,final 
> String host,int port,boolean proxy)
>         throws CredentialsNotAvailableException
>         {
>             if (authscheme == null)
>             {
>                 return null;
>             }
>             try
>             {
>                 if (authscheme instanceof NTLMScheme)
>                 {
>                     return new NTCredentials(user, password, host, domain);
>                 }
>                 else if (authscheme instanceof RFC2617Scheme)
>                 {
>                     return new UsernamePasswordCredentials(user, password);
>                 }
>                 else
>                 {
>                     throw new CredentialsNotAvailableException("Unsupported 
> authentication scheme: " +
>                         authscheme.getSchemeName());
>                 }
>             }
>             catch (IOException e)
>             {
>                 throw new CredentialsNotAvailableException(e.getMessage(), e);
>             }
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


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


Mime
View raw message