use of org.apache.archiva.configuration.Configuration in project archiva by apache.
the class DefaultRepositoryProxyConnectors method initConnectorsAndNetworkProxies.
@SuppressWarnings("unchecked")
private void initConnectorsAndNetworkProxies() {
ProxyConnectorOrderComparator proxyOrderSorter = new ProxyConnectorOrderComparator();
this.proxyConnectorMap.clear();
Configuration configuration = archivaConfiguration.getConfiguration();
List<ProxyConnectorRuleConfiguration> allProxyConnectorRuleConfigurations = configuration.getProxyConnectorRuleConfigurations();
List<ProxyConnectorConfiguration> proxyConfigs = configuration.getProxyConnectors();
for (ProxyConnectorConfiguration proxyConfig : proxyConfigs) {
String key = proxyConfig.getSourceRepoId();
// Create connector object.
ProxyConnector connector = new ProxyConnector();
ManagedRepository repo = repositoryRegistry.getManagedRepository(proxyConfig.getSourceRepoId());
if (repo == null) {
log.error("Cannot find source repository after config change " + proxyConfig.getSourceRepoId());
continue;
}
connector.setSourceRepository(repo.getContent());
RemoteRepository rRepo = repositoryRegistry.getRemoteRepository(proxyConfig.getTargetRepoId());
if (rRepo == null) {
log.error("Cannot find target repository after config change " + proxyConfig.getSourceRepoId());
continue;
}
connector.setTargetRepository(rRepo.getContent());
connector.setProxyId(proxyConfig.getProxyId());
connector.setPolicies(proxyConfig.getPolicies());
connector.setOrder(proxyConfig.getOrder());
connector.setDisabled(proxyConfig.isDisabled());
// Copy any blacklist patterns.
List<String> blacklist = new ArrayList<>(0);
if (CollectionUtils.isNotEmpty(proxyConfig.getBlackListPatterns())) {
blacklist.addAll(proxyConfig.getBlackListPatterns());
}
connector.setBlacklist(blacklist);
// Copy any whitelist patterns.
List<String> whitelist = new ArrayList<>(0);
if (CollectionUtils.isNotEmpty(proxyConfig.getWhiteListPatterns())) {
whitelist.addAll(proxyConfig.getWhiteListPatterns());
}
connector.setWhitelist(whitelist);
List<ProxyConnectorRuleConfiguration> proxyConnectorRuleConfigurations = findProxyConnectorRules(connector.getSourceRepository().getId(), connector.getTargetRepository().getId(), allProxyConnectorRuleConfigurations);
if (!proxyConnectorRuleConfigurations.isEmpty()) {
for (ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : proxyConnectorRuleConfigurations) {
if (StringUtils.equals(proxyConnectorRuleConfiguration.getRuleType(), ProxyConnectorRuleType.BLACK_LIST.getRuleType())) {
connector.getBlacklist().add(proxyConnectorRuleConfiguration.getPattern());
}
if (StringUtils.equals(proxyConnectorRuleConfiguration.getRuleType(), ProxyConnectorRuleType.WHITE_LIST.getRuleType())) {
connector.getWhitelist().add(proxyConnectorRuleConfiguration.getPattern());
}
}
}
// Get other connectors
List<ProxyConnector> connectors = this.proxyConnectorMap.get(key);
if (connectors == null) {
// Create if we are the first.
connectors = new ArrayList<>(1);
}
// Add the connector.
connectors.add(connector);
// Ensure the list is sorted.
Collections.sort(connectors, proxyOrderSorter);
// Set the key to the list of connectors.
this.proxyConnectorMap.put(key, connectors);
}
this.networkProxyMap.clear();
List<NetworkProxyConfiguration> networkProxies = archivaConfiguration.getConfiguration().getNetworkProxies();
for (NetworkProxyConfiguration networkProxyConfig : networkProxies) {
String key = networkProxyConfig.getId();
ProxyInfo proxy = new ProxyInfo();
proxy.setType(networkProxyConfig.getProtocol());
proxy.setHost(networkProxyConfig.getHost());
proxy.setPort(networkProxyConfig.getPort());
proxy.setUserName(networkProxyConfig.getUsername());
proxy.setPassword(networkProxyConfig.getPassword());
this.networkProxyMap.put(key, proxy);
}
}
use of org.apache.archiva.configuration.Configuration in project archiva by apache.
the class RepositoryServletRepositoryGroupTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
String appserverBase = System.getProperty("appserver.base");
Configuration configuration = archivaConfiguration.getConfiguration();
repoRootFirst = Paths.get(appserverBase, "data/repositories/" + MANAGED_REPO_FIRST);
repoRootLast = Paths.get(appserverBase, "data/repositories/" + MANAGED_REPO_LAST);
configuration.addManagedRepository(createManagedRepository(MANAGED_REPO_FIRST, "First Test Repo", repoRootFirst, true));
configuration.addManagedRepository(createManagedRepository(MANAGED_REPO_LAST, "Last Test Repo", repoRootLast, true));
List<String> managedRepoIds = new ArrayList<>();
managedRepoIds.add(MANAGED_REPO_FIRST);
managedRepoIds.add(MANAGED_REPO_LAST);
configuration.addRepositoryGroup(createRepositoryGroup(REPO_GROUP_WITH_VALID_REPOS, managedRepoIds));
// Create the repository group with an invalid managed repository
repoRootInvalid = Paths.get(appserverBase, "data/repositories/" + MANAGED_REPO_INVALID);
ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepository(MANAGED_REPO_INVALID, "Invalid Test Repo", repoRootInvalid, true);
configuration.addManagedRepository(createManagedRepository(MANAGED_REPO_FIRST, "First Test Repo", repoRootFirst, true));
configuration.addManagedRepository(managedRepositoryConfiguration);
configuration.addManagedRepository(createManagedRepository(MANAGED_REPO_LAST, "Last Test Repo", repoRootLast, true));
List<String> invalidManagedRepoIds = new ArrayList<>();
invalidManagedRepoIds.add(MANAGED_REPO_FIRST);
invalidManagedRepoIds.add(MANAGED_REPO_INVALID);
invalidManagedRepoIds.add(MANAGED_REPO_LAST);
configuration.addRepositoryGroup(createRepositoryGroup(REPO_GROUP_WITH_INVALID_REPOS, invalidManagedRepoIds));
configuration.removeManagedRepository(managedRepositoryConfiguration);
org.apache.archiva.common.utils.FileUtils.deleteDirectory(repoRootInvalid);
repositoryRegistry.reload();
saveConfiguration(archivaConfiguration);
startRepository();
}
use of org.apache.archiva.configuration.Configuration in project archiva by apache.
the class RepositoryServletSecurityTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
String appserverBase = System.getProperty("appserver.base", Paths.get("target/appserver-base").toAbsolutePath().toString());
Path testConf = Paths.get("src/test/resources/repository-archiva.xml");
Path testConfDest = Paths.get(appserverBase, "conf/archiva.xml");
FileUtils.copyFile(testConf.toFile(), testConfDest.toFile());
Configuration config = archivaConfiguration.getConfiguration();
// clear managed repository
List<ManagedRepositoryConfiguration> f1 = new ArrayList<>(config.getManagedRepositories());
for (ManagedRepositoryConfiguration f : f1) {
config.removeManagedRepository(f);
}
assertEquals(0, config.getManagedRepositories().size());
// add internal repo
config.addManagedRepository(createManagedRepository(REPOID_INTERNAL, "Internal Test Repo", repoRootInternal.getRoot()));
saveConfiguration(archivaConfiguration);
CacheManager.getInstance().clearAll();
servletAuthControl = EasyMock.createControl();
servletAuth = servletAuthControl.createMock(ServletAuthenticator.class);
httpAuthControl = EasyMock.createControl();
httpAuth = httpAuthControl.createMock(HttpAuthenticator.class);
davSessionProvider = new ArchivaDavSessionProvider(servletAuth, httpAuth);
final MockServletContext mockServletContext = new MockServletContext();
WebApplicationContext webApplicationContext = new AbstractRepositoryServletTestCase.TestWebapplicationContext(applicationContext, mockServletContext);
mockServletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);
MockServletConfig mockServletConfig = new MockServletConfig() {
@Override
public ServletContext getServletContext() {
return mockServletContext;
}
};
servlet = new RepositoryServlet();
servlet.init(mockServletConfig);
}
use of org.apache.archiva.configuration.Configuration in project archiva by apache.
the class RepositoryServletTest method testGetRepositoryAfterDelete.
@Test
public void testGetRepositoryAfterDelete() throws Exception {
RepositoryServlet servlet = RepositoryServlet.class.cast(findServlet("repository"));
assertNotNull(servlet);
ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
Configuration c = archivaConfiguration.getConfiguration();
c.removeManagedRepository(c.findManagedRepositoryById(REPOID_INTERNAL));
saveConfiguration(archivaConfiguration);
ManagedRepository repository = servlet.getRepository(REPOID_INTERNAL);
assertNull(repository);
}
use of org.apache.archiva.configuration.Configuration in project archiva by apache.
the class DefaultArchivaAdministration method addFileTypePattern.
@Override
public void addFileTypePattern(String fileTypeId, String pattern, AuditInformation auditInformation) throws RepositoryAdminException {
Configuration configuration = getArchivaConfiguration().getConfiguration();
org.apache.archiva.configuration.FileType fileType = getFileTypeById(fileTypeId, configuration);
if (fileType == null) {
return;
}
if (fileType.getPatterns().contains(pattern)) {
throw new RepositoryAdminException("File type [" + fileTypeId + "] already contains pattern [" + pattern + "]");
}
fileType.addPattern(pattern);
saveConfiguration(configuration);
triggerAuditEvent("", "", AuditEvent.ADD_PATTERN, auditInformation);
}
Aggregations