You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2022/06/19 00:42:21 UTC

[maven-wagon] 01/01: [WAGON-629] Properly handle authentication scenarios with MKCOL

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

michaelo pushed a commit to branch WAGON-629
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git

commit 88e8574c69d83e6a658fcd2ad10f3f80926b8840
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Jun 19 02:39:34 2022 +0200

    [WAGON-629] Properly handle authentication scenarios with MKCOL
    
    Introduce HttpMethodConfiguration for MKCOL and enforce test for preemptive
    for this method. Thus, we can remove two TODOs/FIXMEs which completely
    ignored that config. While fixing properly split WebDAV Wagon tests for
    non-preemptive (default) and preemptive.
    
    This closes #85
---
 .../wagon/shared/http/AbstractHttpClientWagon.java |  2 +
 .../maven/wagon/shared/http/HttpConfiguration.java | 15 +++++++
 .../wagon/providers/http/HttpClientWagonTest.java  |  2 +-
 .../maven/wagon/providers/webdav/WebDavWagon.java  | 17 -------
 .../webdav/WebDavWagonPreemptiveTest.java          | 52 ++++++++++++++++++++++
 .../wagon/providers/webdav/WebDavWagonTest.java    | 37 +++++++--------
 ...onTest.java => WebDavsWagonPreemptiveTest.java} | 37 ++++++++++++---
 .../wagon/providers/webdav/WebDavsWagonTest.java   |  9 ++--
 8 files changed, 120 insertions(+), 51 deletions(-)

diff --git a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
index c49fb5b2..ec02bf6d 100644
--- a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
+++ b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/AbstractHttpClientWagon.java
@@ -952,6 +952,8 @@ public abstract class AbstractHttpClientWagon
 
         requestConfigBuilder.setConnectTimeout( getTimeout() );
         requestConfigBuilder.setSocketTimeout( getReadTimeout() );
+        // We don't apply this to MKCOL because RFC 7231 says that this will not work without a body
+        // and our MKCOL requests don't have a body. They will logically behave like GET.
         if ( httpMethod instanceof HttpPut )
         {
             requestConfigBuilder.setExpectContinueEnabled( true );
diff --git a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java
index 97d4d533..14fde8c7 100644
--- a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java
+++ b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/HttpConfiguration.java
@@ -35,6 +35,8 @@ public class HttpConfiguration
 
     private HttpMethodConfiguration head;
 
+    private HttpMethodConfiguration mkcol;
+
     public HttpMethodConfiguration getAll()
     {
         return all;
@@ -79,6 +81,17 @@ public class HttpConfiguration
         return this;
     }
 
+    public HttpMethodConfiguration getMkcol()
+    {
+        return mkcol;
+    }
+
+    public HttpConfiguration setMkcol( HttpMethodConfiguration mkcol )
+    {
+        this.mkcol = mkcol;
+        return this;
+    }
+
     public HttpMethodConfiguration getMethodConfiguration( HttpUriRequest method )
     {
         switch ( method.getMethod() )
@@ -89,6 +102,8 @@ public class HttpConfiguration
             return ConfigurationUtils.merge( all, put );
         case "HEAD":
             return ConfigurationUtils.merge( all, head );
+        case "MKCOL":
+            return ConfigurationUtils.merge( all, mkcol );
         default:
             return all;
         }
diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
index 30ff6ac0..6ea7da68 100755
--- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
+++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/HttpClientWagonTest.java
@@ -45,7 +45,7 @@ public class HttpClientWagonTest
         methodConfig.addParam("http.protocol.max-redirects", "%i," + maxRedirects);
 
         HttpConfiguration config = new HttpConfiguration();
-        config.setAll(methodConfig);
+        config.setAll( methodConfig );
 
         HttpHead method = new HttpHead();
         RequestConfig.Builder builder = RequestConfig.custom();
diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java b/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
index 22c1ee42..9847c04b 100644
--- a/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
+++ b/wagon-providers/wagon-webdav-jackrabbit/src/main/java/org/apache/maven/wagon/providers/webdav/WebDavWagon.java
@@ -20,11 +20,8 @@ package org.apache.maven.wagon.providers.webdav;
  */
 
 import org.apache.http.HttpException;
-import org.apache.http.HttpHost;
 import org.apache.http.HttpStatus;
-import org.apache.http.auth.AuthScope;
 import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.impl.auth.BasicScheme;
 import org.apache.http.util.EntityUtils;
 import org.apache.jackrabbit.webdav.DavConstants;
 import org.apache.jackrabbit.webdav.DavException;
@@ -50,7 +47,6 @@ import org.w3c.dom.Node;
 import java.io.File;
 import java.io.IOException;
 import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -156,19 +152,6 @@ public class WebDavWagon
     private int doMkCol( String url )
         throws IOException
     {
-        // preemptive for mkcol
-        // TODO: is it a good idea, though? 'Expect-continue' handshake would serve much better
-
-        // FIXME Perform only when preemptive has been configured
-        Repository repo = getRepository();
-        HttpHost targetHost = new HttpHost( repo.getHost(), repo.getPort(), repo.getProtocol() );
-        AuthScope targetScope = getBasicAuthScope().getScope( targetHost );
-
-        if ( getCredentialsProvider().getCredentials( targetScope ) != null )
-        {
-            BasicScheme targetAuth = new BasicScheme( StandardCharsets.UTF_8 );
-            getAuthCache().put( targetHost, targetAuth );
-        }
         HttpMkcol method = new HttpMkcol( url );
         try ( CloseableHttpResponse closeableHttpResponse = execute( method ) )
         {
diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonPreemptiveTest.java b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonPreemptiveTest.java
new file mode 100644
index 00000000..2ce97e08
--- /dev/null
+++ b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonPreemptiveTest.java
@@ -0,0 +1,52 @@
+package org.apache.maven.wagon.providers.webdav;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.shared.http.HttpConfiguration;
+import org.apache.maven.wagon.shared.http.HttpMethodConfiguration;
+
+public class WebDavWagonPreemptiveTest
+    extends WebDavWagonTest
+{
+    @Override
+    protected Wagon getWagon()
+        throws Exception
+    {
+        WebDavWagon wagon = (WebDavWagon) super.getWagon();
+        wagon.setHttpConfiguration(
+            new HttpConfiguration() //
+                .setAll( new HttpMethodConfiguration().setUsePreemptive( true ) ) );
+        return wagon;
+    }
+
+    @Override
+    protected boolean supportPreemptiveAuthenticationPut()
+    {
+        return true;
+    }
+
+    @Override
+    protected boolean supportPreemptiveAuthenticationGet()
+    {
+        return true;
+    }
+
+}
diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java
index e6a355d1..317007a4 100644
--- a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java
+++ b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavWagonTest.java
@@ -1,18 +1,22 @@
 package org.apache.maven.wagon.providers.webdav;
 
 /*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
  *
- * http://www.apache.org/licenses/LICENSE-2.0
+ *   http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  */
 
 import it.could.webdav.DAVServlet;
@@ -51,17 +55,6 @@ public class WebDavWagonTest
     extends HttpWagonTestCase
 {
 
-    @Override
-    protected Wagon getWagon()
-        throws Exception
-    {
-        WebDavWagon wagon = (WebDavWagon) super.getWagon();
-        wagon.setHttpConfiguration(
-            new HttpConfiguration() //
-                .setPut( new HttpMethodConfiguration().setUsePreemptive( true ) ));
-        return wagon;
-    }
-
     protected String getTestRepositoryUrl()
         throws IOException
     {
@@ -425,7 +418,7 @@ public class WebDavWagonTest
     @Override
     protected boolean supportPreemptiveAuthenticationPut()
     {
-        return true;
+        return false;
     }
 
     @Override
diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavsWagonTest.java b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavsWagonPreemptiveTest.java
similarity index 73%
copy from wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavsWagonTest.java
copy to wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavsWagonPreemptiveTest.java
index 9e5a997e..c578c163 100644
--- a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavsWagonTest.java
+++ b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavsWagonPreemptiveTest.java
@@ -1,9 +1,5 @@
 package org.apache.maven.wagon.providers.webdav;
 
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -23,14 +19,20 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
  * under the License.
  */
 
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.shared.http.HttpConfiguration;
+import org.apache.maven.wagon.shared.http.HttpMethodConfiguration;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
 
 /**
  * WebDAV Wagon Test
- * 
+ *
  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
  */
-public class WebDavsWagonTest
+public class WebDavsWagonPreemptiveTest
     extends WebDavWagonTest
 {
     protected String getProtocol()
@@ -55,4 +57,27 @@ public class WebDavsWagonTest
         return serverConnector;
     }
 
+    @Override
+    protected Wagon getWagon()
+        throws Exception
+    {
+        WebDavWagon wagon = (WebDavWagon) super.getWagon();
+        wagon.setHttpConfiguration(
+            new HttpConfiguration() //
+                .setAll( new HttpMethodConfiguration().setUsePreemptive( true ) ) );
+        return wagon;
+    }
+
+    @Override
+    protected boolean supportPreemptiveAuthenticationPut()
+    {
+        return true;
+    }
+
+    @Override
+    protected boolean supportPreemptiveAuthenticationGet()
+    {
+        return true;
+    }
+
 }
diff --git a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavsWagonTest.java b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavsWagonTest.java
index 9e5a997e..3a89ef08 100644
--- a/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavsWagonTest.java
+++ b/wagon-providers/wagon-webdav-jackrabbit/src/test/java/org/apache/maven/wagon/providers/webdav/WebDavsWagonTest.java
@@ -1,9 +1,5 @@
 package org.apache.maven.wagon.providers.webdav;
 
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -23,10 +19,13 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
  * under the License.
  */
 
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
 
 /**
  * WebDAV Wagon Test
- * 
+ *
  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
  */