aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-11-08 16:19:05 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-11-08 16:19:05 +0000
commit9f4dee3c7192645ee1f9e3063495b971ee14d0c6 (patch)
treef720ed17cf507c551ba4be3665d0b408f787acb7
parent48330ef457b97a358fc8efc65385c804518608b2 (diff)
downloadarchiva-9f4dee3c7192645ee1f9e3063495b971ee14d0c6.tar.gz
archiva-9f4dee3c7192645ee1f9e3063495b971ee14d0c6.zip
[MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
Implemented on-load cleanup of remote repo username/password (instead of on-save) Implemented proper check for blank username/password in proxy connectors. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@593220 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java20
-rw-r--r--archiva-base/archiva-configuration/src/test/conf/repository-manager.xml18
-rw-r--r--archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java25
-rw-r--r--archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java6
4 files changed, 59 insertions, 10 deletions
diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
index 52701830c..4ca6f0229 100644
--- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
@@ -22,6 +22,7 @@ package org.apache.maven.archiva.configuration;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.functors.ProxyConnectorConfigurationOrderComparator;
import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryReader;
import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryWriter;
@@ -41,7 +42,6 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExce
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.registry.RegistryListener;
-import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.IOException;
@@ -196,6 +196,24 @@ public class DefaultArchivaConfiguration
registry.removeSubset( KEY + ".repositories" );
}
+
+ if ( !CollectionUtils.isEmpty( config.getRemoteRepositories() ) )
+ {
+ List<RemoteRepositoryConfiguration> remoteRepos = config.getRemoteRepositories();
+ for ( RemoteRepositoryConfiguration repo : remoteRepos )
+ {
+ // [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
+ if( StringUtils.isBlank( repo.getUsername() ) )
+ {
+ repo.setUsername( null );
+ }
+
+ if( StringUtils.isBlank( repo.getPassword() ) )
+ {
+ repo.setPassword( null );
+ }
+ }
+ }
if ( !config.getProxyConnectors().isEmpty() )
{
diff --git a/archiva-base/archiva-configuration/src/test/conf/repository-manager.xml b/archiva-base/archiva-configuration/src/test/conf/repository-manager.xml
index a8f7054a9..7566d549f 100644
--- a/archiva-base/archiva-configuration/src/test/conf/repository-manager.xml
+++ b/archiva-base/archiva-configuration/src/test/conf/repository-manager.xml
@@ -54,6 +54,8 @@
<name>Java.net Repository for Maven 2</name>
<url>https://maven2-repository.dev.java.net/nonav/repository</url>
<layout>default</layout>
+ <username></username>
+ <password></password>
</remoteRepository>
</remoteRepositories>
@@ -62,17 +64,21 @@
<sourceRepoId>internal</sourceRepoId>
<targetRepoId>central</targetRepoId>
<proxyId/>
- <snapshotsPolicy>disabled</snapshotsPolicy>
- <releasePolicy>never</releasePolicy>
- <failurePolicy>not-found</failurePolicy>
+ <policies>
+ <releases>ignored</releases>
+ <snapshots>disabled</snapshots>
+ <cache-failures>cached</cache-failures>
+ </policies>
</proxyConnector>
<proxyConnector>
<sourceRepoId>internal</sourceRepoId>
<targetRepoId>maven2-repository.dev.java.net</targetRepoId>
<proxyId/>
- <snapshotsPolicy>disabled</snapshotsPolicy>
- <releasePolicy>never</releasePolicy>
- <failurePolicy>not-found</failurePolicy>
+ <policies>
+ <releases>ignored</releases>
+ <snapshots>disabled</snapshots>
+ <cache-failures>cached</cache-failures>
+ </policies>
<whiteListPatterns>
<whiteListPattern>javax/**</whiteListPattern>
</whiteListPatterns>
diff --git a/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
index ab2fae5d6..03fd89498 100644
--- a/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
+++ b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
@@ -636,4 +636,29 @@ public class ArchivaConfigurationTest
assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
}
+
+ /**
+ * [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
+ */
+ public void testGetConfigurationFixEmptyRemoteRepoUsernamePassword()
+ throws Exception
+ {
+ ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup(
+ ArchivaConfiguration.class.getName(),
+ "test-configuration" );
+
+ Configuration configuration = archivaConfiguration.getConfiguration();
+ assertConfiguration( configuration );
+ assertEquals( "check remote repositories", 2, configuration.getRemoteRepositories().size() );
+
+ RemoteRepositoryConfiguration repository = (RemoteRepositoryConfiguration) configuration
+ .getRemoteRepositoriesAsMap().get( "maven2-repository.dev.java.net" );
+
+ assertEquals( "remote repository.url", "https://maven2-repository.dev.java.net/nonav/repository", repository.getUrl() );
+ assertEquals( "remote repository.name", "Java.net Repository for Maven 2", repository.getName() );
+ assertEquals( "remote repository.id", "maven2-repository.dev.java.net", repository.getId() );
+ assertEquals( "remote repository.layout", "default", repository.getLayout() );
+ assertNull( "remote repository.username == null", repository.getUsername() );
+ assertNull( "remote repository.password == null", repository.getPassword() );
+ }
}
diff --git a/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
index c2946b33c..70d9c0f20 100644
--- a/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
+++ b/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
@@ -792,10 +792,10 @@ public class DefaultRepositoryProxyConnectors
AuthenticationInfo authInfo = null;
String username = remoteRepository.getRepository().getUsername();
String password = remoteRepository.getRepository().getPassword();
- if ( username != null && password != null )
+
+ if ( StringUtils.isNotBlank( username ) && StringUtils.isNotBlank( password ) )
{
- getLogger().debug(
- "Using username " + username + " to connect to remote repository "
+ getLogger().debug( "Using username " + username + " to connect to remote repository "
+ remoteRepository.getURL() );
authInfo = new AuthenticationInfo();
authInfo.setUserName( username );