[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
This commit is contained in:
Joakim Erdfelt 2007-11-08 16:19:05 +00:00
parent 48330ef457
commit 9f4dee3c71
4 changed files with 59 additions and 10 deletions

View File

@ -22,6 +22,7 @@ package org.apache.maven.archiva.configuration;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.io.FileUtils; 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.functors.ProxyConnectorConfigurationOrderComparator;
import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryReader; import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryReader;
import org.apache.maven.archiva.configuration.io.registry.ConfigurationRegistryWriter; 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.Registry;
import org.codehaus.plexus.registry.RegistryException; import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.registry.RegistryListener; import org.codehaus.plexus.registry.RegistryListener;
import org.codehaus.plexus.util.StringUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -197,6 +197,24 @@ public class DefaultArchivaConfiguration
registry.removeSubset( KEY + ".repositories" ); 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() ) if ( !config.getProxyConnectors().isEmpty() )
{ {
// Fix Proxy Connector Settings. // Fix Proxy Connector Settings.

View File

@ -54,6 +54,8 @@
<name>Java.net Repository for Maven 2</name> <name>Java.net Repository for Maven 2</name>
<url>https://maven2-repository.dev.java.net/nonav/repository</url> <url>https://maven2-repository.dev.java.net/nonav/repository</url>
<layout>default</layout> <layout>default</layout>
<username></username>
<password></password>
</remoteRepository> </remoteRepository>
</remoteRepositories> </remoteRepositories>
@ -62,17 +64,21 @@
<sourceRepoId>internal</sourceRepoId> <sourceRepoId>internal</sourceRepoId>
<targetRepoId>central</targetRepoId> <targetRepoId>central</targetRepoId>
<proxyId/> <proxyId/>
<snapshotsPolicy>disabled</snapshotsPolicy> <policies>
<releasePolicy>never</releasePolicy> <releases>ignored</releases>
<failurePolicy>not-found</failurePolicy> <snapshots>disabled</snapshots>
<cache-failures>cached</cache-failures>
</policies>
</proxyConnector> </proxyConnector>
<proxyConnector> <proxyConnector>
<sourceRepoId>internal</sourceRepoId> <sourceRepoId>internal</sourceRepoId>
<targetRepoId>maven2-repository.dev.java.net</targetRepoId> <targetRepoId>maven2-repository.dev.java.net</targetRepoId>
<proxyId/> <proxyId/>
<snapshotsPolicy>disabled</snapshotsPolicy> <policies>
<releasePolicy>never</releasePolicy> <releases>ignored</releases>
<failurePolicy>not-found</failurePolicy> <snapshots>disabled</snapshots>
<cache-failures>cached</cache-failures>
</policies>
<whiteListPatterns> <whiteListPatterns>
<whiteListPattern>javax/**</whiteListPattern> <whiteListPattern>javax/**</whiteListPattern>
</whiteListPatterns> </whiteListPatterns>

View File

@ -636,4 +636,29 @@ public class ArchivaConfigurationTest
assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() ); 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() );
}
} }

View File

@ -792,10 +792,10 @@ public class DefaultRepositoryProxyConnectors
AuthenticationInfo authInfo = null; AuthenticationInfo authInfo = null;
String username = remoteRepository.getRepository().getUsername(); String username = remoteRepository.getRepository().getUsername();
String password = remoteRepository.getRepository().getPassword(); String password = remoteRepository.getRepository().getPassword();
if ( username != null && password != null )
if ( StringUtils.isNotBlank( username ) && StringUtils.isNotBlank( password ) )
{ {
getLogger().debug( getLogger().debug( "Using username " + username + " to connect to remote repository "
"Using username " + username + " to connect to remote repository "
+ remoteRepository.getURL() ); + remoteRepository.getURL() );
authInfo = new AuthenticationInfo(); authInfo = new AuthenticationInfo();
authInfo.setUserName( username ); authInfo.setUserName( username );