]> source.dussan.org Git - archiva.git/commitdiff
[MRM-582] Remote Repositories with empty <username> and <password> fields shouldn...
authorJoakim Erdfelt <joakime@apache.org>
Thu, 8 Nov 2007 16:19:05 +0000 (16:19 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Thu, 8 Nov 2007 16:19:05 +0000 (16:19 +0000)
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

archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
archiva-base/archiva-configuration/src/test/conf/repository-manager.xml
archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java

index 52701830cd37f39035e613f6716884a7cc0b6a63..4ca6f0229aecdb8b0e272a17ba8785e1f7de7fcd 100644 (file)
@@ -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() )
         {
index a8f7054a9f0094a23b017a8404f745d993d57360..7566d549fec11851156641da100ae772dc0300f2 100644 (file)
@@ -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>
 
       <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>
index ab2fae5d64002dc231e21a6a365eb4200b5594fa..03fd894985a113f10416e6193c7ad45618d7886e 100644 (file)
@@ -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() );
+    }
 }
index c2946b33cf87740bd4dccf4b83f956a4907b68a8..70d9c0f20003933b8a84a0ee2466daf8221da6a7 100644 (file)
@@ -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 );