]> source.dussan.org Git - archiva.git/commitdiff
added in a refresh in case the user store is nukes and the repos still exist, it...
authorJesse McConnell <jmcconnell@apache.org>
Tue, 19 Sep 2006 10:28:26 +0000 (10:28 +0000)
committerJesse McConnell <jmcconnell@apache.org>
Tue, 19 Sep 2006 10:28:26 +0000 (10:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@447799 13f79535-47bb-0310-9956-ffa450edef68

archiva-webapp/src/main/java/org/apache/maven/archiva/web/interceptor/ConfigurationInterceptor.java

index cb6cc4fe4a55bd3fd6e16028a217856afb9c38a4..25cafd0d7546287c7fac8403b9d8483ab2dd1ddc 100644 (file)
@@ -20,11 +20,15 @@ import com.opensymphony.xwork.ActionInvocation;
 import com.opensymphony.xwork.interceptor.Interceptor;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.ConfigurationStore;
+import org.apache.maven.archiva.configuration.ConfigurationStoreException;
 import org.apache.maven.archiva.web.util.RoleManager;
 import org.apache.maven.archiva.web.ArchivaDefaults;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.security.rbac.RBACManager;
 
+import java.util.Map;
+import java.util.Iterator;
+
 /**
  * An interceptor that makes the application configuration available
  *
@@ -65,6 +69,7 @@ public class ConfigurationInterceptor
         throws Exception
     {
         archivaDefaults.ensureDefaultsExist();
+        ensureRepoRolesExist();
 
         // determine if we need an admin account made
 
@@ -89,6 +94,38 @@ public class ConfigurationInterceptor
         }
     }
 
+    public void ensureRepoRolesExist()
+    {
+        try
+        {
+            if ( configurationStore.getConfigurationFromStore().isValid() )
+            {
+                Map repositories = configurationStore.getConfigurationFromStore().getRepositoriesMap();
+
+                for ( Iterator i = repositories.keySet().iterator(); i.hasNext(); )
+                {
+                    String id = (String) i.next();
+
+                    if ( !rbacManager.roleExists( "Repository Observer - " + id ) )
+                    {
+                        getLogger().info( "recovering Repository Observer - " + id );
+                        roleManager.addRepository( id );
+                    }
+
+                    if ( !rbacManager.roleExists( "Repository Manager - " + id ) )
+                    {
+                        getLogger().info( "recovering Repository Manager - " + id );
+                        roleManager.addRepository( id );
+                    }
+                }
+            }
+        }
+        catch ( ConfigurationStoreException e )
+        {
+            throw new RuntimeException( "error with configurationStore()" );
+        }
+    }
+
     public void destroy()
     {
         // This space left intentionally blank