Search in sources :

Example 1 with ProxyConnectorRuleConfiguration

use of org.apache.archiva.configuration.ProxyConnectorRuleConfiguration in project archiva by apache.

the class DefaultProxyConnectorRuleAdmin method deleteProxyConnectorRule.

@Override
public void deleteProxyConnectorRule(ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation) throws RepositoryAdminException {
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    // key is the pattern !!
    // recreate a list without the pattern
    boolean toSave = false;
    List<ProxyConnectorRuleConfiguration> proxyConnectorRuleConfigurations = new ArrayList<>();
    for (ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : configuration.getProxyConnectorRuleConfigurations()) {
        if (StringUtils.equals(proxyConnectorRuleConfiguration.getPattern(), proxyConnectorRule.getPattern()) && StringUtils.equals(proxyConnectorRuleConfiguration.getRuleType(), proxyConnectorRule.getProxyConnectorRuleType().getRuleType())) {
            toSave = true;
        } else {
            proxyConnectorRuleConfigurations.add(proxyConnectorRuleConfiguration);
        }
    }
    if (toSave) {
        configuration.setProxyConnectorRuleConfigurations(proxyConnectorRuleConfigurations);
        saveConfiguration(configuration);
    }
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.ProxyConnectorRuleConfiguration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.ProxyConnectorRuleConfiguration) ArrayList(java.util.ArrayList)

Example 2 with ProxyConnectorRuleConfiguration

use of org.apache.archiva.configuration.ProxyConnectorRuleConfiguration in project archiva by apache.

the class DefaultProxyConnectorRuleAdmin method addProxyConnectorRule.

@Override
public void addProxyConnectorRule(ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation) throws RepositoryAdminException {
    ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration = new ProxyConnectorRuleConfiguration();
    proxyConnectorRuleConfiguration.setPattern(proxyConnectorRule.getPattern());
    proxyConnectorRuleConfiguration.setRuleType(proxyConnectorRule.getProxyConnectorRuleType().getRuleType());
    for (ProxyConnector proxyConnector : proxyConnectorRule.getProxyConnectors()) {
        ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
        proxyConnectorConfiguration.setSourceRepoId(proxyConnector.getSourceRepoId());
        proxyConnectorConfiguration.setTargetRepoId(proxyConnector.getTargetRepoId());
        proxyConnectorRuleConfiguration.getProxyConnectors().add(proxyConnectorConfiguration);
    }
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    configuration.getProxyConnectorRuleConfigurations().add(proxyConnectorRuleConfiguration);
    saveConfiguration(configuration);
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.ProxyConnectorRuleConfiguration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.ProxyConnectorRuleConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector)

Example 3 with ProxyConnectorRuleConfiguration

use of org.apache.archiva.configuration.ProxyConnectorRuleConfiguration in project archiva by apache.

the class DefaultProxyConnectorRuleAdmin method updateProxyConnectorRule.

@Override
public void updateProxyConnectorRule(ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation) throws RepositoryAdminException {
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    for (ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : configuration.getProxyConnectorRuleConfigurations()) {
        if (StringUtils.equals(proxyConnectorRuleConfiguration.getPattern(), proxyConnectorRule.getPattern()) && StringUtils.equals(proxyConnectorRuleConfiguration.getRuleType(), proxyConnectorRule.getProxyConnectorRuleType().getRuleType())) {
            List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>(proxyConnectorRule.getProxyConnectors().size());
            for (ProxyConnector proxyConnector : proxyConnectorRule.getProxyConnectors()) {
                ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
                proxyConnectorConfiguration.setSourceRepoId(proxyConnector.getSourceRepoId());
                proxyConnectorConfiguration.setTargetRepoId(proxyConnector.getTargetRepoId());
                proxyConnectors.add(proxyConnectorConfiguration);
            }
            proxyConnectorRuleConfiguration.setProxyConnectors(proxyConnectors);
            saveConfiguration(configuration);
        }
    }
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.ProxyConnectorRuleConfiguration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.ProxyConnectorRuleConfiguration) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector)

Example 4 with ProxyConnectorRuleConfiguration

use of org.apache.archiva.configuration.ProxyConnectorRuleConfiguration 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);
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.ProxyConnectorRuleConfiguration) Configuration(org.apache.archiva.configuration.Configuration) NetworkProxyConfiguration(org.apache.archiva.configuration.NetworkProxyConfiguration) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.ProxyConnectorRuleConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.NetworkProxyConfiguration) ProxyConnector(org.apache.archiva.proxy.model.ProxyConnector)

Example 5 with ProxyConnectorRuleConfiguration

use of org.apache.archiva.configuration.ProxyConnectorRuleConfiguration in project archiva by apache.

the class DefaultProxyConnectorRuleAdmin method getProxyConnectorRules.

@Override
public List<ProxyConnectorRule> getProxyConnectorRules() throws RepositoryAdminException {
    List<ProxyConnectorRuleConfiguration> proxyConnectorRuleConfigurations = getArchivaConfiguration().getConfiguration().getProxyConnectorRuleConfigurations();
    if (proxyConnectorRuleConfigurations.isEmpty()) {
        return Collections.emptyList();
    }
    List<ProxyConnectorRule> proxyConnectorRules = new ArrayList<>(proxyConnectorRuleConfigurations.size());
    for (ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : proxyConnectorRuleConfigurations) {
        ProxyConnectorRule proxyConnectorRule = new ProxyConnectorRule();
        proxyConnectorRule.setPattern(proxyConnectorRuleConfiguration.getPattern());
        proxyConnectorRule.setProxyConnectorRuleType(getProxyConnectorRuleType(proxyConnectorRuleConfiguration.getRuleType()));
        for (ProxyConnectorConfiguration proxyConnectorConfiguration : proxyConnectorRuleConfiguration.getProxyConnectors()) {
            ProxyConnector proxyConnector = new ProxyConnector();
            proxyConnector.setSourceRepoId(proxyConnectorConfiguration.getSourceRepoId());
            proxyConnector.setTargetRepoId(proxyConnectorConfiguration.getTargetRepoId());
            proxyConnectorRule.getProxyConnectors().add(proxyConnector);
        }
        proxyConnectorRules.add(proxyConnectorRule);
    }
    return proxyConnectorRules;
}
Also used : ProxyConnectorRuleConfiguration(org.apache.archiva.configuration.ProxyConnectorRuleConfiguration) ProxyConnectorRule(org.apache.archiva.admin.model.beans.ProxyConnectorRule) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector)

Aggregations

ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)5 ProxyConnectorRuleConfiguration (org.apache.archiva.configuration.ProxyConnectorRuleConfiguration)5 ArrayList (java.util.ArrayList)4 Configuration (org.apache.archiva.configuration.Configuration)4 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)3 ProxyConnectorRule (org.apache.archiva.admin.model.beans.ProxyConnectorRule)1 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)1 NetworkProxyConfiguration (org.apache.archiva.configuration.NetworkProxyConfiguration)1 ProxyConnector (org.apache.archiva.proxy.model.ProxyConnector)1 ManagedRepository (org.apache.archiva.repository.ManagedRepository)1 RemoteRepository (org.apache.archiva.repository.RemoteRepository)1 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)1