use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class SecuritySynchronization method assignRepositoryObserverToGuestUser.
private void assignRepositoryObserverToGuestUser(List<ManagedRepositoryConfiguration> repos) {
for (ManagedRepositoryConfiguration repoConfig : repos) {
String repoId = repoConfig.getId();
String principal = UserManager.GUEST_USERNAME;
try {
UserAssignment ua;
if (rbacManager.userAssignmentExists(principal)) {
ua = rbacManager.getUserAssignment(principal);
} else {
ua = rbacManager.createUserAssignment(principal);
}
ua.addRoleName(ArchivaRoleConstants.toRepositoryObserverRoleName(repoId));
rbacManager.saveUserAssignment(ua);
} catch (RbacManagerException e) {
log.warn("Unable to add role [{}] to {} user.", ArchivaRoleConstants.toRepositoryObserverRoleName(repoId), principal, e);
}
}
}
use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class AbstractRepositoryServletTestCase method createManagedRepository.
protected ManagedRepositoryConfiguration createManagedRepository(String id, String name, Path location, String layout, boolean blockRedeployments) {
ManagedRepositoryConfiguration repo = createManagedRepository(id, name, location, blockRedeployments);
repo.setLayout(layout);
return repo;
}
use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class RepositoryRegistry method putRepository.
/**
* Adds a new repository or updates the repository with the same id, if it exists already.
* The configuration is saved immediately.
*
* @param managedRepositoryConfiguration the repository configuration
* @return the updated or created repository
* @throws RepositoryException if an error occurs, or the configuration is not valid.
*/
public ManagedRepository putRepository(ManagedRepositoryConfiguration managedRepositoryConfiguration) throws RepositoryException {
rwLock.writeLock().lock();
try {
final String id = managedRepositoryConfiguration.getId();
final RepositoryType repositoryType = RepositoryType.valueOf(managedRepositoryConfiguration.getType());
Configuration configuration = getArchivaConfiguration().getConfiguration();
ManagedRepository repo = managedRepositories.get(id);
ManagedRepositoryConfiguration oldCfg = repo != null ? getProvider(repositoryType).getManagedConfiguration(repo) : null;
repo = putRepository(managedRepositoryConfiguration, configuration);
try {
getArchivaConfiguration().save(configuration);
} catch (IndeterminateConfigurationException | RegistryException e) {
if (oldCfg != null) {
getProvider(repositoryType).updateManagedInstance((EditableManagedRepository) repo, oldCfg);
}
log.error("Could not save the configuration for repository {}: {}", id, e.getMessage(), e);
throw new RepositoryException("Could not save the configuration for repository " + id + ": " + e.getMessage());
}
return repo;
} finally {
rwLock.writeLock().unlock();
}
}
use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class RepositoryRegistry method getManagedRepositoriesFromConfig.
private Map<String, ManagedRepository> getManagedRepositoriesFromConfig() {
try {
List<ManagedRepositoryConfiguration> managedRepoConfigs = getArchivaConfiguration().getConfiguration().getManagedRepositories();
if (managedRepoConfigs == null) {
return Collections.emptyMap();
}
Map<String, ManagedRepository> managedRepos = new LinkedHashMap<>(managedRepoConfigs.size());
Map<RepositoryType, RepositoryProvider> providerMap = createProviderMap();
for (ManagedRepositoryConfiguration repoConfig : managedRepoConfigs) {
RepositoryType repositoryType = RepositoryType.valueOf(repoConfig.getType());
if (providerMap.containsKey(repositoryType)) {
try {
ManagedRepository repo = createNewManagedRepository(providerMap.get(repositoryType), repoConfig);
managedRepos.put(repo.getId(), repo);
} catch (Exception e) {
log.error("Could not create managed repository {}: {}", repoConfig.getId(), e.getMessage(), e);
}
}
}
return managedRepos;
} catch (Throwable e) {
log.error("Could not initialize repositories from config: {}", e.getMessage(), e);
// noinspection unchecked
return Collections.EMPTY_MAP;
}
}
use of org.apache.archiva.configuration.ManagedRepositoryConfiguration in project archiva by apache.
the class RepositoryRegistry method removeRepository.
public void removeRepository(ManagedRepository managedRepository, Configuration configuration) throws RepositoryException {
final String id = managedRepository.getId();
ManagedRepository repo = getManagedRepository(id);
if (repo != null) {
rwLock.writeLock().lock();
try {
repo = managedRepositories.remove(id);
if (repo != null) {
repo.close();
ManagedRepositoryConfiguration cfg = configuration.findManagedRepositoryById(id);
if (cfg != null) {
configuration.removeManagedRepository(cfg);
}
}
} finally {
rwLock.writeLock().unlock();
}
}
}
Aggregations