]> source.dussan.org Git - archiva.git/commitdiff
[MRM-398] configure guest access by default for pre-configured repositories
authorJoakim Erdfelt <joakime@apache.org>
Mon, 15 Oct 2007 20:39:26 +0000 (20:39 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Mon, 15 Oct 2007 20:39:26 +0000 (20:39 +0000)
Reverted partially r584279. (some good fixes for related bugs in place)
Introduced ArchivaConfiguration.isDefaulted() to aide SecuritySynchronization (startup task in archiva-webapp) to add guest user read-only roles if the configuration was set to default for some reason.

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

archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java
archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/SecuritySynchronization.java

index 9a52f7aa6626ef96f1a9afb6b3ca93dba271f5af..f15ca054243eebdb44c2108b925153070b26c5bc 100644 (file)
@@ -23,9 +23,6 @@ import org.apache.commons.io.FileUtils;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.security.ArchivaRoleConstants;
-import org.codehaus.plexus.redback.rbac.RBACManager;
-import org.codehaus.plexus.redback.rbac.RbacManagerException;
-import org.codehaus.plexus.redback.rbac.UserAssignment;
 import org.codehaus.plexus.redback.role.RoleManager;
 import org.codehaus.plexus.redback.role.RoleManagerException;
 
@@ -48,11 +45,6 @@ public abstract class AbstractManagedRepositoriesAction
      */
     protected RoleManager roleManager;
     
-    /**
-     * @plexus.requirement role-hint="cached"
-     */
-    protected RBACManager rbacManager;
-
     public RoleManager getRoleManager()
     {
         return roleManager;
@@ -98,18 +90,6 @@ public abstract class AbstractManagedRepositoriesAction
         {
             roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
         }
-
-        try
-        {
-            UserAssignment ua = rbacManager.getUserAssignment( ArchivaRoleConstants.GUEST_ROLE );
-            ua.addRoleName( ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - " + repoId );
-            rbacManager.saveUserAssignment( ua );
-        }
-        catch ( RbacManagerException e )
-        {
-            getLogger().warn( "Unable to add role [" + ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - "
-                              + repoId + "] to Guest user.", e );
-        }
     }
 
     protected void removeContents( ManagedRepositoryConfiguration existingRepository )
index b2e37ec0df72a28f70991966b1bcd8d0fdbae565..c63dbe0608a964586e622bd7ad40642cdd3c4e63 100644 (file)
@@ -25,6 +25,9 @@ import org.apache.maven.archiva.configuration.ConfigurationNames;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.security.ArchivaRoleConstants;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.rbac.RbacManagerException;
+import org.codehaus.plexus.redback.rbac.UserAssignment;
 import org.codehaus.plexus.redback.role.RoleManager;
 import org.codehaus.plexus.redback.role.RoleManagerException;
 import org.codehaus.plexus.registry.Registry;
@@ -49,6 +52,11 @@ public class SecuritySynchronization
      * @plexus.requirement role-hint="default"
      */
     private RoleManager roleManager;
+    
+    /**
+     * @plexus.requirement role-hint="cached"
+     */
+    private RBACManager rbacManager;
 
     /**
      * @plexus.requirement
@@ -104,5 +112,29 @@ public class SecuritySynchronization
     {
         synchConfiguration( archivaConfiguration.getConfiguration().getManagedRepositories() );
         archivaConfiguration.addChangeListener( this );
+        
+        if ( archivaConfiguration.isDefaulted() )
+        {
+            assignRepositoryObserverToGuestUser( archivaConfiguration.getConfiguration().getManagedRepositories() );
+        }
+    }
+
+    private void assignRepositoryObserverToGuestUser( List<ManagedRepositoryConfiguration> repos )
+    {
+        for ( ManagedRepositoryConfiguration repoConfig : repos )
+        {
+            String repoId = repoConfig.getId();
+            try
+            {
+                UserAssignment ua = rbacManager.getUserAssignment( ArchivaRoleConstants.GUEST_ROLE );
+                ua.addRoleName( ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - " + repoId );
+                rbacManager.saveUserAssignment( ua );
+            }
+            catch ( RbacManagerException e )
+            {
+                getLogger().warn( "Unable to add role [" + ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - "
+                                      + repoId + "] to Guest user.", e );
+            }
+        }
     }
 }