use of org.apache.archiva.configuration.model.NetworkProxyConfiguration in project archiva by apache.
the class ConfigurationRegistryReader method readNetworkProxyConfiguration.
private NetworkProxyConfiguration readNetworkProxyConfiguration(String prefix, Registry registry) {
NetworkProxyConfiguration value = new NetworkProxyConfiguration();
// String id = registry.getString( prefix + "id", value.getId() );
List<String> idList = registry.getList(prefix + "id");
String id = value.getId();
if (idList != null && !idList.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (int i = 0, size = idList.size(); i < size; i++) {
sb.append(idList.get(i));
if (i < size - 1) {
sb.append(',');
}
}
id = sb.toString();
}
value.setId(id);
// String protocol = registry.getString( prefix + "protocol", value.getProtocol() );
List<String> protocolList = registry.getList(prefix + "protocol");
String protocol = value.getProtocol();
if (protocolList != null && !protocolList.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (int i = 0, size = protocolList.size(); i < size; i++) {
sb.append(protocolList.get(i));
if (i < size - 1) {
sb.append(',');
}
}
protocol = sb.toString();
}
value.setProtocol(protocol);
// String host = registry.getString( prefix + "host", value.getHost() );
List<String> hostList = registry.getList(prefix + "host");
String host = value.getHost();
if (hostList != null && !hostList.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (int i = 0, size = hostList.size(); i < size; i++) {
sb.append(hostList.get(i));
if (i < size - 1) {
sb.append(',');
}
}
host = sb.toString();
}
value.setHost(host);
int port = registry.getInt(prefix + "port", value.getPort());
value.setPort(port);
// String username = registry.getString( prefix + "username", value.getUsername() );
List<String> usernameList = registry.getList(prefix + "username");
String username = value.getUsername();
if (usernameList != null && !usernameList.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (int i = 0, size = usernameList.size(); i < size; i++) {
sb.append(usernameList.get(i));
if (i < size - 1) {
sb.append(',');
}
}
username = sb.toString();
}
value.setUsername(username);
// String password = registry.getString( prefix + "password", value.getPassword() );
List<String> passwordList = registry.getList(prefix + "password");
String password = value.getPassword();
if (passwordList != null && !passwordList.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (int i = 0, size = passwordList.size(); i < size; i++) {
sb.append(passwordList.get(i));
if (i < size - 1) {
sb.append(',');
}
}
password = sb.toString();
}
value.setPassword(password);
boolean useNtlm = registry.getBoolean(prefix + "useNtlm", value.isUseNtlm());
value.setUseNtlm(useNtlm);
return value;
}
use of org.apache.archiva.configuration.model.NetworkProxyConfiguration in project archiva by apache.
the class ArchivaProxyRegistry method updateNetworkProxies.
private void updateNetworkProxies() {
this.networkProxyMap.clear();
List<NetworkProxyConfiguration> networkProxies = getArchivaConfiguration().getConfiguration().getNetworkProxies();
for (NetworkProxyConfiguration networkProxyConfig : networkProxies) {
String key = networkProxyConfig.getId();
NetworkProxy proxy = new NetworkProxy();
proxy.setProtocol(networkProxyConfig.getProtocol());
proxy.setHost(networkProxyConfig.getHost());
proxy.setPort(networkProxyConfig.getPort());
proxy.setUsername(networkProxyConfig.getUsername());
proxy.setPassword(networkProxyConfig.getPassword() == null ? new char[0] : networkProxyConfig.getPassword().toCharArray());
proxy.setUseNtlm(networkProxyConfig.isUseNtlm());
this.networkProxyMap.put(key, proxy);
}
for (RepositoryProxyHandler proxyHandler : repositoryProxyHandlers) {
proxyHandler.setNetworkProxies(this.networkProxyMap);
}
}
use of org.apache.archiva.configuration.model.NetworkProxyConfiguration in project archiva by apache.
the class HttpProxyTransferTest method setUp.
@Before
public void setUp() throws Exception {
proxyHandler = applicationContext.getBean("repositoryProxyHandler#test", RepositoryProxyHandler.class);
// clear from previous tests - TODO the spring context should be initialised per test instead, or the config
// made a complete mock
config.getConfiguration().getProxyConnectors().clear();
// Setup source repository (using default layout)
String repoPath = "target/test-repository/managed/" + getClass().getSimpleName();
Path destRepoDir = Paths.get(repoPath);
// Cleanout destination dirs.
if (Files.exists(destRepoDir)) {
FileUtils.deleteDirectory(destRepoDir.toFile());
}
// Make the destination dir.
Files.createDirectories(destRepoDir);
Handler handler = new AbstractHandler() {
@Override
public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/plain");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().print("get-default-layout-1.0.jar\n\n");
assertNotNull(request.getHeader("Proxy-Connection"));
((Request) request).setHandled(true);
}
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
response.setContentType("text/plain");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().print("get-default-layout-1.0.jar\n\n");
assertNotNull(request.getHeader("Proxy-Connection"));
((Request) request).setHandled(true);
}
};
server = new Server();
ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory());
server.addConnector(serverConnector);
server.setHandler(handler);
server.start();
int port = serverConnector.getLocalPort();
NetworkProxyConfiguration proxyConfig = new NetworkProxyConfiguration();
proxyConfig.setHost("localhost");
proxyConfig.setPort(port);
proxyConfig.setProtocol("http");
proxyConfig.setId(PROXY_ID);
config.getConfiguration().addNetworkProxy(proxyConfig);
((MockConfiguration) config).triggerChange("networkProxies.networkProxy(0).host", "localhost");
// Setup target (proxied to) repository.
RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration();
repoConfig.setId(PROXIED_ID);
repoConfig.setName("Proxied Repository 1");
repoConfig.setLayout("default");
repoConfig.setUrl("http://www.example.com/");
config.getConfiguration().addRemoteRepository(repoConfig);
Wagon wagon = new HttpWagon();
WagonDelegate delegate = (WagonDelegate) applicationContext.getBean("wagon#http", Wagon.class);
delegate.setDelegate(wagon);
proxyRegistry.reload();
repositoryRegistry.reload();
managedDefaultRepository = createRepository(MANAGED_ID, "Default Managed Repository", repoPath, "default");
}
use of org.apache.archiva.configuration.model.NetworkProxyConfiguration in project archiva by apache.
the class ArchivaConfigurationTest method testRemoveLastElements.
@Test
public void testRemoveLastElements() throws Exception {
Path baseFile = getTestFile("target/test/test-file.xml");
Files.deleteIfExists(baseFile);
assertFalse(Files.exists(baseFile));
Path userFile = getTestFile("target/test/test-file-user.xml");
Files.deleteIfExists(userFile);
assertFalse(Files.exists(userFile));
Files.createDirectories(baseFile.getParent());
FileUtils.copyFile(getTestFile("src/test/conf/conf-single-list-elements.xml").toFile(), baseFile.toFile());
Files.createDirectories(userFile.getParent());
FileUtils.writeStringToFile(userFile.toFile(), "<configuration/>", Charset.forName("UTF-8"));
ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-remove-central");
archivaConfiguration.reload();
Configuration configuration = archivaConfiguration.getConfiguration();
RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get(0);
assertNotNull(repositoryGroup);
configuration.removeRepositoryGroup(repositoryGroup);
assertTrue(configuration.getRepositoryGroups().isEmpty());
RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get("central");
assertNotNull(repository);
configuration.removeRemoteRepository(repository);
assertTrue(configuration.getRemoteRepositories().isEmpty());
ManagedRepositoryConfiguration managedRepository = configuration.getManagedRepositoriesAsMap().get("snapshots");
assertNotNull(managedRepository);
configuration.removeManagedRepository(managedRepository);
assertTrue(configuration.getManagedRepositories().isEmpty());
ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get(0);
assertNotNull(proxyConnector);
configuration.removeProxyConnector(proxyConnector);
assertTrue(configuration.getProxyConnectors().isEmpty());
NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get("proxy");
assertNotNull(networkProxy);
configuration.removeNetworkProxy(networkProxy);
assertTrue(configuration.getNetworkProxies().isEmpty());
LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get(0);
assertNotNull(path);
configuration.removeLegacyArtifactPath(path);
assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
String consumer = scanning.getKnownContentConsumers().get(0);
assertNotNull(consumer);
scanning.removeKnownContentConsumer(consumer);
// default values
assertFalse(scanning.getKnownContentConsumers().isEmpty());
consumer = scanning.getInvalidContentConsumers().get(0);
assertNotNull(consumer);
scanning.removeInvalidContentConsumer(consumer);
assertTrue(scanning.getInvalidContentConsumers().isEmpty());
archivaConfiguration.save(configuration);
archivaConfiguration = lookup(ArchivaConfiguration.class, "test-read-saved");
configuration = archivaConfiguration.getConfiguration();
assertNull(configuration.getRemoteRepositoriesAsMap().get("central"));
assertTrue(configuration.getRepositoryGroups().isEmpty());
assertNull(configuration.getManagedRepositoriesAsMap().get("snapshots"));
assertTrue(configuration.getProxyConnectors().isEmpty());
assertNull(configuration.getNetworkProxiesAsMap().get("proxy"));
assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
scanning = configuration.getRepositoryScanning();
assertFalse(scanning.getKnownContentConsumers().isEmpty());
assertTrue(scanning.getInvalidContentConsumers().isEmpty());
}
use of org.apache.archiva.configuration.model.NetworkProxyConfiguration in project archiva by apache.
the class MavenProxyPropertyLoaderTest method testLoadValidMavenProxyConfiguration.
@Test
public void testLoadValidMavenProxyConfiguration() throws IOException, InvalidConfigurationException {
Path confFile = ArchivaConfigurationTest.getTestFile("src/test/conf/maven-proxy-complete.conf");
Configuration configuration = new Configuration();
NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
proxy.setHost("original-host");
// overwritten
configuration.addNetworkProxy(proxy);
loader.load(Files.newInputStream(confFile), configuration);
Map<String, ManagedRepositoryConfiguration> repositoryIdMap = configuration.getManagedRepositoriesAsMap();
assertEquals("Count repositories", 1, repositoryIdMap.size());
assertRepositoryExists("maven-proxy", "target", repositoryIdMap.get("maven-proxy"));
Map<String, RemoteRepositoryConfiguration> remoteRepositoryMap = configuration.getRemoteRepositoriesAsMap();
assertEquals("Count repositories", 4, remoteRepositoryMap.size());
assertRepositoryExists("local-repo", "file://target", remoteRepositoryMap.get("local-repo"));
assertRepositoryExists("www-ibiblio-org", "http://www.ibiblio.org/maven2", remoteRepositoryMap.get("www-ibiblio-org"));
assertRepositoryExists("dist-codehaus-org", "http://dist.codehaus.org", remoteRepositoryMap.get("dist-codehaus-org"));
assertRepositoryExists("private-example-com", "http://private.example.com/internal", remoteRepositoryMap.get("private-example-com"));
}
Aggregations