You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2021/12/22 17:20:17 UTC

[ant] branch master updated: Allow ant:get task to disable authentication on redirect.

This is an automated email from the ASF dual-hosted git repository.

bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git


The following commit(s) were added to refs/heads/master by this push:
     new 0f3985c  Allow ant:get task to disable authentication on redirect.
     new fa82fe5  Merge pull request #173 from bernolanger/master
0f3985c is described below

commit 0f3985c356e11fb5c73383bea5f94ff9dce1a71b
Author: Berno Langer <bl...@immosolve.de>
AuthorDate: Mon Dec 20 11:46:36 2021 +0100

    Allow ant:get task to disable authentication on redirect.
    
    When the server answers with a redirect response, the request to the new
    location may or may not need a second authentication. To disable the
    authentication, the new attribute "authenticateOnRedirect" can be set to
    "false".
---
 manual/Tasks/get.html                           |  6 ++++++
 src/main/org/apache/tools/ant/taskdefs/Get.java | 20 +++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/manual/Tasks/get.html b/manual/Tasks/get.html
index 28a6826..b4c4e57 100644
--- a/manual/Tasks/get.html
+++ b/manual/Tasks/get.html
@@ -92,6 +92,12 @@ the request is relayed to the proxy.</p>
     <td>Yes if <var>username</var> is set</td>
   </tr>
   <tr>
+    <td>authenticateOnRedirect</td>
+    <td>Whether the credentials should also be sent to the new location when a redirect is followed.<br/>
+    <em>since Ant 1.10.13</em></td>
+    <td>No; default is <q>true</q></td>
+  </tr>
+  <tr>
     <td>maxtime</td>
     <td>Maximum time in seconds a single download may take, otherwise it will be interrupted and
       treated like a download error.  <em>Since Ant 1.8.0</em></td>
diff --git a/src/main/org/apache/tools/ant/taskdefs/Get.java b/src/main/org/apache/tools/ant/taskdefs/Get.java
index 5ee3fb6..15f732f 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Get.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Get.java
@@ -82,6 +82,7 @@ public class Get extends Task {
     private boolean ignoreErrors = false;
     private String uname = null;
     private String pword = null;
+    private boolean authenticateOnRedirect = true; // on by default for backward compatibility
     private long maxTime = 0;
     private int numberRetries = NUMBER_RETRIES;
     private boolean skipExisting = false;
@@ -406,6 +407,16 @@ public class Get extends Task {
     }
 
     /**
+     * If true, credentials are set when following a redirect to a new location.
+     *
+     * @param v "true" to enable sending the credentials on redirect; "false" otherwise
+     * @since Ant 1.10.13
+     */
+    public void setAuthenticateOnRedirect(final boolean v) {
+        this.authenticateOnRedirect = v;
+    }
+
+    /**
      * The time in seconds the download is allowed to take before
      * being terminated.
      *
@@ -685,7 +696,7 @@ public class Get extends Task {
 
         private boolean get() throws IOException, BuildException {
 
-            connection = openConnection(source);
+            connection = openConnection(source, uname, pword);
 
             if (connection == null) {
                 return false;
@@ -735,7 +746,8 @@ public class Get extends Task {
             return true;
         }
 
-        private URLConnection openConnection(final URL aSource) throws IOException {
+        private URLConnection openConnection(final URL aSource, final String uname,
+                                             final String pword) throws IOException {
 
             // set up the URL connection
             final URLConnection connection = aSource.openConnection();
@@ -795,7 +807,9 @@ public class Get extends Task {
                     if (!redirectionAllowed(aSource, newURL)) {
                         return null;
                     }
-                    return openConnection(newURL);
+                    return openConnection(newURL,
+                        authenticateOnRedirect ? uname : null,
+                        authenticateOnRedirect ? pword : null);
                 }
                 // next test for a 304 result (HTTP only)
                 final long lastModified = httpConnection.getLastModified();