commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ross Gardler <>
Subject Re: JJar via authenticating proxy
Date Mon, 03 Jun 2002 11:22:25 GMT
(copied back to jakarta-commons in case anywone there has a better idea)

Geir Magnusson Jr. wrote:
  >> Is it possible to use the JJar ANT task via an authenticating proxy?

  >> It works fine through a non-authenticating proxy using the
  >> http.proxyHost and http.proxyPort system properties, but with an
  >> authenticating proxy a 407 (authentication failure) is returned.

 > Working on JJAR now, and will be posting code back to commons in the next
 > week or so.
 > How would this work?  How do you specify the auth info?

This issue has come about on the Centipede build system which uses JJar

The following code snippet illustrates how to connet to an
authenticating server:


            public class URLReader {
                public static void main(String[] args) throws Exception {
                   System.getProperties().put( "proxySet", "true" );
                   System.getProperties().put( "proxyHost",
"" );
                   System.getProperties().put( "proxyPort", "80" );

                   URL yahoo = new URL("");
     URLConnection connection = yahoo.openConnection();
                   String userPassword = "username:password";
                   String encodedPassword = new
sun.misc.BASE64Encoder().encode (userPassword.getBytes());
                   connection.setRequestProperty( "Authorization",
encodedPassword );

                    BufferedReader in = new BufferedReader(
                                            new InputStreamReader(

                    String inputLine;

                    while ((inputLine = in.readLine()) != null)


The system properties can be set via ANT_OPTS so there is no problem
with those. However, the username and password do not have corresponding
default properties. I can therefore see three possible soluions.

1. Put the username and password in the ANT build file and pass them to
the JJAR test

2. Have ant ask for the username and password interactively and pass the
values to the JJAR task

3. Define our own System propoerties to hold the username and password
and have JJAR extract them from there

1 & 3 have a problem in that we either have to force the user to encode
the values before setting them or we create a security problem by
storing them unencoded.

2 is perhaps the best. We could set a property in the build file
indicating whether we are connecting through an authenticating proxy or
not, thus prompting the user for username and password. Furthermore,
using this method we allow the user to decide if they want to store the
username/password in the build file and thus prevent the need to type
them each time.

What do you think?


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message