]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1612] reduce number of security checks for a configuration change to avoid
authorBrett Porter <brett@apache.org>
Thu, 1 Mar 2012 13:15:45 +0000 (13:15 +0000)
committerBrett Porter <brett@apache.org>
Thu, 1 Mar 2012 13:15:45 +0000 (13:15 +0000)
blocking when the number of repositories gets large

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1295553 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/startup/SecuritySynchronization.java

index 76d81feef0f2f30b6bc97c38344179d3d8091fa5..47980e88cb326db909f202699713217c42c492ce 100644 (file)
@@ -100,9 +100,12 @@ public class SecuritySynchronization
 
     public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
     {
-        if ( ConfigurationNames.isManagedRepositories( propertyName ) )
+        if ( ConfigurationNames.isManagedRepositories( propertyName ) && propertyName.endsWith( ".id" ) )
         {
-            synchConfiguration( archivaConfiguration.getConfiguration().getManagedRepositories() );
+            if ( propertyValue != null )
+            {
+                syncRepoConfiguration( (String) propertyValue );
+            }
         }
     }
 
@@ -117,39 +120,38 @@ public class SecuritySynchronization
 
         for ( ManagedRepositoryConfiguration repoConfig : repos )
         {
-            // manage roles for repositories
-            try
+            syncRepoConfiguration( repoConfig.getId() );
+        }
+    }
+
+    private void syncRepoConfiguration( String id )
+    {
+        // manage roles for repositories
+        try
+        {
+            if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id ) )
             {
-                if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
-                                                       repoConfig.getId() ) )
-                {
-                    roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
-                                                     repoConfig.getId() );
-                }
-                else
-                {
-                    roleManager.verifyTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
-                                                     repoConfig.getId() );
-                }
+                roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id );
+            }
+            else
+            {
+                roleManager.verifyTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id );
+            }
 
-                if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
-                                                       repoConfig.getId() ) )
-                {
-                    roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
-                                                     repoConfig.getId() );
-                }
-                else
-                {
-                    roleManager.verifyTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
-                                                     repoConfig.getId() );
-                }
+            if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, id ) )
+            {
+                roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, id );
             }
-            catch ( RoleManagerException e )
+            else
             {
-                // Log error.
-                log.error( "Unable to create roles for configured repositories: " + e.getMessage(), e );
+                roleManager.verifyTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, id );
             }
         }
+        catch ( RoleManagerException e )
+        {
+            // Log error.
+            log.error( "Unable to create roles for configured repositories: " + e.getMessage(), e );
+        }
     }
 
     public void startup()