mirror of https://github.com/apache/archiva.git
[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:
parent
48330ef457
commit
9f4dee3c71
|
@ -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() )
|
||||
{
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue