Search in sources :

Example 31 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class RepositoryServlet method initServers.

public synchronized void initServers(ServletConfig servletConfig) throws RepositoryAdminException {
    long start = System.currentTimeMillis();
    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletConfig.getServletContext());
    configuration = wac.getBean("archivaConfiguration#default", ArchivaConfiguration.class);
    configuration.addListener(this);
    managedRepositoryAdmin = wac.getBean(ManagedRepositoryAdmin.class);
    repositoryMap = managedRepositoryAdmin.getManagedRepositoriesAsMap();
    for (ManagedRepository repo : repositoryMap.values()) {
        Path repoDir = Paths.get(repo.getLocation());
        if (!Files.exists(repoDir)) {
            try {
                Files.createDirectories(repoDir);
            } catch (IOException e) {
                log.info("Unable to create missing directory for {}", repo.getLocation());
                continue;
            }
        }
    }
    resourceFactory = wac.getBean("davResourceFactory#archiva", DavResourceFactory.class);
    locatorFactory = new ArchivaDavLocatorFactory();
    ServletAuthenticator servletAuth = wac.getBean(ServletAuthenticator.class);
    HttpAuthenticator httpAuth = wac.getBean("httpAuthenticator#basic", HttpAuthenticator.class);
    sessionProvider = new ArchivaDavSessionProvider(servletAuth, httpAuth);
    long end = System.currentTimeMillis();
    log.debug("initServers done in {} ms", (end - start));
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) DavResourceFactory(org.apache.jackrabbit.webdav.DavResourceFactory) ServletAuthenticator(org.apache.archiva.security.ServletAuthenticator) ManagedRepositoryAdmin(org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin) HttpAuthenticator(org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator) IOException(java.io.IOException) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 32 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class ManagedRepositoriesServiceTest method addManagedRepo.

@Test
public void addManagedRepo() throws Exception {
    ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader);
    ManagedRepository repo = getTestManagedRepository();
    if (service.getManagedRepository(repo.getId()) != null) {
        service.deleteManagedRepository(repo.getId(), true);
        assertNull(service.getManagedRepository(repo.getId()));
    }
    service.addManagedRepository(repo);
    repo = service.getManagedRepository(repo.getId());
    assertNotNull(repo);
    assertEquals(getTestManagedRepository().getDescription(), repo.getDescription());
    RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
    int timeout = 20000;
    while (timeout > 0 && repositoriesService.alreadyScanning(repo.getId())) {
        Thread.sleep(500);
        timeout -= 500;
    }
    service.deleteManagedRepository(repo.getId(), true);
    assertNull(service.getManagedRepository(repo.getId()));
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) Test(org.junit.Test)

Example 33 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class ManagedRepositoriesServiceTest method updateManagedRepo.

@Test
public void updateManagedRepo() throws Exception {
    ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader);
    ManagedRepository repo = getTestManagedRepository();
    if (service.getManagedRepository(repo.getId()) != null) {
        service.deleteManagedRepository(repo.getId(), true);
        assertNull(service.getManagedRepository(repo.getId()));
    }
    service.addManagedRepository(repo);
    RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
    int timeout = 20000;
    while (timeout > 0 && repositoriesService.alreadyScanning(repo.getId())) {
        Thread.sleep(500);
        timeout -= 500;
    }
    repo = service.getManagedRepository(repo.getId());
    assertNotNull(repo);
    assertEquals("test", repo.getName());
    // toto is foo in French :-)
    repo.setName("toto");
    service.updateManagedRepository(repo);
    repo = service.getManagedRepository(repo.getId());
    assertNotNull(repo);
    assertEquals("toto", repo.getName());
    timeout = 20000;
    while (timeout > 0 && repositoriesService.alreadyScanning(repo.getId())) {
        Thread.sleep(500);
        timeout -= 500;
    }
    service.deleteManagedRepository(repo.getId(), true);
    assertNull(service.getManagedRepository(repo.getId()));
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) Test(org.junit.Test)

Example 34 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class DefaultUserRepositories method getAccessibleRepositoryIds.

private List<String> getAccessibleRepositoryIds(String principal, String operation) throws ArchivaSecurityException, AccessDeniedException, PrincipalNotFoundException {
    List<ManagedRepository> managedRepositories = getAccessibleRepositories(principal, operation);
    List<String> repoIds = new ArrayList<>(managedRepositories.size());
    for (ManagedRepository managedRepository : managedRepositories) {
        repoIds.add(managedRepository.getId());
    }
    return repoIds;
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArrayList(java.util.ArrayList)

Example 35 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class DefaultUserRepositories method getAccessibleRepositories.

private List<ManagedRepository> getAccessibleRepositories(String principal, String operation) throws ArchivaSecurityException, AccessDeniedException, PrincipalNotFoundException {
    SecuritySession securitySession = createSession(principal);
    List<ManagedRepository> managedRepositories = new ArrayList<>();
    try {
        List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
        for (ManagedRepository repo : repos) {
            try {
                String repoId = repo.getId();
                if (securitySystem.isAuthorized(securitySession, operation, repoId)) {
                    managedRepositories.add(repo);
                }
            } catch (AuthorizationException e) {
                // swallow.
                log.debug("Not authorizing '{}' for repository '{}': {}", principal, repo.getId(), e.getMessage());
            }
        }
        return managedRepositories;
    } catch (RepositoryAdminException e) {
        throw new ArchivaSecurityException(e.getMessage(), e);
    }
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) AuthorizationException(org.apache.archiva.redback.authorization.AuthorizationException) SecuritySession(org.apache.archiva.redback.system.SecuritySession) DefaultSecuritySession(org.apache.archiva.redback.system.DefaultSecuritySession) ArrayList(java.util.ArrayList) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Aggregations

ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)46 Test (org.junit.Test)23 Path (java.nio.file.Path)20 AbstractRepositoryAdminTest (org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)11 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)10 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)10 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)9 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)8 ArrayList (java.util.ArrayList)7 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)7 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)5 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5 RepositoryException (org.apache.archiva.repository.RepositoryException)5 IOException (java.io.IOException)4 Date (java.util.Date)4 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)4 ArtifactReference (org.apache.archiva.model.ArtifactReference)4 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)3 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)3 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)3