Search in sources :

Example 1 with NetworkProxyConfiguration

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;
}
Also used : NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration)

Example 2 with NetworkProxyConfiguration

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);
    }
}
Also used : NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) NetworkProxy(org.apache.archiva.proxy.model.NetworkProxy) RepositoryProxyHandler(org.apache.archiva.proxy.model.RepositoryProxyHandler)

Example 3 with NetworkProxyConfiguration

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");
}
Also used : Path(java.nio.file.Path) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpWagon(org.apache.maven.wagon.providers.http.HttpWagon) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Handler(org.eclipse.jetty.server.Handler) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) RepositoryProxyHandler(org.apache.archiva.proxy.model.RepositoryProxyHandler) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpWagon(org.apache.maven.wagon.providers.http.HttpWagon) Wagon(org.apache.maven.wagon.Wagon) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerConnector(org.eclipse.jetty.server.ServerConnector) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryProxyHandler(org.apache.archiva.proxy.model.RepositoryProxyHandler) Before(org.junit.Before)

Example 4 with NetworkProxyConfiguration

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());
}
Also used : Path(java.nio.file.Path) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) 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) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Test(org.junit.Test)

Example 5 with NetworkProxyConfiguration

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"));
}
Also used : Path(java.nio.file.Path) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) Test(org.junit.Test)

Aggregations

NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)12 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)6 Configuration (org.apache.archiva.configuration.model.Configuration)5 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)5 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)4 Path (java.nio.file.Path)3 LegacyArtifactPath (org.apache.archiva.configuration.model.LegacyArtifactPath)3 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)3 Test (org.junit.Test)3 Iterator (java.util.Iterator)2 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)2 ProxyConnectorRuleConfiguration (org.apache.archiva.configuration.model.ProxyConnectorRuleConfiguration)2 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)2 WebappConfiguration (org.apache.archiva.configuration.model.WebappConfiguration)2 RepositoryProxyHandler (org.apache.archiva.proxy.model.RepositoryProxyHandler)2 List (java.util.List)1 Properties (java.util.Properties)1 StringTokenizer (java.util.StringTokenizer)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1