You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DefaultManagedRepositoryAdmin.java 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. package org.apache.archiva.admin.repository.managed;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.admin.model.AuditInformation;
  21. import org.apache.archiva.admin.model.RepositoryAdminException;
  22. import org.apache.archiva.admin.model.beans.ManagedRepository;
  23. import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
  24. import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
  25. import org.apache.archiva.components.cache.Cache;
  26. import org.apache.archiva.components.taskqueue.TaskQueueException;
  27. import org.apache.archiva.configuration.model.Configuration;
  28. import org.apache.archiva.configuration.model.ManagedRepositoryConfiguration;
  29. import org.apache.archiva.configuration.model.ProxyConnectorConfiguration;
  30. import org.apache.archiva.indexer.ArchivaIndexManager;
  31. import org.apache.archiva.indexer.IndexManagerFactory;
  32. import org.apache.archiva.indexer.IndexUpdateFailedException;
  33. import org.apache.archiva.metadata.model.facets.AuditEvent;
  34. import org.apache.archiva.metadata.repository.MetadataRepository;
  35. import org.apache.archiva.metadata.repository.MetadataRepositoryException;
  36. import org.apache.archiva.metadata.repository.MetadataSessionException;
  37. import org.apache.archiva.metadata.repository.RepositorySession;
  38. import org.apache.archiva.metadata.repository.RepositorySessionFactory;
  39. import org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsManager;
  40. import org.apache.archiva.redback.role.RoleManager;
  41. import org.apache.archiva.redback.role.RoleManagerException;
  42. import org.apache.archiva.repository.ReleaseScheme;
  43. import org.apache.archiva.repository.RepositoryException;
  44. import org.apache.archiva.repository.RepositoryRegistry;
  45. import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
  46. import org.apache.archiva.repository.features.ArtifactCleanupFeature;
  47. import org.apache.archiva.repository.features.IndexCreationFeature;
  48. import org.apache.archiva.repository.features.StagingRepositoryFeature;
  49. import org.apache.archiva.scheduler.repository.model.RepositoryArchivaTaskScheduler;
  50. import org.apache.archiva.scheduler.repository.model.RepositoryTask;
  51. import org.apache.archiva.security.common.ArchivaRoleConstants;
  52. import org.apache.commons.lang3.StringUtils;
  53. import org.slf4j.Logger;
  54. import org.slf4j.LoggerFactory;
  55. import org.springframework.stereotype.Service;
  56. import javax.annotation.PostConstruct;
  57. import javax.annotation.PreDestroy;
  58. import javax.inject.Inject;
  59. import javax.inject.Named;
  60. import java.io.IOException;
  61. import java.nio.file.Path;
  62. import java.nio.file.Paths;
  63. import java.util.ArrayList;
  64. import java.util.List;
  65. import java.util.Map;
  66. import java.util.stream.Collectors;
  67. /**
  68. * FIXME review the staging mechanism to have a per user session one
  69. *
  70. * @author Olivier Lamy
  71. */
  72. @Service("managedRepositoryAdmin#default")
  73. public class DefaultManagedRepositoryAdmin
  74. extends AbstractRepositoryAdmin
  75. implements ManagedRepositoryAdmin
  76. {
  77. private Logger log = LoggerFactory.getLogger( getClass() );
  78. public static final String STAGE_REPO_ID_END = "-stage";
  79. @Inject
  80. private RepositoryRegistry repositoryRegistry;
  81. @SuppressWarnings( "unused" )
  82. @Inject
  83. private RepositoryHandlerDependencies managedRepositoryHandler;
  84. @Inject
  85. @Named(value = "archivaTaskScheduler#repository")
  86. private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
  87. /**
  88. * FIXME: this could be multiple implementations and needs to be configured.
  89. */
  90. @Inject
  91. private RepositorySessionFactory repositorySessionFactory;
  92. @Inject
  93. private RepositoryStatisticsManager repositoryStatisticsManager;
  94. @Inject
  95. protected RoleManager roleManager;
  96. @Inject
  97. @Named(value = "cache#namespaces")
  98. private Cache<String, List<String>> namespacesCache;
  99. @Inject
  100. private IndexManagerFactory indexManagerFactory;
  101. @PostConstruct
  102. public void initialize()
  103. throws RepositoryAdminException, RoleManagerException
  104. {
  105. // initialize index context on start and check roles here
  106. for ( ManagedRepository managedRepository : getManagedRepositories() )
  107. {
  108. log.debug("Initializating {}", managedRepository.getId());
  109. addRepositoryRoles( managedRepository.getId() );
  110. }
  111. }
  112. @PreDestroy
  113. public void shutdown()
  114. throws RepositoryAdminException
  115. {
  116. }
  117. /*
  118. * Conversion between the repository from the registry and the serialized DTO for the admin API
  119. */
  120. private ManagedRepository convertRepo( org.apache.archiva.repository.ManagedRepository repo ) {
  121. if (repo==null) {
  122. return null;
  123. }
  124. ManagedRepository adminRepo = new ManagedRepository( getArchivaConfiguration().getDefaultLocale() );
  125. setBaseRepoAttributes( adminRepo, repo );
  126. adminRepo.setLocation( convertUriToString( repo.getLocation()) );
  127. adminRepo.setReleases(repo.getActiveReleaseSchemes().contains( ReleaseScheme.RELEASE ));
  128. adminRepo.setSnapshots( repo.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT) );
  129. adminRepo.setBlockRedeployments( repo.blocksRedeployments() );
  130. adminRepo.setCronExpression( repo.getSchedulingDefinition() );
  131. if (repo.supportsFeature( IndexCreationFeature.class )) {
  132. IndexCreationFeature icf = repo.getFeature( IndexCreationFeature.class );
  133. adminRepo.setSkipPackedIndexCreation( icf.isSkipPackedIndexCreation() );
  134. }
  135. adminRepo.setScanned( repo.isScanned() );
  136. if (repo.supportsFeature( ArtifactCleanupFeature.class) ) {
  137. ArtifactCleanupFeature acf = repo.getFeature( ArtifactCleanupFeature.class );
  138. adminRepo.setRetentionPeriod( acf.getRetentionPeriod().getDays() );
  139. adminRepo.setRetentionCount( acf.getRetentionCount() );
  140. adminRepo.setDeleteReleasedSnapshots( acf.isDeleteReleasedSnapshots() );
  141. }
  142. if (repo.supportsFeature( StagingRepositoryFeature.class )) {
  143. StagingRepositoryFeature stf = repo.getFeature( StagingRepositoryFeature.class );
  144. adminRepo.setStageRepoNeeded( stf.isStageRepoNeeded() );
  145. if (stf.getStagingRepository()!=null) {
  146. adminRepo.setStagingRepository( convertRepo( stf.getStagingRepository() ) );
  147. }
  148. }
  149. return adminRepo;
  150. }
  151. private ManagedRepositoryConfiguration getRepositoryConfiguration(ManagedRepository repo) {
  152. ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
  153. setBaseRepoAttributes( repoConfig, repo );
  154. repoConfig.setBlockRedeployments( repo.isBlockRedeployments( ) );
  155. repoConfig.setReleases( repo.isReleases() );
  156. repoConfig.setSnapshots( repo.isSnapshots() );
  157. repoConfig.setScanned( repo.isScanned() );
  158. repoConfig.setLocation( getRepositoryCommonValidator().removeExpressions( repo.getLocation() ) );
  159. repoConfig.setRefreshCronExpression( repo.getCronExpression() );
  160. repoConfig.setRetentionPeriod( repo.getRetentionPeriod() );
  161. repoConfig.setRetentionCount( repo.getRetentionCount());
  162. repoConfig.setDeleteReleasedSnapshots( repo.isDeleteReleasedSnapshots() );
  163. repoConfig.setSkipPackedIndexCreation( repo.isSkipPackedIndexCreation());
  164. repoConfig.setStageRepoNeeded( repo.isStageRepoNeeded() );
  165. return repoConfig;
  166. }
  167. @Override
  168. public List<ManagedRepository> getManagedRepositories()
  169. throws RepositoryAdminException
  170. {
  171. return repositoryRegistry.getManagedRepositories().stream().map( rep -> this.convertRepo( rep ) ).collect( Collectors.toList());
  172. }
  173. @Override
  174. public Map<String, ManagedRepository> getManagedRepositoriesAsMap()
  175. throws RepositoryAdminException
  176. {
  177. return repositoryRegistry.getManagedRepositories().stream().collect( Collectors.toMap( e -> e.getId(), e -> convertRepo( e ) ) );
  178. }
  179. @Override
  180. public ManagedRepository getManagedRepository( String repositoryId )
  181. throws RepositoryAdminException
  182. {
  183. return convertRepo( repositoryRegistry.getManagedRepository( repositoryId ) );
  184. }
  185. @Override
  186. public Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
  187. AuditInformation auditInformation )
  188. throws RepositoryAdminException
  189. {
  190. log.debug("addManagedRepository {}, {}, {}", managedRepository.getId(), needStageRepo, auditInformation);
  191. getRepositoryCommonValidator().basicValidation( managedRepository, false );
  192. getRepositoryCommonValidator().validateManagedRepository( managedRepository );
  193. triggerAuditEvent( managedRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
  194. ManagedRepositoryConfiguration repoConfig = getRepositoryConfiguration( managedRepository );
  195. if (needStageRepo) {
  196. repoConfig.setStageRepoNeeded( true );
  197. }
  198. Configuration configuration = getArchivaConfiguration().getConfiguration();
  199. try
  200. {
  201. org.apache.archiva.repository.ManagedRepository newRepo = repositoryRegistry.putRepository( repoConfig );
  202. log.debug("Added new repository {}", newRepo.getId());
  203. addRepositoryRoles( newRepo.getId() );
  204. //MRM-1342 Repository statistics report doesn't appear to be working correctly
  205. //scan repository when adding of repository is successful
  206. try
  207. {
  208. if ( newRepo.isScanned())
  209. {
  210. scanRepository( newRepo.getId(), true );
  211. }
  212. org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature( StagingRepositoryFeature.class ).getStagingRepository( );
  213. if ( stagingRepo!=null)
  214. {
  215. if (stagingRepo.isScanned()) {
  216. scanRepository( stagingRepo.getId(), true );
  217. }
  218. addRepositoryRoles( stagingRepo.getId( ) );
  219. }
  220. }
  221. catch ( Exception e )
  222. {
  223. log.warn("Unable to scan repository [{}]: {}", newRepo.getId(), e.getMessage(), e);
  224. }
  225. }
  226. catch ( RepositoryException e )
  227. {
  228. log.error("Could not add managed repository {}"+managedRepository);
  229. throw new RepositoryAdminException( "Could not add repository "+e.getMessage() );
  230. }
  231. catch ( RoleManagerException e )
  232. {
  233. log.error("Could not add repository roles for repository [{}]: {}", managedRepository.getId(), e.getMessage(), e);
  234. throw new RepositoryAdminException( "Could not add roles to repository "+e.getMessage() );
  235. }
  236. return Boolean.TRUE;
  237. }
  238. @Override
  239. public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation,
  240. boolean deleteContent )
  241. throws RepositoryAdminException
  242. {
  243. Configuration config = getArchivaConfiguration().getConfiguration();
  244. ManagedRepositoryConfiguration repoConfig=config.findManagedRepositoryById( repositoryId );
  245. if (repoConfig!=null) {
  246. log.debug("Repo location " + repoConfig.getLocation());
  247. org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository(repositoryId);
  248. org.apache.archiva.repository.ManagedRepository stagingRepository = null;
  249. if (repo != null) {
  250. if (repo.supportsFeature(StagingRepositoryFeature.class)) {
  251. stagingRepository = repo.getFeature( StagingRepositoryFeature.class ).getStagingRepository();
  252. }
  253. } else {
  254. throw new RepositoryAdminException("A repository with that id does not exist");
  255. }
  256. triggerAuditEvent(repositoryId, null, AuditEvent.DELETE_MANAGED_REPO, auditInformation);
  257. if (repoConfig != null) {
  258. deleteManagedRepository(repoConfig, deleteContent, config, false);
  259. }
  260. // stage repo exists ?
  261. if (stagingRepository != null) {
  262. // do not trigger event when deleting the staged one
  263. ManagedRepositoryConfiguration stagingRepositoryConfig = config.findManagedRepositoryById(stagingRepository.getId());
  264. if (stagingRepositoryConfig != null) {
  265. deleteManagedRepository(stagingRepositoryConfig, deleteContent, config, true);
  266. }
  267. }
  268. try {
  269. saveConfiguration(config);
  270. } catch (Exception e) {
  271. throw new RepositoryAdminException("Error saving configuration for delete action" + e.getMessage(), e);
  272. }
  273. return Boolean.TRUE;
  274. } else {
  275. return Boolean.FALSE;
  276. }
  277. }
  278. private Boolean deleteManagedRepository( ManagedRepositoryConfiguration repository, boolean deleteContent,
  279. Configuration config, boolean stagedOne )
  280. throws RepositoryAdminException
  281. {
  282. if ( !stagedOne )
  283. {
  284. boolean success=false;
  285. try(RepositorySession repositorySession = getRepositorySessionFactory().createSession())
  286. {
  287. MetadataRepository metadataRepository = repositorySession.getRepository();
  288. metadataRepository.removeRepository(repositorySession , repository.getId() );
  289. //invalidate cache
  290. namespacesCache.remove( repository.getId() );
  291. repositorySession.save();
  292. success=true;
  293. }
  294. catch ( MetadataRepositoryException e )
  295. {
  296. //throw new RepositoryAdminException( e.getMessage(), e );
  297. log.warn( "skip error during removing repository from MetadataRepository:{}", e.getMessage(), e );
  298. success = false;
  299. } catch (MetadataSessionException e) {
  300. log.warn( "skip error during removing repository from MetadataRepository:{}", e.getMessage(), e );
  301. success = false;
  302. }
  303. if (success)
  304. {
  305. log.debug( "call repositoryStatisticsManager.deleteStatistics" );
  306. try
  307. {
  308. getRepositoryStatisticsManager( ).deleteStatistics( repository.getId( ) );
  309. }
  310. catch ( MetadataRepositoryException e )
  311. {
  312. e.printStackTrace( );
  313. }
  314. }
  315. }
  316. // olamy: copy list for reading as a unit test in webapp fail with ConcurrentModificationException
  317. List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>( config.getProxyConnectors() );
  318. for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
  319. {
  320. if ( StringUtils.equals( proxyConnector.getSourceRepoId(), repository.getId() ) )
  321. {
  322. config.removeProxyConnector( proxyConnector );
  323. }
  324. }
  325. try
  326. {
  327. removeRepositoryRoles( repository );
  328. }
  329. catch ( RoleManagerException e )
  330. {
  331. throw new RepositoryAdminException(
  332. "fail to remove repository roles for repository " + repository.getId() + " : " + e.getMessage(), e );
  333. }
  334. try {
  335. org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( repository.getId( ) );
  336. if (repo!=null)
  337. {
  338. repositoryRegistry.removeRepository( repo, config );
  339. if ( deleteContent )
  340. {
  341. // TODO could be async ? as directory can be huge
  342. Path dir = Paths.get( repository.getLocation( ) );
  343. org.apache.archiva.common.utils.FileUtils.deleteQuietly( dir );
  344. }
  345. }
  346. } catch (RepositoryException e) {
  347. throw new RepositoryAdminException("Removal of repository "+repository.getId()+ " failed: "+e.getMessage());
  348. }
  349. saveConfiguration( config );
  350. return Boolean.TRUE;
  351. }
  352. ArchivaIndexManager getIndexManager(ManagedRepository managedRepository) {
  353. org.apache.archiva.repository.ManagedRepository repo = getRepositoryRegistry().getManagedRepository(managedRepository.getId());
  354. return indexManagerFactory.getIndexManager(repo.getType());
  355. }
  356. @Override
  357. public Boolean updateManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
  358. AuditInformation auditInformation, boolean resetStats )
  359. throws RepositoryAdminException
  360. {
  361. log.debug( "updateManagedConfiguration repo {} needStage {} resetStats {} ", managedRepository, needStageRepo,
  362. resetStats );
  363. // Ensure that the fields are valid.
  364. getRepositoryCommonValidator().basicValidation( managedRepository, true );
  365. getRepositoryCommonValidator().validateManagedRepository( managedRepository );
  366. ManagedRepositoryConfiguration updatedRepoConfig = getRepositoryConfiguration( managedRepository );
  367. updatedRepoConfig.setStageRepoNeeded( needStageRepo );
  368. org.apache.archiva.repository.ManagedRepository oldRepo = repositoryRegistry.getManagedRepository( managedRepository.getId( ) );
  369. boolean stagingExists = false;
  370. if (oldRepo.supportsFeature( StagingRepositoryFeature.class ) ){
  371. stagingExists = oldRepo.getFeature( StagingRepositoryFeature.class ).getStagingRepository() != null;
  372. }
  373. boolean updateIndexContext = !StringUtils.equals( updatedRepoConfig.getIndexDir(), managedRepository.getIndexDirectory() );
  374. org.apache.archiva.repository.ManagedRepository newRepo;
  375. // TODO remove content from old if path has changed !!!!!
  376. try
  377. {
  378. newRepo = repositoryRegistry.putRepository( updatedRepoConfig );
  379. if (newRepo.supportsFeature( StagingRepositoryFeature.class )) {
  380. org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature( StagingRepositoryFeature.class ).getStagingRepository( );
  381. if (stagingRepo!=null && !stagingExists)
  382. {
  383. triggerAuditEvent( stagingRepo.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
  384. addRepositoryRoles( stagingRepo.getId( ) );
  385. }
  386. }
  387. }
  388. catch ( RepositoryException e )
  389. {
  390. log.error("Could not update repository {}: {}", managedRepository.getId(), e.getMessage(), e);
  391. throw new RepositoryAdminException( "Could not update repository "+managedRepository.getId());
  392. }
  393. catch ( RoleManagerException e ) {
  394. log.error("Error during role update of stage repo {}", managedRepository.getId(), e);
  395. throw new RepositoryAdminException( "Could not update repository "+managedRepository.getId());
  396. }
  397. triggerAuditEvent( managedRepository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO,
  398. auditInformation );
  399. // Save the repository configuration.
  400. RepositorySession repositorySession = null;
  401. try
  402. {
  403. repositorySession = getRepositorySessionFactory().createSession();
  404. }
  405. catch ( MetadataRepositoryException e )
  406. {
  407. e.printStackTrace( );
  408. }
  409. try
  410. {
  411. if ( resetStats )
  412. {
  413. log.debug( "call repositoryStatisticsManager.deleteStatistics" );
  414. getRepositoryStatisticsManager().deleteStatistics(
  415. managedRepository.getId() );
  416. repositorySession.save();
  417. }
  418. }
  419. catch (MetadataRepositoryException | MetadataSessionException e )
  420. {
  421. throw new RepositoryAdminException( e.getMessage(), e );
  422. }
  423. finally
  424. {
  425. repositorySession.close();
  426. }
  427. if ( updateIndexContext )
  428. {
  429. try
  430. {
  431. repositoryRegistry.resetIndexingContext(newRepo);
  432. } catch (IndexUpdateFailedException e) {
  433. e.printStackTrace();
  434. }
  435. }
  436. return true;
  437. }
  438. //--------------------------
  439. // utils methods
  440. //--------------------------
  441. protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
  442. throws RepositoryAdminException, IOException
  443. {
  444. try
  445. {
  446. getRepositoryRegistry().putRepository( repository, configuration );
  447. }
  448. catch ( RepositoryException e )
  449. {
  450. throw new RepositoryAdminException( "Could not add the repository to the registry. Cause: "+e.getMessage() );
  451. }
  452. }
  453. public Boolean scanRepository( String repositoryId, boolean fullScan )
  454. {
  455. if ( getRepositoryTaskScheduler().isProcessingRepositoryTask( repositoryId ) )
  456. {
  457. log.info( "scanning of repository with id {} already scheduled", repositoryId );
  458. }
  459. RepositoryTask task = new RepositoryTask();
  460. task.setRepositoryId( repositoryId );
  461. task.setScanAll( fullScan );
  462. try
  463. {
  464. getRepositoryTaskScheduler().queueTask( task );
  465. }
  466. catch ( TaskQueueException e )
  467. {
  468. log.error( "failed to schedule scanning of repo with id {}", repositoryId, e );
  469. return false;
  470. }
  471. return true;
  472. }
  473. private void addRepositoryRoles( String repoId )
  474. throws RoleManagerException
  475. {
  476. // TODO: double check these are configured on start up
  477. // TODO: belongs in the business logic
  478. if ( !getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
  479. {
  480. getRoleManager().createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
  481. }
  482. if ( !getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
  483. {
  484. getRoleManager().createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
  485. }
  486. }
  487. protected void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository )
  488. throws RoleManagerException
  489. {
  490. String repoId = existingRepository.getId();
  491. if ( getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
  492. {
  493. getRoleManager().removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
  494. }
  495. if ( getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
  496. {
  497. getRoleManager().removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
  498. }
  499. log.debug( "removed user roles associated with repository {}", repoId );
  500. }
  501. //--------------------------
  502. // setters/getters
  503. //--------------------------
  504. public RoleManager getRoleManager()
  505. {
  506. return roleManager;
  507. }
  508. public void setRoleManager( RoleManager roleManager )
  509. {
  510. this.roleManager = roleManager;
  511. }
  512. public RepositoryStatisticsManager getRepositoryStatisticsManager()
  513. {
  514. return repositoryStatisticsManager;
  515. }
  516. public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager )
  517. {
  518. this.repositoryStatisticsManager = repositoryStatisticsManager;
  519. }
  520. public RepositorySessionFactory getRepositorySessionFactory()
  521. {
  522. return repositorySessionFactory;
  523. }
  524. public void setRepositorySessionFactory( RepositorySessionFactory repositorySessionFactory )
  525. {
  526. this.repositorySessionFactory = repositorySessionFactory;
  527. }
  528. public RepositoryArchivaTaskScheduler getRepositoryTaskScheduler()
  529. {
  530. return repositoryTaskScheduler;
  531. }
  532. public void setRepositoryTaskScheduler( RepositoryArchivaTaskScheduler repositoryTaskScheduler )
  533. {
  534. this.repositoryTaskScheduler = repositoryTaskScheduler;
  535. }
  536. public RepositoryRegistry getRepositoryRegistry( )
  537. {
  538. return repositoryRegistry;
  539. }
  540. public void setRepositoryRegistry( RepositoryRegistry repositoryRegistry )
  541. {
  542. this.repositoryRegistry = repositoryRegistry;
  543. }
  544. }