You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2014/10/01 02:58:10 UTC
[1/2] git commit: [WAGON-422] HTTP wagon AuthScope is not definable
from settings Submitted by leon franzen
Repository: maven-wagon
Updated Branches:
refs/heads/master 4210c0bb6 -> 1d3da753e
[WAGON-422] HTTP wagon AuthScope is not definable from settings
Submitted by leon franzen
Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/162e51bd
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/162e51bd
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/162e51bd
Branch: refs/heads/master
Commit: 162e51bdbe2ebf9358c35cea04ffe6c110920ddc
Parents: 4210c0b
Author: Olivier Lamy <ol...@apache.org>
Authored: Wed Oct 1 10:44:51 2014 +1000
Committer: Olivier Lamy <ol...@apache.org>
Committed: Wed Oct 1 10:44:51 2014 +1000
----------------------------------------------------------------------
.../providers/http/AbstractHttpClientWagon.java | 73 ++++++++--
.../wagon/providers/http/BasicAuthScope.java | 143 +++++++++++++++++++
.../providers/http/BasicAuthScopeTest.java | 94 ++++++++++++
3 files changed, 301 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/162e51bd/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
index 1962794..a78a1d6 100755
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
@@ -440,6 +440,16 @@ public abstract class AbstractHttpClientWagon
*/
private HttpConfiguration httpConfiguration;
+ /**
+ * Basic auth scope overrides
+ */
+ private BasicAuthScope basicAuth;
+
+ /**
+ * Proxy basic auth scope overrides
+ */
+ private BasicAuthScope proxyAuth;
+
public void openConnectionInternal()
{
repository.setUrl( getURL( repository ) );
@@ -461,10 +471,11 @@ public abstract class AbstractHttpClientWagon
Credentials creds = new UsernamePasswordCredentials( username, password );
String host = getRepository().getHost();
- int port = getRepository().getPort() > -1 ? getRepository().getPort() : AuthScope.ANY_PORT;
+ int port = getRepository().getPort();
- credentialsProvider.setCredentials( new AuthScope( host, port ), creds );
- }
+ credentialsProvider.setCredentials(getBasicAuthScope()
+ .getScope(host, port), creds);
+ }
}
ProxyInfo proxyInfo = getProxyInfo( getRepository().getProtocol(), getRepository().getHost() );
@@ -489,10 +500,11 @@ public abstract class AbstractHttpClientWagon
creds = new UsernamePasswordCredentials( proxyUsername, proxyPassword );
}
- int port = proxyInfo.getPort() > -1 ? proxyInfo.getPort() : AuthScope.ANY_PORT;
+ int port = proxyInfo.getPort();
- AuthScope authScope = new AuthScope( proxyHost, port );
- credentialsProvider.setCredentials( authScope, creds );
+ AuthScope authScope = getProxyBasicAuthScope().getScope(
+ proxyHost, port);
+ credentialsProvider.setCredentials(authScope, creds);
}
}
}
@@ -588,7 +600,7 @@ public abstract class AbstractHttpClientWagon
Repository repo = getRepository();
HttpHost targetHost = new HttpHost( repo.getHost(), repo.getPort(), repo.getProtocol() );
- AuthScope targetScope = new AuthScope( targetHost );
+ AuthScope targetScope = getBasicAuthScope().getScope(targetHost);
if ( credentialsProvider.getCredentials( targetScope ) != null )
{
@@ -810,7 +822,7 @@ public abstract class AbstractHttpClientWagon
if ( config != null && config.isUsePreemptive() )
{
HttpHost targetHost = new HttpHost( repo.getHost(), repo.getPort(), repo.getProtocol() );
- AuthScope targetScope = new AuthScope( targetHost );
+ AuthScope targetScope = getBasicAuthScope().getScope(targetHost);
if ( credentialsProvider.getCredentials( targetScope ) != null )
{
@@ -825,7 +837,8 @@ public abstract class AbstractHttpClientWagon
if ( proxyInfo.getHost() != null )
{
HttpHost proxyHost = new HttpHost( proxyInfo.getHost(), proxyInfo.getPort() );
- AuthScope proxyScope = new AuthScope( proxyHost );
+ AuthScope proxyScope = getProxyBasicAuthScope().getScope(
+ proxyHost);
String proxyUsername = proxyInfo.getUserName();
String proxyPassword = proxyInfo.getPassword();
@@ -930,6 +943,48 @@ public abstract class AbstractHttpClientWagon
this.httpConfiguration = httpConfiguration;
}
+ /**
+ * Get the override values for standard HttpClient AuthScope
+ *
+ * @return the basicAuth
+ */
+ public BasicAuthScope getBasicAuthScope() {
+ if (basicAuth == null)
+ basicAuth = new BasicAuthScope();
+ return basicAuth;
+ }
+
+ /**
+ * Set the override values for standard HttpClient AuthScope
+ *
+ * @param basicAuth
+ * the AuthScope to set
+ */
+ public void setBasicAuthScope(BasicAuthScope basicAuth) {
+ this.basicAuth = basicAuth;
+ }
+
+ /**
+ * Get the override values for proxy HttpClient AuthScope
+ *
+ * @return the proxyAuth
+ */
+ public BasicAuthScope getProxyBasicAuthScope() {
+ if (proxyAuth == null)
+ proxyAuth = new BasicAuthScope();
+ return proxyAuth;
+ }
+
+ /**
+ * Set the override values for proxy HttpClient AuthScope
+ *
+ * @param proxyAuth
+ * the AuthScope to set
+ */
+ public void setProxyBasicAuthScope(BasicAuthScope proxyAuth) {
+ this.proxyAuth = proxyAuth;
+ }
+
public void fillInputData( InputData inputData )
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/162e51bd/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/BasicAuthScope.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/BasicAuthScope.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/BasicAuthScope.java
new file mode 100644
index 0000000..016f5c6
--- /dev/null
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/BasicAuthScope.java
@@ -0,0 +1,143 @@
+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.http.HttpHost;
+import org.apache.http.auth.AuthScope;
+
+public class BasicAuthScope {
+ private String host;
+ private String port;
+ private String realm;
+
+ /**
+ * @return the host
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * @param host
+ * the host to set
+ */
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ /**
+ * @return the realm
+ */
+ public String getRealm() {
+ return realm;
+ }
+
+ /**
+ * @param realm
+ * the realm to set
+ */
+ public void setRealm(String realm) {
+ this.realm = realm;
+ }
+
+ /**
+ * Create an authScope given the /repository/host and /repository/password
+ * and the /server/basicAuth or /server/proxyBasicAuth host, port and realm
+ * settings. The basicAuth setting should override the repository settings
+ * host and/or port if host, port or realm is set to "ANY".
+ * <p>
+ * Realm can also be set to a specific string and will be set if
+ * /server/basicAuthentication/realm is non-null
+ *
+ * @param host
+ * The server setting's /server/host value
+ * @param port
+ * The server setting's /server/port value
+ * @return
+ */
+ public AuthScope getScope(String host, int port) {
+ if (getHost() != null && "ANY".compareTo(getHost()) == 0
+ && getPort() != null && "ANY".compareTo(getPort()) == 0
+ && getRealm() != null && "ANY".compareTo(getRealm()) == 0) {
+ return AuthScope.ANY;
+ }
+ String scopeHost = host;
+ if (getHost() != null) {
+ if ("ANY".compareTo(getHost()) == 0) {
+ scopeHost = AuthScope.ANY_HOST;
+ } else {
+ scopeHost = getHost();
+ }
+ }
+
+ int scopePort = port > -1 ? port : AuthScope.ANY_PORT;
+ // -1 for server/port settings does this, but providing an override here
+ // in
+ // the BasicAuthScope config
+ if (getPort() != null) {
+ if ("ANY".compareTo(getPort()) == 0) {
+ scopePort = AuthScope.ANY_PORT;
+ } else {
+ scopePort = Integer.parseInt(getPort());
+ }
+ }
+
+ String scopeRealm = AuthScope.ANY_REALM;
+ if (getRealm() != null) {
+ if ("ANY".compareTo(getRealm()) != 0) {
+ scopeRealm = getRealm();
+ } else {
+ scopeRealm = getRealm();
+ }
+ }
+
+ return new AuthScope(scopeHost, scopePort, scopeRealm);
+ }
+
+ /**
+ * @return the port
+ */
+ public String getPort() {
+ return port;
+ }
+
+ /**
+ * @param port
+ * the port to set
+ */
+ public void setPort(String port) {
+ this.port = port;
+ }
+
+ /**
+ * Given a HttpHost, return scope with overrides from appropriate basicAuth
+ * configuration.
+ * <p>
+ * Note: Protocol is ignored. AuthScope impl ignores it as well, but if that
+ * changed, there could be a problem.
+ * </p>
+ *
+ * @param targetHost
+ * @return
+ */
+ public AuthScope getScope(HttpHost targetHost) {
+ return getScope(targetHost.getHostName(), targetHost.getPort());
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/162e51bd/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java
new file mode 100644
index 0000000..18627f3
--- /dev/null
+++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java
@@ -0,0 +1,94 @@
+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.http.auth.AuthScope;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class BasicAuthScopeTest {
+
+ /**
+ * Test AuthScope override with no overriding values set. Nothing should
+ * change in original host/port.
+ */
+ @Test
+ public void testGetScopeNothingOverridden() {
+ BasicAuthScope scope = new BasicAuthScope();
+
+ AuthScope authScope = scope.getScope("original.host.com", 3456);
+ Assert.assertEquals("original.host.com", authScope.getHost());
+ Assert.assertEquals(3456, authScope.getPort());
+ Assert.assertEquals(AuthScope.ANY_REALM, authScope.getRealm());
+ }
+
+ /**
+ * Test AuthScope override for all values overridden
+ */
+ @Test
+ public void testGetScopeAllOverridden() {
+ BasicAuthScope scope = new BasicAuthScope();
+ scope.setHost("override.host.com");
+ scope.setPort("1234");
+ scope.setRealm("override-realm");
+ AuthScope authScope = scope.getScope("original.host.com", 3456);
+ Assert.assertEquals("override.host.com", authScope.getHost());
+ Assert.assertEquals(1234, authScope.getPort());
+ Assert.assertEquals("override-realm", authScope.getRealm());
+ }
+
+ /**
+ * Test AuthScope override for all values overridden with "ANY"
+ */
+ @Test
+ public void testGetScopeAllAny() {
+ BasicAuthScope scope = new BasicAuthScope();
+ scope.setHost("ANY");
+ scope.setPort("ANY");
+ scope.setRealm("ANY");
+ AuthScope authScope = scope.getScope("original.host.com", 3456);
+ Assert.assertEquals(AuthScope.ANY_HOST, authScope.getHost());
+ Assert.assertEquals(AuthScope.ANY_PORT, authScope.getPort());
+ Assert.assertEquals(AuthScope.ANY_REALM, authScope.getRealm());
+ }
+
+ /**
+ * Test AuthScope override for realm value overridden
+ */
+ @Test
+ public void testGetScopeRealmOverridden() {
+ BasicAuthScope scope = new BasicAuthScope();
+ scope.setRealm("override-realm");
+ AuthScope authScope = scope.getScope("original.host.com", 3456);
+ Assert.assertEquals("original.host.com", authScope.getHost());
+ Assert.assertEquals(3456, authScope.getPort());
+ Assert.assertEquals("override-realm", authScope.getRealm());
+ }
+
+ /**
+ * Test AuthScope where original port is -1, which should result in ANY
+ */
+ @Test
+ public void testGetScopeOriginalPortIsNegativeOne() {
+ BasicAuthScope scope = new BasicAuthScope();
+ AuthScope authScope = scope.getScope("original.host.com", -1);
+ Assert.assertEquals(AuthScope.ANY_PORT, authScope.getPort());
+ }
+}
[2/2] git commit: formatting and add @since
Posted by ol...@apache.org.
formatting and add @since
Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/1d3da753
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/1d3da753
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/1d3da753
Branch: refs/heads/master
Commit: 1d3da753e6661c375bec27cf21880a9364250a4d
Parents: 162e51b
Author: Olivier Lamy <ol...@apache.org>
Authored: Wed Oct 1 10:57:58 2014 +1000
Committer: Olivier Lamy <ol...@apache.org>
Committed: Wed Oct 1 10:57:58 2014 +1000
----------------------------------------------------------------------
.../providers/http/AbstractHttpClientWagon.java | 90 +++++------
.../wagon/providers/http/BasicAuthScope.java | 155 +++++++++++--------
.../providers/http/BasicAuthScopeTest.java | 78 +++++-----
3 files changed, 170 insertions(+), 153 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/1d3da753/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
index a78a1d6..fa31b01 100755
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/AbstractHttpClientWagon.java
@@ -19,25 +19,6 @@ package org.apache.maven.wagon.providers.http;
* under the License.
*/
-import java.io.ByteArrayInputStream;
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Properties;
-import java.util.TimeZone;
-import java.util.concurrent.TimeUnit;
-
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
@@ -442,11 +423,13 @@ public abstract class AbstractHttpClientWagon
/**
* Basic auth scope overrides
+ * @since 2.8
*/
private BasicAuthScope basicAuth;
/**
* Proxy basic auth scope overrides
+ * @since 2.8
*/
private BasicAuthScope proxyAuth;
@@ -471,11 +454,10 @@ public abstract class AbstractHttpClientWagon
Credentials creds = new UsernamePasswordCredentials( username, password );
String host = getRepository().getHost();
- int port = getRepository().getPort();
+ int port = getRepository().getPort();
- credentialsProvider.setCredentials(getBasicAuthScope()
- .getScope(host, port), creds);
- }
+ credentialsProvider.setCredentials( getBasicAuthScope().getScope( host, port ), creds );
+ }
}
ProxyInfo proxyInfo = getProxyInfo( getRepository().getProtocol(), getRepository().getHost() );
@@ -500,11 +482,10 @@ public abstract class AbstractHttpClientWagon
creds = new UsernamePasswordCredentials( proxyUsername, proxyPassword );
}
- int port = proxyInfo.getPort();
+ int port = proxyInfo.getPort();
- AuthScope authScope = getProxyBasicAuthScope().getScope(
- proxyHost, port);
- credentialsProvider.setCredentials(authScope, creds);
+ AuthScope authScope = getProxyBasicAuthScope().getScope( proxyHost, port );
+ credentialsProvider.setCredentials( authScope, creds );
}
}
}
@@ -566,7 +547,7 @@ public abstract class AbstractHttpClientWagon
*/
private String buildUrl( Resource resource )
{
- return EncodingUtil.encodeURLToString( getRepository().getUrl(), resource.getName() );
+ return EncodingUtil.encodeURLToString( getRepository().getUrl(), resource.getName() );
}
@@ -600,7 +581,7 @@ public abstract class AbstractHttpClientWagon
Repository repo = getRepository();
HttpHost targetHost = new HttpHost( repo.getHost(), repo.getPort(), repo.getProtocol() );
- AuthScope targetScope = getBasicAuthScope().getScope(targetHost);
+ AuthScope targetScope = getBasicAuthScope().getScope( targetHost );
if ( credentialsProvider.getCredentials( targetScope ) != null )
{
@@ -822,7 +803,7 @@ public abstract class AbstractHttpClientWagon
if ( config != null && config.isUsePreemptive() )
{
HttpHost targetHost = new HttpHost( repo.getHost(), repo.getPort(), repo.getProtocol() );
- AuthScope targetScope = getBasicAuthScope().getScope(targetHost);
+ AuthScope targetScope = getBasicAuthScope().getScope( targetHost );
if ( credentialsProvider.getCredentials( targetScope ) != null )
{
@@ -837,8 +818,7 @@ public abstract class AbstractHttpClientWagon
if ( proxyInfo.getHost() != null )
{
HttpHost proxyHost = new HttpHost( proxyInfo.getHost(), proxyInfo.getPort() );
- AuthScope proxyScope = getProxyBasicAuthScope().getScope(
- proxyHost);
+ AuthScope proxyScope = getProxyBasicAuthScope().getScope( proxyHost );
String proxyUsername = proxyInfo.getUserName();
String proxyPassword = proxyInfo.getPassword();
@@ -945,44 +925,50 @@ public abstract class AbstractHttpClientWagon
/**
* Get the override values for standard HttpClient AuthScope
- *
+ *
* @return the basicAuth
*/
- public BasicAuthScope getBasicAuthScope() {
- if (basicAuth == null)
- basicAuth = new BasicAuthScope();
- return basicAuth;
+ public BasicAuthScope getBasicAuthScope()
+ {
+ if ( basicAuth == null )
+ {
+ basicAuth = new BasicAuthScope();
+ }
+ return basicAuth;
}
/**
* Set the override values for standard HttpClient AuthScope
- *
- * @param basicAuth
- * the AuthScope to set
+ *
+ * @param basicAuth the AuthScope to set
*/
- public void setBasicAuthScope(BasicAuthScope basicAuth) {
- this.basicAuth = basicAuth;
+ public void setBasicAuthScope( BasicAuthScope basicAuth )
+ {
+ this.basicAuth = basicAuth;
}
/**
* Get the override values for proxy HttpClient AuthScope
- *
+ *
* @return the proxyAuth
*/
- public BasicAuthScope getProxyBasicAuthScope() {
- if (proxyAuth == null)
- proxyAuth = new BasicAuthScope();
- return proxyAuth;
+ public BasicAuthScope getProxyBasicAuthScope()
+ {
+ if ( proxyAuth == null )
+ {
+ proxyAuth = new BasicAuthScope();
+ }
+ return proxyAuth;
}
/**
* Set the override values for proxy HttpClient AuthScope
- *
- * @param proxyAuth
- * the AuthScope to set
+ *
+ * @param proxyAuth the AuthScope to set
*/
- public void setProxyBasicAuthScope(BasicAuthScope proxyAuth) {
- this.proxyAuth = proxyAuth;
+ public void setProxyBasicAuthScope( BasicAuthScope proxyAuth )
+ {
+ this.proxyAuth = proxyAuth;
}
public void fillInputData( InputData inputData )
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/1d3da753/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/BasicAuthScope.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/BasicAuthScope.java b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/BasicAuthScope.java
index 016f5c6..5bcc2d3 100644
--- a/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/BasicAuthScope.java
+++ b/wagon-providers/wagon-http/src/main/java/org/apache/maven/wagon/providers/http/BasicAuthScope.java
@@ -22,39 +22,47 @@ package org.apache.maven.wagon.providers.http;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
-public class BasicAuthScope {
+/**
+ * @since 2.8
+ */
+public class BasicAuthScope
+{
private String host;
+
private String port;
+
private String realm;
/**
* @return the host
*/
- public String getHost() {
- return host;
+ public String getHost()
+ {
+ return host;
}
/**
- * @param host
- * the host to set
+ * @param host the host to set
*/
- public void setHost(String host) {
- this.host = host;
+ public void setHost( String host )
+ {
+ this.host = host;
}
/**
* @return the realm
*/
- public String getRealm() {
- return realm;
+ public String getRealm()
+ {
+ return realm;
}
/**
- * @param realm
- * the realm to set
+ * @param realm the realm to set
*/
- public void setRealm(String realm) {
- this.realm = realm;
+ public void setRealm( String realm )
+ {
+ this.realm = realm;
}
/**
@@ -62,68 +70,84 @@ public class BasicAuthScope {
* and the /server/basicAuth or /server/proxyBasicAuth host, port and realm
* settings. The basicAuth setting should override the repository settings
* host and/or port if host, port or realm is set to "ANY".
- * <p>
+ * <p/>
* Realm can also be set to a specific string and will be set if
* /server/basicAuthentication/realm is non-null
- *
- * @param host
- * The server setting's /server/host value
- * @param port
- * The server setting's /server/port value
+ *
+ * @param host The server setting's /server/host value
+ * @param port The server setting's /server/port value
* @return
*/
- public AuthScope getScope(String host, int port) {
- if (getHost() != null && "ANY".compareTo(getHost()) == 0
- && getPort() != null && "ANY".compareTo(getPort()) == 0
- && getRealm() != null && "ANY".compareTo(getRealm()) == 0) {
- return AuthScope.ANY;
- }
- String scopeHost = host;
- if (getHost() != null) {
- if ("ANY".compareTo(getHost()) == 0) {
- scopeHost = AuthScope.ANY_HOST;
- } else {
- scopeHost = getHost();
- }
- }
-
- int scopePort = port > -1 ? port : AuthScope.ANY_PORT;
- // -1 for server/port settings does this, but providing an override here
- // in
- // the BasicAuthScope config
- if (getPort() != null) {
- if ("ANY".compareTo(getPort()) == 0) {
- scopePort = AuthScope.ANY_PORT;
- } else {
- scopePort = Integer.parseInt(getPort());
- }
- }
-
- String scopeRealm = AuthScope.ANY_REALM;
- if (getRealm() != null) {
- if ("ANY".compareTo(getRealm()) != 0) {
- scopeRealm = getRealm();
- } else {
- scopeRealm = getRealm();
- }
- }
-
- return new AuthScope(scopeHost, scopePort, scopeRealm);
+ public AuthScope getScope( String host, int port )
+ {
+ if ( getHost() != null //
+ && "ANY".compareTo( getHost() ) == 0 //
+ && getPort() != null //
+ && "ANY".compareTo( getPort() ) == 0 //
+ && getRealm() != null //
+ && "ANY".compareTo( getRealm() ) == 0 )
+ {
+ return AuthScope.ANY;
+ }
+ String scopeHost = host;
+ if ( getHost() != null )
+ {
+ if ( "ANY".compareTo( getHost() ) == 0 )
+ {
+ scopeHost = AuthScope.ANY_HOST;
+ }
+ else
+ {
+ scopeHost = getHost();
+ }
+ }
+
+ int scopePort = port > -1 ? port : AuthScope.ANY_PORT;
+ // -1 for server/port settings does this, but providing an override here
+ // in
+ // the BasicAuthScope config
+ if ( getPort() != null )
+ {
+ if ( "ANY".compareTo( getPort() ) == 0 )
+ {
+ scopePort = AuthScope.ANY_PORT;
+ }
+ else
+ {
+ scopePort = Integer.parseInt( getPort() );
+ }
+ }
+
+ String scopeRealm = AuthScope.ANY_REALM;
+ if ( getRealm() != null )
+ {
+ if ( "ANY".compareTo( getRealm() ) != 0 )
+ {
+ scopeRealm = getRealm();
+ }
+ else
+ {
+ scopeRealm = getRealm();
+ }
+ }
+
+ return new AuthScope( scopeHost, scopePort, scopeRealm );
}
/**
* @return the port
*/
- public String getPort() {
- return port;
+ public String getPort()
+ {
+ return port;
}
/**
- * @param port
- * the port to set
+ * @param port the port to set
*/
- public void setPort(String port) {
- this.port = port;
+ public void setPort( String port )
+ {
+ this.port = port;
}
/**
@@ -133,11 +157,12 @@ public class BasicAuthScope {
* Note: Protocol is ignored. AuthScope impl ignores it as well, but if that
* changed, there could be a problem.
* </p>
- *
+ *
* @param targetHost
* @return
*/
- public AuthScope getScope(HttpHost targetHost) {
- return getScope(targetHost.getHostName(), targetHost.getPort());
+ public AuthScope getScope( HttpHost targetHost )
+ {
+ return getScope( targetHost.getHostName(), targetHost.getPort() );
}
}
http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/1d3da753/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java
----------------------------------------------------------------------
diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java
index 18627f3..9cab689 100644
--- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java
+++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java
@@ -23,72 +23,78 @@ import org.apache.http.auth.AuthScope;
import org.junit.Assert;
import org.junit.Test;
-public class BasicAuthScopeTest {
+public class BasicAuthScopeTest
+{
/**
* Test AuthScope override with no overriding values set. Nothing should
* change in original host/port.
*/
@Test
- public void testGetScopeNothingOverridden() {
- BasicAuthScope scope = new BasicAuthScope();
+ public void testGetScopeNothingOverridden()
+ {
+ BasicAuthScope scope = new BasicAuthScope();
- AuthScope authScope = scope.getScope("original.host.com", 3456);
- Assert.assertEquals("original.host.com", authScope.getHost());
- Assert.assertEquals(3456, authScope.getPort());
- Assert.assertEquals(AuthScope.ANY_REALM, authScope.getRealm());
+ AuthScope authScope = scope.getScope( "original.host.com", 3456 );
+ Assert.assertEquals( "original.host.com", authScope.getHost() );
+ Assert.assertEquals( 3456, authScope.getPort() );
+ Assert.assertEquals( AuthScope.ANY_REALM, authScope.getRealm() );
}
/**
* Test AuthScope override for all values overridden
*/
@Test
- public void testGetScopeAllOverridden() {
- BasicAuthScope scope = new BasicAuthScope();
- scope.setHost("override.host.com");
- scope.setPort("1234");
- scope.setRealm("override-realm");
- AuthScope authScope = scope.getScope("original.host.com", 3456);
- Assert.assertEquals("override.host.com", authScope.getHost());
- Assert.assertEquals(1234, authScope.getPort());
- Assert.assertEquals("override-realm", authScope.getRealm());
+ public void testGetScopeAllOverridden()
+ {
+ BasicAuthScope scope = new BasicAuthScope();
+ scope.setHost( "override.host.com" );
+ scope.setPort( "1234" );
+ scope.setRealm( "override-realm" );
+ AuthScope authScope = scope.getScope( "original.host.com", 3456 );
+ Assert.assertEquals( "override.host.com", authScope.getHost() );
+ Assert.assertEquals( 1234, authScope.getPort() );
+ Assert.assertEquals( "override-realm", authScope.getRealm() );
}
/**
* Test AuthScope override for all values overridden with "ANY"
*/
@Test
- public void testGetScopeAllAny() {
- BasicAuthScope scope = new BasicAuthScope();
- scope.setHost("ANY");
- scope.setPort("ANY");
- scope.setRealm("ANY");
- AuthScope authScope = scope.getScope("original.host.com", 3456);
- Assert.assertEquals(AuthScope.ANY_HOST, authScope.getHost());
- Assert.assertEquals(AuthScope.ANY_PORT, authScope.getPort());
- Assert.assertEquals(AuthScope.ANY_REALM, authScope.getRealm());
+ public void testGetScopeAllAny()
+ {
+ BasicAuthScope scope = new BasicAuthScope();
+ scope.setHost( "ANY" );
+ scope.setPort( "ANY" );
+ scope.setRealm( "ANY" );
+ AuthScope authScope = scope.getScope( "original.host.com", 3456 );
+ Assert.assertEquals( AuthScope.ANY_HOST, authScope.getHost() );
+ Assert.assertEquals( AuthScope.ANY_PORT, authScope.getPort() );
+ Assert.assertEquals( AuthScope.ANY_REALM, authScope.getRealm() );
}
/**
* Test AuthScope override for realm value overridden
*/
@Test
- public void testGetScopeRealmOverridden() {
- BasicAuthScope scope = new BasicAuthScope();
- scope.setRealm("override-realm");
- AuthScope authScope = scope.getScope("original.host.com", 3456);
- Assert.assertEquals("original.host.com", authScope.getHost());
- Assert.assertEquals(3456, authScope.getPort());
- Assert.assertEquals("override-realm", authScope.getRealm());
+ public void testGetScopeRealmOverridden()
+ {
+ BasicAuthScope scope = new BasicAuthScope();
+ scope.setRealm( "override-realm" );
+ AuthScope authScope = scope.getScope( "original.host.com", 3456 );
+ Assert.assertEquals( "original.host.com", authScope.getHost() );
+ Assert.assertEquals( 3456, authScope.getPort() );
+ Assert.assertEquals( "override-realm", authScope.getRealm() );
}
/**
* Test AuthScope where original port is -1, which should result in ANY
*/
@Test
- public void testGetScopeOriginalPortIsNegativeOne() {
- BasicAuthScope scope = new BasicAuthScope();
- AuthScope authScope = scope.getScope("original.host.com", -1);
- Assert.assertEquals(AuthScope.ANY_PORT, authScope.getPort());
+ public void testGetScopeOriginalPortIsNegativeOne()
+ {
+ BasicAuthScope scope = new BasicAuthScope();
+ AuthScope authScope = scope.getScope( "original.host.com", -1 );
+ Assert.assertEquals( AuthScope.ANY_PORT, authScope.getPort() );
}
}