Search in sources :

Example 21 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.

the class ManagedRepositoryHandlerTest method putWithConfiguration.

@Test
void putWithConfiguration() throws RepositoryException {
    String id = "test-repo-05";
    try {
        ManagedRepositoryHandler repoHandler = createHandler();
        ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration();
        configuration.setId(id);
        configuration.setName("n-" + id);
        repoHandler.put(configuration);
        ManagedRepository repo = repoHandler.get(id);
        assertNotNull(repo);
        assertEquals(id, repo.getId());
        assertEquals("n-" + id, repo.getName());
        assertTrue(hasRepositoryInConfig(id));
    } finally {
        removeRepositoryFromConfig(id);
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.jupiter.api.Test)

Example 22 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.

the class ManagedRepositoryHandlerTest method putWithCheck_invalid.

@Test
void putWithCheck_invalid() throws RepositoryException {
    final String id = "test-repo-07";
    final String name = "n-" + id;
    try {
        ManagedRepositoryHandler repoHandler = createHandler();
        BasicManagedRepositoryValidator checker = new BasicManagedRepositoryValidator(configurationHandler);
        checker.setRepositoryRegistry(repositoryRegistry);
        ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration();
        configuration.setId("");
        configuration.setName(name);
        CheckedResult<ManagedRepository, Map<String, List<ValidationError>>> result = repoHandler.putWithCheck(configuration, checker);
        assertNull(repoHandler.get(id));
        assertNotNull(result.getResult());
        assertNotNull(result.getResult().get("id"));
        assertEquals(2, result.getResult().get("id").size());
        assertEquals(ISEMPTY, result.getResult().get("id").get(0).getType());
        assertFalse(hasRepositoryInConfig(id));
        assertFalse(hasRepositoryInConfig(""));
    } finally {
        removeRepositoryFromConfig(id);
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 23 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.

the class ManagedRepositoryHandlerTest method removeWithoutSave.

@Test
void removeWithoutSave() throws RepositoryException {
    final String id = "test-repo-09";
    ManagedRepositoryHandler repoHandler = createHandler();
    Configuration aCfg = new Configuration();
    ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration();
    configuration.setId(id);
    configuration.setName("n-" + id);
    repoHandler.put(configuration, aCfg);
    assertTrue(aCfg.getManagedRepositories().stream().anyMatch(g -> g != null && id.equals(g.getId())));
    repoHandler.remove(id, aCfg);
    assertNull(repoHandler.get(id));
    assertTrue(aCfg.getManagedRepositories().stream().noneMatch(g -> g != null && id.equals(g.getId())));
    assertNull(repoHandler.get(id));
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) CheckedResult(org.apache.archiva.repository.validation.CheckedResult) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) ArchivaRepositoryRegistry(org.apache.archiva.repository.base.ArchivaRepositoryRegistry) Inject(javax.inject.Inject) Repository(org.apache.archiva.repository.Repository) RepositoryContentFactory(org.apache.archiva.repository.RepositoryContentFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ISEMPTY(org.apache.archiva.repository.validation.ErrorKeys.ISEMPTY) IndexManagerFactory(org.apache.archiva.indexer.IndexManagerFactory) Map(java.util.Map) FileUtils(org.apache.archiva.common.utils.FileUtils) Named(javax.inject.Named) ConfigurationHandler(org.apache.archiva.repository.base.ConfigurationHandler) ValidationError(org.apache.archiva.repository.validation.ValidationError) Path(java.nio.file.Path) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryValidator(org.apache.archiva.repository.validation.RepositoryValidator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Iterator(java.util.Iterator) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Files(java.nio.file.Files) FileLockManager(org.apache.archiva.common.filelock.FileLockManager) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) RepositoryType(org.apache.archiva.repository.RepositoryType) ManagedRepository(org.apache.archiva.repository.ManagedRepository) Test(org.junit.jupiter.api.Test) List(java.util.List) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Assertions(org.junit.jupiter.api.Assertions) RepositoryState(org.apache.archiva.repository.RepositoryState) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.jupiter.api.Test)

Example 24 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.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.addRoleId(ArchivaRoleConstants.toRepositoryObserverRoleId(repoId));
            rbacManager.saveUserAssignment(ua);
        } catch (RbacManagerException e) {
            log.warn("Unable to add role [{}] to {} user.", ArchivaRoleConstants.toRepositoryObserverRoleId(repoId), principal, e);
        }
    }
}
Also used : UserAssignment(org.apache.archiva.redback.rbac.UserAssignment) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)

Example 25 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.

the class ArchivaConfigurationTest method testConfigurationUpgradeFrom13.

@Test
public void testConfigurationUpgradeFrom13() throws Exception {
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-upgrade-1.3");
    // we just use the defaults when upgrading from 1.3 at this point.
    Configuration configuration = archivaConfiguration.getConfiguration();
    assertConfiguration(configuration, 2, 2, 2);
    assertEquals("check network proxies", 0, configuration.getNetworkProxies().size());
    ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get(0);
    assertEquals("check managed repositories", "${appserver.base}/data/repositories/internal", repository.getLocation());
    assertEquals("check managed repositories", "Archiva Managed Internal Repository", repository.getName());
    assertEquals("check managed repositories", "internal", repository.getId());
    assertEquals("check managed repositories", "default", repository.getLayout());
    assertTrue("check managed repositories", repository.isScanned());
    log.info("knowContentConsumers {}", configuration.getRepositoryScanning().getKnownContentConsumers());
    assertFalse(configuration.getRepositoryScanning().getKnownContentConsumers().contains("update-db-artifact"));
    assertFalse(configuration.getRepositoryScanning().getKnownContentConsumers().contains("update-db-repository-metadata"));
    assertTrue(configuration.getRepositoryScanning().getKnownContentConsumers().contains("create-archiva-metadata"));
    assertTrue(configuration.getRepositoryScanning().getKnownContentConsumers().contains("duplicate-artifacts"));
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.Test)

Aggregations

ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)72 Configuration (org.apache.archiva.configuration.model.Configuration)27 ManagedRepository (org.apache.archiva.repository.ManagedRepository)18 ContextConfiguration (org.springframework.test.context.ContextConfiguration)18 Path (java.nio.file.Path)17 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)14 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)14 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)14 Test (org.junit.Test)14 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)13 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)11 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)10 Test (org.junit.jupiter.api.Test)10 ArrayList (java.util.ArrayList)9 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)9 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)9 RepositoryException (org.apache.archiva.repository.RepositoryException)9 Before (org.junit.Before)8 IOException (java.io.IOException)7 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)7