]> source.dussan.org Git - archiva.git/commitdiff
verify roles for repository are configured on startup
authorOlivier Lamy <olamy@apache.org>
Wed, 24 Apr 2013 13:38:23 +0000 (13:38 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 24 Apr 2013 13:38:23 +0000 (13:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1471410 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRedbackRuntimeConfigurationService.java

index f3c62a02319468126e8174f40958fc30e16c5817..f35af62e4f93390a79864200b3da72152cf9cb35 100644 (file)
@@ -109,7 +109,7 @@ public class DefaultManagedRepositoryAdmin
 
     @PostConstruct
     public void initialize()
-        throws RepositoryAdminException
+        throws RepositoryAdminException, RoleManagerException
     {
         try
         {
@@ -120,10 +120,12 @@ public class DefaultManagedRepositoryAdmin
         {
             throw new RepositoryAdminException( e.getMessage(), e );
         }
-        // initialize index context on start
+        // initialize index context on start and check roles here
         for ( ManagedRepository managedRepository : getManagedRepositories() )
         {
             createIndexContext( managedRepository );
+            addRepositoryRoles( managedRepository.getId() );
+
         }
     }
 
@@ -264,13 +266,13 @@ public class DefaultManagedRepositoryAdmin
         try
         {
             addRepository( repository, config );
-            addRepositoryRoles( repository );
+            addRepositoryRoles( repository.getId() );
 
             if ( stageRepoNeeded )
             {
                 ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
                 addRepository( stagingRepository, config );
-                addRepositoryRoles( stagingRepository );
+                addRepositoryRoles( stagingRepository.getId() );
                 triggerAuditEvent( stagingRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
             }
         }
@@ -727,7 +729,8 @@ public class DefaultManagedRepositoryAdmin
         return true;
     }
 
-    protected void addRepositoryRoles( ManagedRepositoryConfiguration newRepository )
+
+    public void addRepositoryRoles( ManagedRepository newRepository )
         throws RoleManagerException
     {
         String repoId = newRepository.getId();
@@ -746,6 +749,24 @@ public class DefaultManagedRepositoryAdmin
         }
     }
 
+
+    private void addRepositoryRoles( String repoId )
+        throws RoleManagerException
+    {
+        // TODO: double check these are configured on start up
+        // TODO: belongs in the business logic
+
+        if ( !getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
+        {
+            getRoleManager().createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
+        }
+
+        if ( !getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
+        {
+            getRoleManager().createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
+        }
+    }
+
     protected void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository )
         throws RoleManagerException
     {
index bd856338a6ee68731692e6c7c05011d7fd114a7d..6bd4dd280234e55b44a0ccab3cac429925c4d3bb 100644 (file)
@@ -179,6 +179,8 @@ public class DefaultRedbackRuntimeConfigurationService
 
             ldapUserMapper.initialize();
 
+            //check repositories roles are here !!!
+
             return Boolean.TRUE;
         }
         catch ( Exception e )