verify roles for repository are configured on startup

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1471410 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2013-04-24 13:38:23 +00:00
parent 3c082f7e58
commit a63168fbbc
2 changed files with 28 additions and 5 deletions

View File

@ -109,7 +109,7 @@ public class DefaultManagedRepositoryAdmin
@PostConstruct @PostConstruct
public void initialize() public void initialize()
throws RepositoryAdminException throws RepositoryAdminException, RoleManagerException
{ {
try try
{ {
@ -120,10 +120,12 @@ public class DefaultManagedRepositoryAdmin
{ {
throw new RepositoryAdminException( e.getMessage(), e ); throw new RepositoryAdminException( e.getMessage(), e );
} }
// initialize index context on start // initialize index context on start and check roles here
for ( ManagedRepository managedRepository : getManagedRepositories() ) for ( ManagedRepository managedRepository : getManagedRepositories() )
{ {
createIndexContext( managedRepository ); createIndexContext( managedRepository );
addRepositoryRoles( managedRepository.getId() );
} }
} }
@ -264,13 +266,13 @@ public class DefaultManagedRepositoryAdmin
try try
{ {
addRepository( repository, config ); addRepository( repository, config );
addRepositoryRoles( repository ); addRepositoryRoles( repository.getId() );
if ( stageRepoNeeded ) if ( stageRepoNeeded )
{ {
ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository ); ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
addRepository( stagingRepository, config ); addRepository( stagingRepository, config );
addRepositoryRoles( stagingRepository ); addRepositoryRoles( stagingRepository.getId() );
triggerAuditEvent( stagingRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation ); triggerAuditEvent( stagingRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
} }
} }
@ -727,7 +729,8 @@ public class DefaultManagedRepositoryAdmin
return true; return true;
} }
protected void addRepositoryRoles( ManagedRepositoryConfiguration newRepository )
public void addRepositoryRoles( ManagedRepository newRepository )
throws RoleManagerException throws RoleManagerException
{ {
String repoId = newRepository.getId(); 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 ) protected void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository )
throws RoleManagerException throws RoleManagerException
{ {

View File

@ -179,6 +179,8 @@ public class DefaultRedbackRuntimeConfigurationService
ldapUserMapper.initialize(); ldapUserMapper.initialize();
//check repositories roles are here !!!
return Boolean.TRUE; return Boolean.TRUE;
} }
catch ( Exception e ) catch ( Exception e )