use of org.apache.archiva.configuration.RepositoryGroupConfiguration in project archiva by apache.
the class DefaultManagedRepositoryAdmin method deleteManagedRepository.
private Boolean deleteManagedRepository(ManagedRepositoryConfiguration repository, boolean deleteContent, Configuration config, boolean stagedOne) throws RepositoryAdminException {
if (!stagedOne) {
RepositorySession repositorySession = getRepositorySessionFactory().createSession();
try {
MetadataRepository metadataRepository = repositorySession.getRepository();
metadataRepository.removeRepository(repository.getId());
// invalidate cache
namespacesCache.remove(repository.getId());
log.debug("call repositoryStatisticsManager.deleteStatistics");
getRepositoryStatisticsManager().deleteStatistics(metadataRepository, repository.getId());
repositorySession.save();
} catch (MetadataRepositoryException e) {
// throw new RepositoryAdminException( e.getMessage(), e );
log.warn("skip error during removing repository from MetadataRepository:{}", e.getMessage(), e);
} finally {
repositorySession.close();
}
}
if (deleteContent) {
// TODO could be async ? as directory can be huge
Path dir = Paths.get(repository.getLocation());
org.apache.archiva.common.utils.FileUtils.deleteQuietly(dir);
}
// olamy: copy list for reading as a unit test in webapp fail with ConcurrentModificationException
List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>(config.getProxyConnectors());
for (ProxyConnectorConfiguration proxyConnector : proxyConnectors) {
if (StringUtils.equals(proxyConnector.getSourceRepoId(), repository.getId())) {
config.removeProxyConnector(proxyConnector);
}
}
Map<String, List<String>> repoToGroupMap = config.getRepositoryToGroupMap();
if (repoToGroupMap != null) {
if (repoToGroupMap.containsKey(repository.getId())) {
List<String> repoGroups = repoToGroupMap.get(repository.getId());
for (String repoGroup : repoGroups) {
// copy to prevent UnsupportedOperationException
RepositoryGroupConfiguration repositoryGroupConfiguration = config.findRepositoryGroupById(repoGroup);
List<String> repos = new ArrayList<>(repositoryGroupConfiguration.getRepositories());
config.removeRepositoryGroup(repositoryGroupConfiguration);
repos.remove(repository.getId());
repositoryGroupConfiguration.setRepositories(repos);
config.addRepositoryGroup(repositoryGroupConfiguration);
}
}
}
try {
removeRepositoryRoles(repository);
} catch (RoleManagerException e) {
throw new RepositoryAdminException("fail to remove repository roles for repository " + repository.getId() + " : " + e.getMessage(), e);
}
try {
final RepositoryRegistry reg = getRepositoryRegistry();
if (reg.getManagedRepository(repository.getId()) != null) {
reg.removeRepository(reg.getManagedRepository(repository.getId()));
}
} catch (RepositoryException e) {
throw new RepositoryAdminException("Removal of repository " + repository.getId() + " failed: " + e.getMessage());
}
saveConfiguration(config);
return Boolean.TRUE;
}
use of org.apache.archiva.configuration.RepositoryGroupConfiguration in project archiva by apache.
the class DefaultRepositoryGroupAdmin method deleteRepositoryGroup.
@Override
public Boolean deleteRepositoryGroup(String repositoryGroupId, AuditInformation auditInformation) throws RepositoryAdminException {
Configuration configuration = getArchivaConfiguration().getConfiguration();
RepositoryGroupConfiguration repositoryGroupConfiguration = configuration.getRepositoryGroupsAsMap().get(repositoryGroupId);
mergedRemoteIndexesScheduler.unschedule(new RepositoryGroup(repositoryGroupId, Collections.<String>emptyList()));
if (repositoryGroupConfiguration == null) {
throw new RepositoryAdminException("repositoryGroup with id " + repositoryGroupId + " doesn't not exists so cannot remove");
}
configuration.removeRepositoryGroup(repositoryGroupConfiguration);
triggerAuditEvent(repositoryGroupId, null, AuditEvent.DELETE_REPO_GROUP, auditInformation);
return Boolean.TRUE;
}
use of org.apache.archiva.configuration.RepositoryGroupConfiguration in project archiva by apache.
the class ArchivaDavResourceFactoryTest method testRepositoryGroupLastRepositoryRequiresAuthentication.
@Test
public void testRepositoryGroupLastRepositoryRequiresAuthentication() throws Exception {
DavResourceLocator locator = new ArchivaDavResourceLocator("", "/repository/" + LOCAL_REPO_GROUP + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP, new ArchivaDavLocatorFactory());
List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
repoGroup.setId(LOCAL_REPO_GROUP);
repoGroup.addRepository(INTERNAL_REPO);
repoGroup.addRepository(RELEASES_REPO);
repoGroups.add(repoGroup);
config.setRepositoryGroups(repoGroups);
ManagedRepositoryContent internalRepo = createManagedRepositoryContent(INTERNAL_REPO);
ManagedRepositoryContent releasesRepo = createManagedRepositoryContent(RELEASES_REPO);
try {
archivaConfigurationControl.reset();
expect(archivaConfiguration.getConfiguration()).andReturn(config).times(3);
expect(request.getMethod()).andReturn("GET").times(3);
expect(request.getPathInfo()).andReturn("org/apache/archiva").times(0, 2);
expect(repoFactory.getManagedRepositoryContent(INTERNAL_REPO)).andReturn(internalRepo);
expect(repoFactory.getManagedRepositoryContent(RELEASES_REPO)).andReturn(releasesRepo);
expect(request.getRemoteAddr()).andReturn("http://localhost:8080").times(2);
expect(request.getDavSession()).andReturn(new ArchivaDavSession()).times(2);
expect(request.getContextPath()).andReturn("").times(2);
expect(repoRequest.isSupportFile("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).andReturn(false);
expect(repoRequest.isDefault("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).andReturn(false);
expect(repoRequest.toArtifactReference("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).andReturn(null);
expect(repoRequest.toNativePath("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", internalRepo)).andReturn(Paths.get(config.findManagedRepositoryById(INTERNAL_REPO).getLocation(), "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar").toString());
expect(repoRequest.isArchetypeCatalog("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).andReturn(false);
archivaConfigurationControl.replay();
requestControl.replay();
repoContentFactoryControl.replay();
repoRequestControl.replay();
resourceFactory.createResource(locator, request, response);
archivaConfigurationControl.verify();
requestControl.verify();
repoContentFactoryControl.verify();
repoRequestControl.verify();
fail("A DavException with 401 error code should have been thrown.");
} catch (DavException e) {
assertEquals(401, e.getErrorCode());
}
}
use of org.apache.archiva.configuration.RepositoryGroupConfiguration in project archiva by apache.
the class ArchivaDavResourceFactory method createResource.
@Override
public DavResource createResource(final DavResourceLocator locator, final DavServletRequest request, final DavServletResponse response) throws DavException {
ArchivaDavResourceLocator archivaLocator = checkLocatorIsInstanceOfRepositoryLocator(locator);
RepositoryGroupConfiguration repoGroupConfig = archivaConfiguration.getConfiguration().getRepositoryGroupsAsMap().get(archivaLocator.getRepositoryId());
String activePrincipal = getActivePrincipal(request);
List<String> resourcesInAbsolutePath = new ArrayList<>();
boolean readMethod = WebdavMethodUtil.isReadMethod(request.getMethod());
DavResource resource;
if (repoGroupConfig != null) {
if (!readMethod) {
throw new DavException(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Write method not allowed for repository groups.");
}
log.debug("Repository group '{}' accessed by '{}", repoGroupConfig.getId(), activePrincipal);
// handle browse requests for virtual repos
if (getLogicalResource(archivaLocator, null, true).endsWith("/")) {
DavResource davResource = getResourceFromGroup(request, repoGroupConfig.getRepositories(), archivaLocator, repoGroupConfig);
setHeaders(response, locator, davResource, true);
return davResource;
} else {
// make a copy to avoid potential concurrent modifications (eg. by configuration)
// TODO: ultimately, locking might be more efficient than copying in this fashion since updates are
// infrequent
List<String> repositories = new ArrayList<>(repoGroupConfig.getRepositories());
resource = processRepositoryGroup(request, archivaLocator, repositories, activePrincipal, resourcesInAbsolutePath, repoGroupConfig);
}
} else {
try {
RemoteRepository remoteRepository = remoteRepositoryAdmin.getRemoteRepository(archivaLocator.getRepositoryId());
if (remoteRepository != null) {
String logicalResource = getLogicalResource(archivaLocator, null, false);
IndexingContext indexingContext = remoteRepositoryAdmin.createIndexContext(remoteRepository);
Path resourceFile = StringUtils.equals(logicalResource, "/") ? Paths.get(indexingContext.getIndexDirectoryFile().getParent()) : Paths.get(indexingContext.getIndexDirectoryFile().getParent(), logicalResource);
resource = new //
ArchivaDavResource(//
resourceFile.toAbsolutePath().toString(), //
locator.getResourcePath(), //
null, //
request.getRemoteAddr(), //
activePrincipal, //
request.getDavSession(), //
archivaLocator, //
this, //
mimeTypes, //
auditListeners, //
scheduler, fileLockManager);
setHeaders(response, locator, resource, false);
return resource;
}
} catch (RepositoryAdminException e) {
log.debug("RepositoryException remote repository with d'{}' not found, msg: {}", archivaLocator.getRepositoryId(), e.getMessage());
}
ManagedRepository repo = repositoryRegistry.getManagedRepository(archivaLocator.getRepositoryId());
if (repo == null) {
throw new DavException(HttpServletResponse.SC_NOT_FOUND, "Invalid repository: " + archivaLocator.getRepositoryId());
}
ManagedRepositoryContent managedRepositoryContent = repo.getContent();
if (managedRepositoryContent == null) {
log.error("Inconsistency detected. Repository content not found for '{}'", archivaLocator.getRepositoryId());
throw new DavException(HttpServletResponse.SC_NOT_FOUND, "Invalid repository: " + archivaLocator.getRepositoryId());
}
log.debug("Managed repository '{}' accessed by '{}'", managedRepositoryContent.getId(), activePrincipal);
resource = processRepository(request, archivaLocator, activePrincipal, managedRepositoryContent, repo);
String logicalResource = getLogicalResource(archivaLocator, null, false);
resourcesInAbsolutePath.add(Paths.get(managedRepositoryContent.getRepoRoot(), logicalResource).toAbsolutePath().toString());
}
String requestedResource = request.getRequestURI();
// merge metadata only when requested via the repo group
if ((repositoryRequest.isMetadata(requestedResource) || repositoryRequest.isMetadataSupportFile(requestedResource)) && repoGroupConfig != null) {
// this should only be at the project level not version level!
if (isProjectReference(requestedResource)) {
ArchivaDavResource res = (ArchivaDavResource) resource;
String filePath = StringUtils.substringBeforeLast(res.getLocalResource().toAbsolutePath().toString().replace('\\', '/'), "/");
filePath = filePath + "/maven-metadata-" + repoGroupConfig.getId() + ".xml";
// for MRM-872 handle checksums of the merged metadata files
if (repositoryRequest.isSupportFile(requestedResource)) {
Path metadataChecksum = Paths.get(filePath + "." + StringUtils.substringAfterLast(requestedResource, "."));
if (Files.exists(metadataChecksum)) {
LogicalResource logicalResource = new LogicalResource(getLogicalResource(archivaLocator, null, false));
resource = new ArchivaDavResource(metadataChecksum.toAbsolutePath().toString(), logicalResource.getPath(), null, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler, fileLockManager);
}
} else {
if (resourcesInAbsolutePath != null && resourcesInAbsolutePath.size() > 1) {
// merge the metadata of all repos under group
ArchivaRepositoryMetadata mergedMetadata = new ArchivaRepositoryMetadata();
for (String resourceAbsPath : resourcesInAbsolutePath) {
try {
Path metadataFile = Paths.get(resourceAbsPath);
ArchivaRepositoryMetadata repoMetadata = MavenMetadataReader.read(metadataFile);
mergedMetadata = RepositoryMetadataMerge.merge(mergedMetadata, repoMetadata);
} catch (XMLException e) {
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while reading metadata file.");
} catch (RepositoryMetadataException r) {
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while merging metadata file.");
}
}
try {
Path resourceFile = writeMergedMetadataToFile(mergedMetadata, filePath);
LogicalResource logicalResource = new LogicalResource(getLogicalResource(archivaLocator, null, false));
resource = new ArchivaDavResource(resourceFile.toAbsolutePath().toString(), logicalResource.getPath(), null, request.getRemoteAddr(), activePrincipal, request.getDavSession(), archivaLocator, this, mimeTypes, auditListeners, scheduler, fileLockManager);
} catch (RepositoryMetadataException r) {
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while writing metadata file.");
} catch (IOException ie) {
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while generating checksum files.");
} catch (DigesterException de) {
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error occurred while generating checksum files." + de.getMessage());
}
}
}
}
}
setHeaders(response, locator, resource, false);
// compatibility with MRM-440 to ensure browsing the repository works ok
if (resource.isCollection() && !request.getRequestURI().endsWith("/")) {
throw new BrowserRedirectException(resource.getHref());
}
resource.addLockManager(lockManager);
return resource;
}
use of org.apache.archiva.configuration.RepositoryGroupConfiguration in project archiva by apache.
the class ArchivaDavResourceFactoryTest method testRepositoryGroupArtifactDoesNotExistInAnyOfTheReposAuthenticationDisabled.
@Test
public void testRepositoryGroupArtifactDoesNotExistInAnyOfTheReposAuthenticationDisabled() throws Exception {
DavResourceLocator locator = new ArchivaDavResourceLocator("", "/repository/" + LOCAL_REPO_GROUP + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP, new ArchivaDavLocatorFactory());
defaultManagedRepositoryAdmin.addManagedRepository(createManagedRepository(LOCAL_MIRROR_REPO, Paths.get("target/test-classes/local-mirror").toString(), "default"), false, null);
List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
repoGroup.setId(LOCAL_REPO_GROUP);
repoGroup.addRepository(INTERNAL_REPO);
repoGroup.addRepository(LOCAL_MIRROR_REPO);
repoGroups.add(repoGroup);
config.setRepositoryGroups(repoGroups);
ManagedRepositoryContent internalRepo = createManagedRepositoryContent(INTERNAL_REPO);
ManagedRepositoryContent localMirrorRepo = createManagedRepositoryContent(LOCAL_MIRROR_REPO);
try {
archivaConfigurationControl.reset();
expect(archivaConfiguration.getConfiguration()).andReturn(config).times(3);
expect(request.getMethod()).andReturn("GET").times(5);
expect(request.getPathInfo()).andReturn("org/apache/archiva").times(0, 2);
expect(repoFactory.getManagedRepositoryContent(INTERNAL_REPO)).andReturn(internalRepo);
expect(repoFactory.getManagedRepositoryContent(LOCAL_MIRROR_REPO)).andReturn(localMirrorRepo);
expect(request.getRemoteAddr()).andReturn("http://localhost:8080").times(4);
expect(request.getDavSession()).andReturn(new ArchivaDavSession()).times(4);
expect(request.getContextPath()).andReturn("").times(2);
expect(repoRequest.isSupportFile("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).andReturn(false).times(2);
expect(repoRequest.isDefault("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).andReturn(false).times(2);
expect(repoRequest.toArtifactReference("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).andReturn(null).times(2);
expect(repoRequest.toNativePath("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", internalRepo)).andReturn(Paths.get(config.findManagedRepositoryById(INTERNAL_REPO).getLocation(), "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar").toString());
expect(repoRequest.toNativePath("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", localMirrorRepo)).andReturn(Paths.get(config.findManagedRepositoryById(LOCAL_MIRROR_REPO).getLocation(), "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar").toString());
expect(repoRequest.isArchetypeCatalog("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).andReturn(false).times(2);
archivaConfigurationControl.replay();
requestControl.replay();
repoContentFactoryControl.replay();
repoRequestControl.replay();
resourceFactory.createResource(locator, request, response);
archivaConfigurationControl.verify();
requestControl.verify();
repoContentFactoryControl.verify();
repoRequestControl.verify();
fail("A DavException with 404 error code should have been thrown.");
} catch (DavException e) {
assertEquals(404, e.getErrorCode());
}
}
Aggregations