You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ni...@apache.org on 2011/08/28 16:41:29 UTC
svn commit: r1162533 - in
/maven/wagon/branches/wagon-1.x/wagon-providers/wagon-http-lightweight/src:
main/java/org/apache/maven/wagon/providers/http/
test/java/org/apache/maven/wagon/providers/http/
Author: nicolas
Date: Sun Aug 28 14:41:28 2011
New Revision: 1162533
URL: http://svn.apache.org/viewvc?rev=1162533&view=rev
Log:
[WAGON-347] Support preemtive authentication
Added:
maven/wagon/branches/wagon-1.x/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpWagonWithPreemptiveAuthenticationTest.java
Modified:
maven/wagon/branches/wagon-1.x/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java
Modified: maven/wagon/branches/wagon-1.x/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/branches/wagon-1.x/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java?rev=1162533&r1=1162532&r2=1162533&view=diff
==============================================================================
--- maven/wagon/branches/wagon-1.x/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java (original)
+++ maven/wagon/branches/wagon-1.x/wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java Sun Aug 28 14:41:28 2011
@@ -28,7 +28,6 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;
-import java.net.URLConnection;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
@@ -46,6 +45,7 @@ import org.apache.maven.wagon.events.Tra
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.resource.Resource;
import org.apache.maven.wagon.shared.http.HtmlFileListParser;
+import org.codehaus.plexus.util.Base64;
/**
* LightweightHttpWagon
@@ -57,6 +57,8 @@ import org.apache.maven.wagon.shared.htt
public class LightweightHttpWagon
extends StreamWagon
{
+ private boolean preemptiveAuthentication;
+
private String previousProxyExclusions;
private String previousHttpProxyHost;
@@ -144,7 +146,7 @@ public class LightweightHttpWagon
}
}
- private void addHeaders( URLConnection urlConnection )
+ private void addHeaders( HttpURLConnection urlConnection )
{
if ( httpHeaders != null )
{
@@ -154,6 +156,17 @@ public class LightweightHttpWagon
urlConnection.setRequestProperty( header, httpHeaders.getProperty( header ) );
}
}
+ setAuthorization( urlConnection );
+ }
+
+ private void setAuthorization( HttpURLConnection urlConnection )
+ {
+ if ( preemptiveAuthentication && authenticationInfo != null && authenticationInfo.getUserName() != null )
+ {
+ String credentials = authenticationInfo.getUserName() + ":" + authenticationInfo.getPassword();
+ String encoded = new String( Base64.encodeBase64( credentials.getBytes() ) );
+ urlConnection.setRequestProperty( "Authorization", "Basic " + encoded );
+ }
}
public void fillOutputData( OutputData outputData )
@@ -234,6 +247,10 @@ public class LightweightHttpWagon
setSystemProperty( "http.proxyPort", null );
}
+ setPreemptiveAuthentication(
+ Boolean.getBoolean( "maven.wagon.http.preemptiveAuthentication" )
+ || Boolean.parseBoolean( repository.getParameter( "preemptiveAuthentication" ) ) );
+
final boolean hasProxy = ( proxyInfo != null && proxyInfo.getUserName() != null );
final boolean hasAuthentication = ( authenticationInfo != null && authenticationInfo.getUserName() != null );
if ( hasProxy || hasAuthentication )
@@ -390,4 +407,8 @@ public class LightweightHttpWagon
}
}
+ public void setPreemptiveAuthentication( boolean preemptiveAuthentication )
+ {
+ this.preemptiveAuthentication |= preemptiveAuthentication;
+ }
}
Added: maven/wagon/branches/wagon-1.x/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpWagonWithPreemptiveAuthenticationTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/branches/wagon-1.x/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpWagonWithPreemptiveAuthenticationTest.java?rev=1162533&view=auto
==============================================================================
--- maven/wagon/branches/wagon-1.x/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpWagonWithPreemptiveAuthenticationTest.java (added)
+++ maven/wagon/branches/wagon-1.x/wagon-providers/wagon-http-lightweight/src/test/java/org/apache/maven/wagon/providers/http/LightweightHttpWagonWithPreemptiveAuthenticationTest.java Sun Aug 28 14:41:28 2011
@@ -0,0 +1,37 @@
+package org.apache.maven.wagon.providers.http;
+
+/*
+ * 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;
+
+/**
+ * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
+ * @version $Id$
+ */
+public class LightweightHttpWagonWithPreemptiveAuthenticationTest
+ extends LightweightHttpWagonTest
+{
+ @Override
+ protected Wagon getWagon() throws Exception {
+ LightweightHttpWagon wagon = (LightweightHttpWagon) super.getWagon();
+ wagon.setPreemptiveAuthentication( true );
+ return wagon;
+ }
+}